我拟合了一个以块为固定因子的线性模型,加上 2 个分类和 1 个连续预测变量。我想要一个 III 型 ANCOVA 表,其中所有效果均按块计算。
dput(rye)
structure(list(strain = c("S23", "S23", "S23", "S23", "S23",
"S23", "S23", "S23", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ", "NZ",
"NZ", "X", "X", "X", "X", "X", "X", "X", "X", "Kent", "Kent",
"Kent", "Kent", "Kent", "Kent", "Kent", "Kent"), manure = c("H",
"H", "H", "H", "A", "A", "A", "A", "H", "H", "H", "H", "A", "A",
"A", "A", "H", "H", "H", "H", "A", "A", "A", "A", "H", "H", "H",
"H", "A", "A", "A", "A"), block = c(1, 2, 3, 4, 1, 2, 3, 4, 1,
2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2,
3, 4), yield = c(299, 318, 284, 279, 247, 202, 171, 183, 315,
247, 289, 307, 257, 175, 188, 174, 403, 439, 355, 324, 222, 170,
192, 176, 382, 353, 383, 310, 233, 246, 200, 143), moisture = c(65.4073415007189,
37.0145280041042, 73.2225001374652, 39.9941837349335, 74.803410076096,
42.8914147357587, 50.792780124357, 55.0153723560264, 47.217016572995,
62.3885361519854, 53.7388755272386, 24.6856936491391, 34.8364200180523,
37.9399805638271, 37.7866881025361, 58.1848457395229, 39.2165119122411,
45.0354704343593, 55.1876133744328, 42.272547076364, 61.2191532302273,
62.5368880571047, 36.1336423251218, 40.8096323034628, 23.8425007638943,
55.7644071035274, 66.9264524519492, 49.8050708164737, 60.5314496784137,
82.4221025517919, 52.8870034752968, 54.0634811725579)), row.names = c(NA,
-32L), spec = structure(list(cols = list(strain = structure(list(), class = c("collector_character",
"collector")), manure = structure(list(), class = c("collector_character",
"collector")), block = structure(list(), class = c("collector_double",
"collector")), yield = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x7ff0af81bf90>, class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
rye_lm <- lm(yield ~ block + strain*manure*moisture, data = rye)
我可以获得连续预测变量的 F 值和 P 值的唯一方法,以及与分类变量的交互项是joint_tests(rye_lm)
,这给出
model term df1 df2 F.ratio p.value
block 1 15 20.144 0.0004
strain 3 15 3.742 0.0345
manure 1 15 144.076 <.0001
moisture 1 15 0.175 0.6820
strain:manure 3 15 6.001 0.0068
strain:moisture 3 15 1.554 0.2419
manure:moisture 1 15 1.128 0.3050
strain:manure:moisture 3 15 0.567 0.6452
这类似于这里的建议,为什么joint_tests函数(emmeans包)的结果没有显示模型的交互之一?
使用这些代码仅给出分类预测变量的 ANOVA 表
rye_emm <- emmeans(rye_lm, c("strain", "manure", "moisture"))
joint_tests(rye_emm)
model term df1 df2 F.ratio p.value
strain 3 15 3.966 0.0289
manure 1 15 162.312 <.0001
strain:manure 3 15 6.178 0.0060
如何更改我的代码,以便在没有块的情况下获得 2 个分类、连续预测变量及其交互的 F 比率和 p 值?非常感谢!!