# Simulate data 1
n <- 10 # number of levels
m <- 200 # number of observations
set.seed(2016)
level <- as.factor(floor(runif(m) * n) + 1)
a0 <- rnorm(n)
sigma <- 0.4
mu <- a0[level]
y <- mu + sigma * rnorm(m)
plot(y~level)
points(1:10,a0, col="red")
da1 <- data.frame(y, level)
#------------------
mn <- gamlss(y~1,data=da1 ) # null model
ms <- gamlss(y~level-1, data=da1) # saturated model
m1 <- gamlss(y~pcat(level), data=da1) # calculating lambda ML
AIC(mn, ms, m1)
if (FALSE) {
m11 <- gamlss(y~pcat(level, method="GAIC", k=log(200)), data=da1) # GAIC
AIC(mn, ms, m1, m11)
#gettng the fitted object -----------------------------------------------------
getSmo(m1)
coef(getSmo(m1))
fitted(getSmo(m1))[1:10]
plot(getSmo(m1)) #
# After the fit a new factor is created this factor has the reduced levels
levels(getSmo(m1)$factor)
# -----------------------------------------------------------------------------
}
Run the code above in your browser using DataLab