Created
February 16, 2021 23:07
-
-
Save cbrown5/04b8688d23ef5cd1649f6878b6ef1d97 to your computer and use it in GitHub Desktop.
Parameterize gamma distribution with mode and SD
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
#Parameterize gamma distribution with mode and SD | |
#Choose summary stats for the gamma | |
xmode <- 1 #mode of distribution | |
xsd <- 0.5 # SD | |
#Calculate gamma parameters | |
beta <- (xmode + sqrt(xmode^2 + 4*xsd^2 ) ) / ( 2 * xsd^2 ) | |
alpha <- 1 + xmode * beta | |
#Plot gamma | |
x <- seq(0.01, 4, length.out = 1000) | |
fx <- dgamma(x, shape = alpha, rate = beta) | |
#NB stan language is same parameterization as R defaults: shape and rate | |
plot(x, fx, type = "l") | |
abline(v = FP_mode) | |
rx <- rgamma(10000, shape = alpha, rate = beta) | |
sd(rx) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment