m <- 2; SD <- exp(1)
fdata <- data.frame(y = rfoldnorm(n <- 1000, m = m, sd = SD))
hist(with(fdata, y), prob = TRUE, main = paste("foldnormal(m = ", m,
", sd = ", round(SD, 2), ")"))
fit <- vglm(y ~ 1, fam = foldnormal, fdata, trace = TRUE)
coef(fit, matrix = TRUE)
(Cfit <- Coef(fit))
mygrid <- with(fdata, seq(min(y), max(y), len = 200)) # Add the fit to the histogram
lines(mygrid, dfoldnorm(mygrid, Cfit[1], Cfit[2]), col = "orange")
Run the code above in your browser using DataLab