1

我想用 R 运行一个组间设计 MANCOVA,有两个因变量(计划内和计划外),两个主题间变量(类型 [男性,女性] 和 Urb [是,否]),一个主题内变量(期间[之前,期间])和一个协变量(BMI)。

这是我所做的(有关类似计算,请参见此处:https ://stats.stackexchange.com/questions/183441/correct-way-to-perform-a-one-way-within-subjects-manova-in- r ):

# Create dummy data
data <- data.frame(Quest_before_planned = sample(1:100, 10),
                   Quest_during_planned = sample(1:100, 10),
                   Quest_before_unplanned = sample(1:100, 10),
                   Quest_during_unplanned = sample(1:100, 10),
                   Genre = sample(rep(c("Male", "Female"), each = 5)),
                   Urb = sample(rep(c("Yes", "No"), each = 5)),
                   BMI = sample(1:100, 10))

# Define the within-subjects factor
period <- as.factor(rep(c('before','during'), each = 2))
idata <- data.frame(period)

# Create the data structure for the linear model
data.model <- with(data, cbind(Quest_before_planned, Quest_during_planned,
                               Quest_before_unplanned, Quest_during_unplanned))

# Build the multivariate-linear model
mod.mlm <- lm(data.model ~ Genre * Urb, data = data_total)

# Run the MANOVA
mav.blpaq <- Anova(mod.mlm, idata = idata, idesign = ~ period, type = 2)
print(mav.blpaq)

因此,设计中的组间方差分析在这里效果很好。但是,我未能在该模型中添加协变量(即 BMI)。你知道我怎样才能做到这一点吗?


注意:我也尝试使用 (great) mancova()function ,其中包含一个协变量参数;但是有了这个函数,我不知道如何指定 Period 是一个主题内变量......

blpaq_macov <- mancova(data_tidy,
                       deps = c("Quest_planned", "Quest_unplanned"),
                       factors = c("Genre", "Period", "Urb"),
                       covs = "BMI",
                       multivar = "pillai")
4

0 回答 0