pdata = data.frame(m = 1.0, SD = exp(1.0))
pdata = transform(pdata, y = rposnorm(n <- 1000, m = m, sd = SD))
with(pdata, hist(y, prob = TRUE, border = "blue",
main = paste("posnorm(m =", m[1], ", sd =", round(SD[1], 2),")")))
fit = vglm(y ~ 1, fam = posnormal1, pdata, trace = TRUE)
coef(fit, matrix = TRUE)
(Cfit = Coef(fit))
mygrid = with(pdata, seq(min(y), max(y), len = 200)) # Add the fit to the histogram
lines(mygrid, dposnorm(mygrid, Cfit[1], Cfit[2]), col = "red")
Run the code above in your browser using DataLab