简体   繁体   中英

Plotting Growth Curve with Quadratic Growth

I am trying to see how I can plot quadratic growth in R for a growth curve model I've been running. Model:

m1 <- lmer(score ~ Time + Group + Time_Sqaure + 
                      (1 + School | Subject), data=df, REML = FALSE)
tab_model(m1)

Both Time (B = 9.58, p<.01) and Time_Square (B = - 0.51, p <.01) along with Group (B = 2.77, p <.01) differences are significant.

If I use plot_model, it gives me the best fit line for each group.

plot_model(m1, type = "pred", terms = c("Time", "Group"))

Is there a way to plot the fitted curves or quadratic growth that shows the rate of growth slowing over time?

Thanks!

For sjPlot::plot_model to understand what is going on, you have to enter Time_Square as I(Time^2) not as a separate predictor.

Given that df$Time_Square <- df$Time^2 , the following two models should give you the same results:

m1 <- lmer(score ~ Time + Group + Time_Square + 
                      (1 + School | Subject), data=df, REML = FALSE)
m2 <- lmer(score ~ Time + Group + I(Time^2) + 
                      (1 + School | Subject), data=df, REML = FALSE)

However, in the second model, it is clear that the predictor Time is entered twice and so it can be taken into account when plotting it with sjPlot::plot_model(...) .

To make sure, I tested it with the following simulated data:

library(dplyr)

grps <- 2 #number of groups
subj <- 100 #number of subjects within group
obs <- 10 #number of observations/times per subjects

b_0 <- 0 #overall intercept
b_1 <- 9.58 #linear time effect
b_2 <- -0.51 #quadratic time effect

sd_b0 <- 0.4 #SD of random intercept per subject
sd_b1 <- 3 #SD of random slope per subject
sd_b3 <- 1 #SD of group effect (you can simulate more than 2 groups)
sd_resid <- 10 #SD of residuals

df <- list(Group = factor(rep(letters[1:grps], each=obs*subj)),
           Subject = factor(rep(1:subj, times=grps, each=obs)),
           Time = rep(1:obs, times=subj*grps)
           ) %>% as.data.frame()
df$TimeSq <- df$Time^2

subj_b0 <- rnorm(subj, b_0, sd_b0) %>% rep(times=grps, each=obs)
subj_b1 <- rnorm(subj, b_1, sd_b1) %>% rep(times=grps, each=obs)
grp_m <- rnorm(grps, 0, sd_b3) %>% rep(times=, each=subj*obs)

df$Score <- with(df, subj_b0 + Time*subj_b1 + (Time^2)*b_2 + grp_m + rnorm(grps*subj*obs, 0, sd_resid))

fit1 <- lme4::lmer(Score ~ Time + I(Time^2) + Group + (Time | Subject), data=df)

sjPlot::plot_model(fit1, type="pred", terms=c("Time"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM