首页 > 解决方案 > 对 R 中 ANOVA 的两个因子

问题描述

我有一些来自两种不同情况(癌症和正常)的菌落计数数据,用两种药物联合治疗:A(3 级)和 B(2 级)。对于菌落,我有不同的类型+总数,但我可以在不同的测试中查看不同的类型。

df <- data.frame( Patient = rep( 1:6, 6), Disease = rep( c( "cancer", "normal"), 18), DrugA = c( rep( 0, 12), rep( 30, 12), rep( 100, 12)), DrugB = rep( c( rep( 0, 6), rep( 2, 6)), 3), n.colonies = sample( 10:300, size = 36) )
head(df)

我的问题是我想比较两种情况(癌症和正常)之间每种治疗(药物A和药物B的组合)的差异。为此,我做了以下事情:

df$treatment.factor <- paste( df$DrugA, df$DrugB, sep = ".")
library(stats)
a <- aov( formula = n.colonies ~ Disease:treatment.factor, data = df)
summary(a)
TukeyHSD(a)

结果返回所有可能的组合,包括同一条件下的不同治疗选项。我有什么方法可以将测试组限制为仅使用相同的治疗。不同疾病的因素?我正在考虑只做感兴趣的 t 检验并纠正多重比较,但它似乎并不完全适合我。我还考虑对每个条件(基于 DrugB 分开)进行回归,但只有 3 个点(DrugA 的三个浓度)也无济于事。

有什么建议吗?谢谢!

爱德华多

标签: rlinear-regressionanova

解决方案


我不确定是否理解。也许你想要:

library(lsmeans)
lsmeans(a, pairwise ~ Disease:treatment.factor | treatment.factor)

$contrasts
treatment.factor = 0.0:
 contrast           estimate       SE df t.ratio p.value
 cancer - normal -101.333333 74.31826 24  -1.364  0.1854

treatment.factor = 0.2:
 contrast           estimate       SE df t.ratio p.value
 cancer - normal  -92.333333 74.31826 24  -1.242  0.2261

treatment.factor = 100.0:
 contrast           estimate       SE df t.ratio p.value
 cancer - normal   50.666667 74.31826 24   0.682  0.5019

treatment.factor = 100.2:
 contrast           estimate       SE df t.ratio p.value
 cancer - normal    1.666667 74.31826 24   0.022  0.9823

treatment.factor = 30.0:
 contrast           estimate       SE df t.ratio p.value
 cancer - normal    9.000000 74.31826 24   0.121  0.9046

treatment.factor = 30.2:
 contrast           estimate       SE df t.ratio p.value
 cancer - normal   79.333333 74.31826 24   1.067  0.2964

推荐阅读