Johnson Distribution Sim
- Load Data
####Simulate Johnson Distribution####
#load supplemental distribution library
library(SuppDists)
## Warning: package 'SuppDists' was built under R version 3.2.2
#Get distribution parms from sample data
df <- read.csv("rd.csv")
- Fit Johnson Distribution and get parameters (gamma, delta, xi, lambda)
parms <- JohnsonFit(df$LT)
- Examine distribtion parameters
parms
## $gamma
## [1] 2.068715
##
## $delta
## [1] 1.357436
##
## $xi
## [1] -0.2879019
##
## $lambda
## [1] 25.81575
##
## $type
## [1] "SB"
- Set n and # of simulations
n <- 300
nsim <- 1000
- Simulate nsim random variables -> Format as Matrx, nsim Samples of n
List <- list()
for (i in 1 : nsim)
{
sim <- rJohnson(n, parms)
List[[i]] <- sim
}
simatrix <- do.call(cbind, List)
- Take st.devation of each simulated distribution and store in vector
st.devs <- apply(simatrix, 2, sd)
- Examine Distribution and Density Plot of Distribution of Standard Deviations
hist(st.devs, prob=TRUE, col="grey") #prob=TRUE for probabilities not counts
lines(density(st.devs, adjust = 2), col="blue", lwd=2) # add a density estimate with defaults
lines(density(st.devs), lty="dotted", col="darkgreen", lwd=2)

- Write matrix and st.dev vector to csv
write.csv(simatrix, "matrix.csv")
write.csv(st.devs, "st_devs.csv")