# NOT RUN {
## Generate some data.
set.seed(111)
n <- 500
## Regressors.
d <- data.frame(fac = factor(rep(1:10, n/10)))
## Response.
d$y <- with(d, 1.5 + rnorm(10, sd = 0.6)[fac] +
rnorm(n, sd = 0.6))
# }
# NOT RUN {
## Estimate model.
b <- bamlss(y ~ s(fac,bs="re"), data = d)
summary(b)
## Plot random effects.
plot(b)
## Extract fitted values.
f <- fitted(b, model = "mu", term = "fac")
f <- cbind(d["fac"], f)
## Now use plotblock.
plotblock(f)
## Variations.
plotblock(f, fill.select = c(0, 1, 0, 1), col.poly = "red")
plotblock(f, fill.select = c(0, 1, 0, 1), col.poly = "lightgray",
lty = c(2, 1, 2), lwd = c(2, 1, 2))
# }
# NOT RUN {
## More examples.
plotblock(y ~ fac, data = d, range = c(0.45, 0.45))
d <- data.frame(fac = factor(rep(1:10, n/10)))
d$y <- with(d, c(2.67, 5, 6, 3, 4, 2, 6, 7, 9, 7.5)[fac])
plotblock(y ~ fac, data = d)
plotblock(cbind(y - 0.1, y + 0.1) ~ fac, data = d)
# }
Run the code above in your browser using DataCamp Workspace