【问题标题】:Plotting Growth Curve with Quadratic Growth用二次增长绘制增长曲线
【发布时间】:2020-10-09 02:42:30
【问题描述】:

我正在尝试了解如何在 R 中为我一直在运行的增长曲线模型绘制二次增长。 型号:

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

时间 (B = 9.58, p<.01 time_square p>

如果我使用 plot_model,它会为我提供每个组的最佳拟合线。

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

有没有办法绘制拟合曲线或二次增长,以显示增长速度随着时间的推移而减慢?

谢谢!

【问题讨论】:

  • lme4中没有plot_model函数。
  • 我猜这是关于sjPLot::plot_model,因为语法适合那个函数。

标签: r ggplot2 lme4


【解决方案1】:

要让sjPlot::plot_model 了解发生了什么,您必须将Time_Square 作为I(Time^2) 输入,而不是作为单独的预测变量。

鉴于df$Time_Square &lt;- df$Time^2,以下两个模型应该会给您相同的结果:

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)

但是,在第二个模型中,很明显预测变量 Time 输入了两次,因此在使用 sjPlot::plot_model(...) 绘制它时可以将其考虑在内。

为确保,我使用以下模拟数据对其进行了测试:

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"))

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2012-07-21
    • 2015-05-26
    • 1970-01-01
    • 2020-03-15
    相关资源
    最近更新 更多