570 likes | 589 Views
Growth Modeling. The aim of growth modeling is to look at the rate of change of a variable over time. Example : attitudes, profits, working speed, life satisfaction. Potential growth patterns can be linear, quadratic, cubic, logarithmic, exponential.
E N D
The aim of growth modeling is to look at the rate of change of a variable over time. Example : attitudes, profits, working speed, life satisfaction. Potential growth patterns can be linear, quadratic, cubic, logarithmic, exponential. The hierarchy in the data is that time points are nested within people (or other entities).
Possible Growth Curves : Cubic Trend Quadratic Trend Linear Trend
Two important things : Growth curve can be fitted up to one less than the number of time points that we have. Example : With three time points, a linear and quadratic growth curve can be fitted. 2. A growth curve is defined by a power function. Linear (Time) Quadratic (Time*Time) Cubic (Time*Time*Time) Quartic (Time*Time*Time*Time)
Person : 115 subject • Gender : 0, 1 • Time : 4 points of time : • Satisfaction Base (0) • Satisfaction 6 Months (1) • Satisfaction 12 Months (2) • Satisfaction 18 Months (3) • LS : Life Satisfaction on a 10-point scale (0 = completely dissatisfied, 10 = completely satisfied)
Data setwd) satisfactionData <- read.delim("LS_Data.dat", header=TRUE) library("reshape") LS <- melt(satisfactionData,id=c("Person","Gender"), measured=c("Satisfaction_Base", "Satisfaction_6_Months","Satisfaction_12_Months", "Satisfaction_18_Months")) Time<-c(rep(0,115),rep(1,115),rep(2,115),rep(3,115)) LS$Time<-Time rm(Time) head(LS)
Data LS_Data<- data.frame(Person = LS$Person, Gender=LS$Gender, Time =LS$Time, LS=LS$value) head(LS_Data)
Nonlinear Mixed Effects Models (nlme) install.packages(“nlme”) library("nlme")
Model 1 Intercept-only ; no predictors Model is specified as y ~ 1 Code : intercept <- gls(LS ~ 1, data=LS_Data, method="ML", na.action=na.exclude) Pred_Y1 <- predict(intercept) # Predicted Y / Regression Line Pred_Y1 <- as.vector(Pred_Y) summary(intercept) intervals(intercept)
Model 1 head(LS_D1) Person Gender Time LS Pred_Y 1 1 0 0 6 5.988584 2 1 0 1 6 5.988584 3 1 0 2 5 5.988584 4 1 0 3 2 5.988584 5 2 1 0 7 5.988584 6 2 1 1 7 5.988584
Model 2 Intercept vary across people : Code : randomIntercept <- lme(LS ~ 1, data = LS_Data, random = ~1|Person, method = "ML", na.action = na.exclude, control = list(opt="optim"))
Model 2 Pred_Y2 <- predict(randomIntercept) Pred_Y2 <- as.vector(Pred_Y2) summary(randomIntercept) intervals(randomIntercept)
Model 2 head(LS_D2) Person Gender Time LS Pred_Y 1 1 0 0 6 5.084936 2 1 0 1 6 5.084936 3 1 0 2 5 5.084936 4 1 0 3 2 5.084936 5 2 1 0 7 6.355934 6 2 1 1 7 6.355934
Footer text: to modify choose 'View' (Office 2003 or earlier) or 'Insert' (Office 2007 or later) then 'Header & Footer'
Model 3 Random Intercept across people + Time as a predictor : Time as a fixed effect Code : timeRI <- update(randomIntercept, .~. + Time) timeRI <- lme(LS ~ Time, data = LS_Data, random = ~1|Person, method = "ML", na.action = na.exclude, control = list(opt="optim"))
Model 3 Code : Pred_Y3 <- predict(timeRI) Pred_Y3 <- as.vector(Pred_Y3) summary(timeRI) intervals(timeRI) coef(timeRI)
Model 3 head(coef(timeRI)) (Intercept) Time 1 6.269597 -0.8772182 2 7.707617 -0.8772182 3 5.242440 -0.8772182 4 6.475028 -0.8772182 5 7.502185 -0.8772182 6 6.680460 -0.8772182
Footer text: to modify choose 'View' (Office 2003 or earlier) or 'Insert' (Office 2007 or later) then 'Header & Footer'
Growth Modeling Rate of development /growth over time differs within entities
Model 4 Effect of Time across people : timeRS <- update(timeRI, random = ~Time|Person) or timeRS <- lme(LS ~ Time, data = LS_Data, random = ~Time|Person, method = "ML", na.action = na.exclude, control = list(opt="optim"))
Model 4 Pred_Y4 <- predict(timeRS) Pred_Y4 <- as.vector(Pred_Y4) summary(timeRS) intervals(timeRS) coef(timeRS)
Model 4 head(coef(timeRS)) (Intercept) Time 1 6.338484 -0.9234636 2 7.705109 -0.8732796 3 5.198861 -0.8586077 4 6.725606 -1.0345095 5 7.317987 -0.7622338 6 6.814232 -0.9616653
Model 5 First Order Autoregressive ARModel <- update(timeRS, correlation = corAR1(0, form = ~Time|Person)) ARModel <- lme(LS ~ Time, data = LS_Data, random = ~Time|Person, method = "ML", na.action = na.exclude, control = list(opt="optim"), correlation = corAR1(0, form = ~Time|Person))
Model 5 Pred_Y5 <- predict(ARModel) Pred_Y5 <- as.vector(Pred_Y5) summary(ARModel) intervals(ARModel) coef(ARModel)
Model 5 head(coef(ARModel)) (Intercept) Time 1 6.296443 -0.8711929 2 7.528736 -0.8702692 3 5.418097 -0.8692794 4 6.414589 -0.8733059 5 7.409368 -0.8674247 6 6.569258 -0.8714521
Footer text: to modify choose 'View' (Office 2003 or earlier) or 'Insert' (Office 2007 or later) then 'Header & Footer'
Comparing 5 models : anova(intercept, randomIntercept, timeRI, timeRS, ARModel)
Footer text: to modify choose 'View' (Office 2003 or earlier) or 'Insert' (Office 2007 or later) then 'Header & Footer'
Quadratic TrendModel 6 If time is the predictor variable, a quadratic is tested by including a predictor timeQuadratic <- update(ARModel, .~. + I(Time^2)) Or : timeQuadratic <- lme(LS ~ Time+I(Time^2), data = LS_Data, random = ~Time|Person, method = "ML", na.action= na.exclude, control = list(opt="optim"), correlation = corAR1(0, form = ~Time|Person))
Cubic TrendModel 7 timeCubic<-update(timeQuadratic, .~. + I(Time^3)) timeCubic<- lme(LS ~ Time+I(Time^2)+I(Time^3), data = LS_Data, random = ~Time|Person, method = "ML", na.action= na.exclude, control = list(opt="optim"), correlation = corAR1(0, form = ~Time|Person))
Comparing 3 models : anova(ARModel, timeQuadratic, timeCubic)
Footer text: to modify choose 'View' (Office 2003 or earlier) or 'Insert' (Office 2007 or later) then 'Header & Footer'
Quadratic TrendModel 8 Update Model 3 : Mod8 <- update(timeRI, .~. + I(Time^2)) Mod8 <- lme(LS ~ Time+I(Time^2), data = LS_Data, random = ~1|Person, method = "ML", na.action= na.exclude, control = list(opt="optim"))
Model 8 summary(Mod8) intervals(Mod8) Pred_Y8 <- predict(Mod8) Pred_Y8 <- as.vector(Pred_Y8)
Model 8 coef(Mod8) head(coef(Mod8)) (Intercept) Time I(Time^2) 1 5.739092 0.7352972 -0.5512887 2 7.232865 0.7352972 -0.5512887 3 4.672111 0.7352972 -0.5512887 4 5.952488 0.7352972 -0.5512887 5 7.019469 0.7352972 -0.5512887 • 6.165884 0.7352972 -0.5512887
Model 8 # Data frame LS_D8 <- data.frame(Person = LS_Data$Person[c(1,116,231,346,2,117,232,347,3,118,233,348,4,119,234,349,5,120,235,350,6,121,236,351)], Gender=LS_Data$Gender[c(1,116,231,346,2,117,232,347,3,118,233,348,4,119,234,349,5,120,235,350,6,121,236,351)], Time =LS_Data$Time[c(1,116,231,346,2,117,232,347,3,118,233,348,4,119,234,349,5,120,235,350,6,121,236,351)], LS=LS_Data$LS[c(1,116,231,346,2,117,232,347,3,118,233,348,4,119,234,349,5,120,235,350,6,121,236,351)], Pred_Y=Pred_Y8[c(1,116,231,346,2,117,232,347,3,118,233,348,4,119,234,349,5,120,235,350,6,121,236,351)])
Model 8 head(LS_D8) Person Gender Time LS Pred_Y 1 1 0 0 6 5.739092 2 1 0 1 6 5.923100 3 1 0 2 5 5.004531 4 1 0 3 2 2.983385 5 2 1 0 7 7.232865 6 2 1 1 7 7.416873
Model 8 ## GGPLOT library(ggplot2) plot <- ggplot(LS_D8, aes(x=LS_D8[,3], y=LS_D8[,5],colour=factor(LS_D8[,1]))) plot + layer(geom="point") + layer(geom="line")+ xlab("Time")+ylab("LS")+ ggtitle("Regression Line / Predicted Y")+labs(colour= "Person")
Footer text: to modify choose 'View' (Office 2003 or earlier) or 'Insert' (Office 2007 or later) then 'Header & Footer'
Cubic TrendModel 9 Mod9 <-update(Mod8, .~. + I(Time^3)) Mod9 <- lme(LS ~ Time+I(Time^2) +I(Time^3), data = LS_Data, random = ~1|Person, method = "ML", na.action= na.exclude, control = list(opt="optim"))
Model 9 Code : summary(Mod9) intervals(Mod9) Pred_Y9 <- predict(Mod9) Pred_Y9 <- as.vector(Pred_Y9)