I had the dataframe 'dat' with the columns 'subject_id' and 'boredom'.
names(dat)
subject_id无聊
还有第二个数据帧' fig2.int'使用列' subject_id',' age'和'性别'。
names(fig2.int)
subject_id质量年龄性别
两个数据框都已合并:
dat2 <- merge(dat,fig2.int[c("subject_id","age","gender")],by="subject_id", all.x=T)
names(dat1)
subject_id质量无聊年龄性别
dat1$gender
1,0,1,1,0,NA 然后我做了线性混合模型(LMM)
library(lme4)
空模型:
mod_zero <- lmer(quality ~ 1 + (1|subject_id), dat2)
summary(mod_zero)
输出:
Number of obs: 1037, groups: subject_id, 119
我从“性别”开始依次添加变量:
mod_one <- lmer(quality ~ gender + (1|subject_id), dat2)
summary(mod_one)
输出:
Number of obs: 1037, groups: subject_id, 118
组数从119减少到118.当添加其他变量时,组数没有变化。栏目的性别&#39;有一个缺失值(NA
)。性别只是一个控制变量,我想保持参与者。我读到merge()
删除了包含NA的行,但all.x=T
或all=T
应该保留NA。这没用。有人有想法吗?我累了aggregate()
,但根本没用。提前感谢,Andrea