Created
December 21, 2016 03:01
-
-
Save msalganik/7d8762e69b3954b3a5a2ec437f62d6e9 to your computer and use it in GitHub Desktop.
R script to explore the rlnorm() function
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
# R script to explore rlnorm() | |
# written by Malte Möser and Matthew Salganik | |
# Described in this blog post: | |
set.seed(123) | |
draws1 <- rlnorm(n = 1000000, mean = 7, sd = 75) | |
mean(draws1) | |
sd(draws1) | |
draws2 <- rlnorm(n = 1000000, meanlog = log(7), sdlog = log(75)) | |
mean(draws2) | |
sd(draws2) | |
m <- 7 | |
s <- 75 | |
location <- log(m^2 / sqrt(s^2 + m^2)) | |
shape <- sqrt(log(1 + (s^2 / m^2))) | |
print(paste("location:", location)) | |
print(paste("shape:", shape)) | |
draws3 <- rlnorm(n = 1000000, location, shape) | |
mean(draws3) | |
sd(draws3) | |
plot(density(draws3[draws3 < 20])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment