這是我的資料集的示例:
df <- data.frame(
id = c(13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65),
collection_point = c(rep(c("Baseline", "Immediate", "3M"), each=28)),
intervention = c(rep(c("B", "A", "C", "B", "C", "A", "A", "B", "A", "C", "B", "C",
"A", "A", "B", "A", "C", "B", "C", "A", "A"), each = 4)),
scale_A = c(6.5, 7.0, 6.25, 6.0, NA, 7.5, 7.5,
8.0, 7.5, 6.75, 7.5, 6.75, 6.75, 6.5,
5.75, 6.75, 7.75, 7.5, 7.75, 7.25, 7.75,
7.25, 7.25, 5.75, 6.75, NA, 6.75, 7.5,
6.75, 7.0, 6.5, 7.0, 7.5, 7.5, 7.5,
7.75, 7.25, 7.25, 7.25, 7.5, 6.5, 6.25,
6.25, 7.25, 7.5, 6.75, 7.25, 7.25, 7.5,
7.25, 7.5, 7.25, NA, 7.0, 7.5, 7.5,
6.75, 7.25, 6.5, 7.0, 7.5, 7.5, 7.5,
7.75, 7.5, 7.5, 7.5, 7.5, 6.5, 5.75,
6.25, 6.75, 7.5, 7.25, 7.25, 7.5, 7.75,
7.75, 7.75, 7.5, NA, NA, NA, NA))
在哪里,
id = 參與者
collection_point = 從參與者收集資料的次數(重復測量)
干預 = 每個參與者被隨機分配到的組(固定效應)
scale_A = 每個參與者在每個資料收集點完成的問卷分數(結果)
參與者被隨機分配到三種干預措施中的一種,并在三個不同的時間點完成相同的量表(量表 A),以確定隨時間推移的任何改善。
為了解釋collection_point為重復測量,本來我這樣做:
mixed.lmer.A<-lmer(scale_A~intervention collection_point intervention*collection_point (1|collection_point), data = df)
從我讀過的內容來看,通常一個變數不是固定效應和隨機效應,但我不確定如何指定collection_point為重復測量。另外,當我運行模型時,R 說有 500 個觀察值。如果您將所有從基線到 3M 的觀察結果相加,這是有道理的,但只有 200 名參與者(一些參與者退出,因此觀察結果少于預期)。所以我認為 R 沒有考慮到重復問卷的參與者是同一個人這一事實?
我也試過這個:
mixed.lmer.A2<-lmer(scale_A~intervention collection_point intervention*collection_point (1 collection_point|id), data = df)
但是我收到一條錯誤訊息,指出 obs 的數量。<= 隨機效應的數量。
最后,我嘗試了這個,但我不確定這是否是解決問題的方法:
mixed.lmer.A3<-lmer(scale_A~intervention collection_point intervention*collection_point (1|collection_point/id), data = df)
任何幫助將不勝感激!我仍在學習 R 并且在使用 lmer 時遇到了一些困難。謝謝!
uj5u.com熱心網友回復:
您在 acollection_point和idgrouping中都進行了重復測量(而且它也不平衡,這會使繪圖有些困難。)(注意:分組不是獨立的,請參閱此答案底部的注釋)
看來您正在考慮intervention是利息的固定效應。由于您可能希望收集點的任何顯示都按照您將其呈現給資料框的順序進行,因此您需要它具有一個levels值和一個ordered標志。
collection_point = factor( c(rep(c("Baseline", "Immediate", "3M"), each=28)),
levels=c("Baseline", "Immediate", "3M"), ordered=TRUE)
模型搭建考慮這個,權威咨詢參考BBolker關于這個主題的頁面:https ://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#model-definition
> mixed.lmer.A1<-lmer(scale_A~intervention (1|id) (1|collection_point), data = df)
> summary(mixed.lmer.A1)
Linear mixed model fit by REML ['lmerMod']
Formula: scale_A ~ intervention (1 | id) (1 | collection_point)
Data: df
REML criterion at convergence: 70.4
Scaled residuals:
Min 1Q Median 3Q Max
-3.9506 -0.3416 0.1162 0.5891 1.4978
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 0.042109 0.20521
collection_point (Intercept) 0.008454 0.09195
Residual 0.099734 0.31581
Number of obs: 77, groups: id, 28; collection_point, 3
Fixed effects:
Estimate Std. Error t value
(Intercept) 7.38963 0.10002 73.880
interventionB -0.81671 0.12886 -6.338
interventionC -0.04588 0.12886 -0.356
Correlation of Fixed Effects:
(Intr) intrvB
interventnB -0.558
interventnC -0.558 0.433
另一種選擇可能是構建一個模型,該模型在三個收集點的有序時序中既具有干預效應又具有線性趨勢估計:
mixed.lmer.inter.trend <- lmer(scale_A~intervention as.numeric(collection_point)
(1|id),
data = df)
最后一個建議是在嘗試將收集點建模為固定效應后提出的,但得到了線性和二次估計(由有序因子的默認處理引起)。
在這種情況下,您可能只需要 (1|id)id 分組的成員都沒有參與多個系列的集合:
with(df, table( collection_point, id))
id
collection_point 13 14 15 16 17 18 19 20 21 22 23 24 29 30 31 32 33 34 35 36 37 38 39 40 62 63 64 65
Baseline 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Immediate 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3M 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/343036.html
下一篇:將資料幀中每一行中的向量分成兩半
