Created
March 19, 2019 10:04
-
-
Save stemangiola/c8aef6237c7574e42a49a2be48dd6a66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generate_gamma_sum <- function(N, k, theta) { | |
n_means = length(k) | |
sums = numeric(N) | |
for(n in 1:N) sums[n] = sum(rgamma(n_means, shape = k, scale = theta)) | |
list(sums = sums, shape = k, scale = theta) | |
} | |
k=c(3,4,5) | |
theta=c(1, 2, 1) | |
generate_gamma_sum(10000, c(3,4,5), c(1, 2, 1)) %$% | |
sums %>% | |
MASS::fitdistr("gamma") | |
k_sum = sum(theta*k)^2/sum(theta^2*k) | |
theta_sum = sum(k*theta)/k_sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment