# load 'gammi' package
library(gammi)
# load 'exam' help file
?exam
# load data
data(exam)
# header of data
head(exam)
# fit model
mod <- gammi(Exam.score ~ VRQ.score, data = exam,
random = ~ (1 | Primary.school) + (1 | Secondary.school))
# plot results (using S3 method)
plot(mod, include.random = FALSE)
# plot results (using visualizer)
xnew <- seq(min(exam$VRQ.score), max(exam$VRQ.score), length.out = 400)
pred <- predict(mod, newdata = data.frame(VRQ.score = xnew),
type = "terms", conf.int = TRUE)
visualizer1(x = xnew, y = pred$fit, lwr = pred$lwr, upr = pred$upr,
xlab = "VRQ.score", ylab = "Exam.score", main = "VRQ.score effect")
Run the code above in your browser using DataLab