# Replicate the Stage 1 results that were obtained in
# Case study 1 of Chapter 4 in Van der Elst (2023)
# ---------------------------------------------------
library(NormData) # load the NormData package
data(GCSE) # load the GCSE dataset
# Conduct the Stage 1 analysis
Model.1.GCSE <- Stage.1(Dataset=GCSE,
Model=Science.Exam~Gender)
summary(Model.1.GCSE)
plot(Model.1.GCSE)
# Replicate the Stage 1 results that were obtained in
# Case study 1 of Chapter 7 in Van der Elst (2023)
# ---------------------------------------------------
library(NormData) # load the NormData package
data(Substitution) # load the Substitution dataset
# Add the variable Age.C (= Age centered) and its
# quadratic and cubic terms to the Substitution dataset
Substitution$Age.C <- Substitution$Age - 50
Substitution$Age.C2 <- (Substitution$Age - 50)**2
Substitution$Age.C3 <- (Substitution$Age - 50)**3
# Fit the full Stage 1 model
Substitution.Model.1 <- Stage.1(Dataset=Substitution,
Model=LDST~Age.C+Age.C2+Age.C3+Gender+LE+Age.C:LE+
Gender:LE+Age.C:Gender, Alpha=0.005)
summary(Substitution.Model.1)
# Fit the model in which the non-significant Age.C:Gender
# interaction term is removed
Substitution.Model.2 <- Stage.1(Dataset=Substitution,
Alpha=0.005,
Model=LDST~Age.C+Age.C2+Age.C3+Gender+LE+
Age.C:LE+Gender:LE)
summary(Substitution.Model.2)
# Evaluate the significance of the Gender:LE interaction term
# GLT is used because the interaction involves multiple regression
# parameters
GLT.1 <- GLT(Dataset=Substitution, Alpha=0.005,
Unrestricted.Model=LDST~Age.C+Age.C2+Age.C3+
Gender+LE+Age.C:LE+Gender:LE,
Restricted.Model=LDST~Age.C+Age.C2+Age.C3+
Gender+LE+Age.C:LE)
summary(GLT.1)
# Fit the model in which the non-significant Gender:LE
# interaction term is removed
Substitution.Model.3 <- Stage.1(Dataset=Substitution,
Alpha=0.005,
Model=LDST~Age.C+Age.C2+Age.C3+Gender+LE+Age.C:LE)
summary(Substitution.Model.3)
# Evaluate the significance of the Age:LE interaction
# using the General Linear Test framework
GLT.2 <- GLT(Dataset=Substitution,
Unrestricted.Model=LDST~Age.C+Age.C2+Age.C3+Gender+LE+Age.C:LE,
Restricted.Model=LDST~Age.C+Age.C2+Age.C3+Gender+LE, Alpha=0.005)
summary(GLT.2)
# Fit the model in which the non-significant Age_c:LE
# interaction term is removed
Substitution.Model.4 <- Stage.1(Dataset=Substitution,
Alpha=0.005, Model=LDST~Age.C+Age.C2+Age.C3+Gender+LE)
summary(Substitution.Model.4)
# Fit the model in which the non-significant Age.C3 term is removed
Substitution.Model.5 <- Stage.1(Dataset=Substitution,
Alpha=0.005, Model=LDST~Age.C+Age.C2+Gender+LE)
summary(Substitution.Model.5)
# Fit the model in which the non-significant Age.C2 term is removed
Substitution.Model.6 <- Stage.1(Dataset=Substitution,
Alpha=0.005, Model=LDST~Age.C+Gender+LE)
summary(Substitution.Model.6)
# Fit the model in which the non-significant main effect of Gender
# is removed
Substitution.Model.7 <- Stage.1(Dataset=Substitution,
Alpha=0.005, Model=LDST~Age.C+LE)
summary(Substitution.Model.7)
plot(Substitution.Model.7, Normality = FALSE, Outliers = FALSE)
# Check the significance of LE using the GLT framework
GLT.3 <- GLT(Dataset=Substitution, Alpha=0.005,
Unrestricted.Model=LDST~Age.C+LE,
Restricted.Model=LDST~Age.C)
summary(GLT.3)
# Residual variance function. Substitution.Model.7 uses
# a cubic polynomial variance prediction function.
# Remove cubic Pred.Y term from Substitution.Model.7, so
# fit quadratic variance prediction function
Substitution.Model.8 <- Stage.1(Dataset=Substitution,
Alpha=0.005, Model=LDST~Age.C+LE,
Order.Poly.Var=2) # Order.Poly.Var=2 specifies a quadratic polynomial
# for the variiance prediction function
summary(Substitution.Model.8)
plot(Substitution.Model.8, Normality = FALSE, Outliers = FALSE)
# Remove quadratic Pred.Y term, so fit linear variance
# prediction function
Substitution.Model.9 <- Stage.1(Dataset=Substitution,
Alpha=0.005, Model=LDST~Age.C+LE,
Order.Poly.Var=1) # Order.Poly.Var=1 specifies a linear polynomial
# for the variiance prediction function
# Final Stage 1 model
summary(Substitution.Model.9)
plot(Substitution.Model.9)
Run the code above in your browser using DataLab