class <- read.csv("S:\\dept\\Brady\\ALMMUSSP\\Chapters\\Data, Syntax, and Output\\Chapter 4\\classroom.csv", h = T) library(nlme) # Model 4.1. model4.1.fit <- lme(mathgain ~ 1, random = ~1 | schoolid/classid, class, method = "REML") summary(model4.1.fit) random.effects(model4.1.fit) getVarCov(model4.1.fit) intervals(model4.1.fit) # Model 4.1A. model4.1A.fit <- lme(mathgain ~ 1, random = ~1 | schoolid, class, method = "REML") anova(model4.1.fit, model4.1A.fit) # Model 4.2. model4.2.fit <- lme(mathgain ~ mathkind + sex + minority + ses, random = ~1 | schoolid/classid, class, na.action = "na.omit", method = "REML") summary(model4.2.fit) # Model 4.1: ML estimation. model4.1.ml.fit <- lme(mathgain ~ 1, random = ~1 | schoolid/classid, class, method = "ML") # Model 4.2: ML estimation. model4.2.ml.fit <- lme(mathgain ~ mathkind + sex + minority + ses, random = ~1 | schoolid/classid, class, na.action = "na.omit", method = "ML") anova(model4.1.ml.fit, model4.2.ml.fit) # Model 4.3. model4.3.fit <- update(model4.2.fit, fixed = ~ mathkind + sex + minority + ses + yearstea + mathprep + mathknow) summary(model4.3.fit) # Model 4.4. model4.4.fit <- update(model4.2.fit, fixed = ~ mathkind + sex + minority + ses + housepov) summary(model4.4.fit)