簡體   English   中英

用二次增長繪制增長曲線

[英]Plotting Growth Curve with Quadratic Growth

我想看看如何為我一直在運行的增長曲線模型繪制 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 (B = - 0.51, p <.01) 以及組 (B = 2.77, p <.01) 差異均顯着。

如果我使用 plot_model,它會為我提供每個組的最佳擬合線。

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

有沒有辦法繪制擬合曲線或二次增長,以顯示增長速度隨時間放緩?

謝謝!

為了讓sjPlot::plot_model了解發生了什么,您必須輸入Time_Square作為I(Time^2)而不是作為單獨的預測變量。

鑒於df$Time_Square <- 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"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM