##########
set.seed(10470923)
nn <- 3000
## Parameters
mysdlog <- exp(-1.5) # sdlog
LL <- 3.5 # Lower bound
UL <- 8.0 # Upper bound
## Truncated data
ldata2 <- data.frame(x2 = runif(nn))
ldata2 <- transform(ldata2, y1 = rtrunclnorm(nn, 1 + 1.5 * x2, mysdlog,
min.support = LL, max.support = UL))
# head(ldata2)
# hist(ldata2$y1, breaks = 22, col = "blue", xlim = c(0, 10))
##############################################################
# Fitting a truncated lognormal distribution - sd is intercept only
fit1 <- vglm(y1 ~ x2, trunclognormal(zero = "sdlog", min.support = LL, max.support = UL),
data = ldata2, trace = TRUE)
coef(fit1, matrix = TRUE)
vcov(fit1)
##############################################################
# Fitting a truncated lognormal distribution - zero = NULL
fit2 <- vglm(y1 ~ x2, trunclognormal(zero = NULL, min.support = LL, max.support = UL),
data = ldata2, trace = TRUE)
coef(fit2, matrix = TRUE)
vcov(fit2)
##############################################################
# Mimicking lognormal()
fit3 <- vglm(y1 ~ x2, trunclognormal(zero = "sdlog"),
data = ldata2, trace = TRUE)
coef(fit3, mat = TRUE)
# Same as
fit3bis <- vglm(y1 ~ x2, lognormal(zero = "sdlog"),
data = ldata2, trace = TRUE)
coef(fit3bis, mat = TRUE)
Run the code above in your browser using DataLab