挖泥机中的子集(MuMIn)-如果存在主要影响,则必须包括交互 [英] Subsetting in dredge (MuMIn) - must include interaction if main effects are present

查看:179
本文介绍了挖泥机中的子集(MuMIn)-如果存在主要影响,则必须包括交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用挖泥机{MuMIn}做一些探索性工作.在此过程中,我希望将两个变量设置为仅在它们之间存在相互作用时才允许一起使用,即它们不能仅作为主要效果一起存在.

I'm doing some exploratory work where I use dredge{MuMIn}. In this procedure there are two variables that I want to set to be allowed together ONLY when the interaction between them is present, i.e. they can not be present together only as main effects.

使用示例数据:我想对模型fm1进行疏通(不考虑它可能没有任何意义).如果变量GNP和人口同时出现,则它们还必须包括它们之间的相互作用.

Using sample data: I want to dredge the model fm1 (disregarding that it probably doesn't make sense). If the variables GNP and Population appear together, they must also include the interaction between them.

require(stats); require(graphics)
## give the data set in the form it is used in S-PLUS:
longley.x <- data.matrix(longley[, 1:6])
longley.y <- longley[, "Employed"]
pairs(longley, main = "longley data")
names(longley)
fm1 <- lm(Employed ~GNP*Population*Armed.Forces, data = longley)
summary(fm1)
dredge(fm1, subset=!((GNP:Population) & !(GNP + Population)))
dredge(fm1, subset=!((GNP:Population) && !(GNP + Population)))

dredge(fm1, subset=dc(GNP+Population,GNP:Population))
dredge(fm1, subset=dc(GNP+Population,GNP*Population))

我如何在dredge()中指定应忽略所有存在国民生产总值和人口的模型,而不是它们之间的相互作用?

How can I specify in dredge() that it should disregard all models where GNP and Population are present, but not the interaction between them?

推荐答案

如果我理解得很好,则希望对两个主要效果进行建模(例如, a b )以及它们之间的互动( a:b ).那么如何:subset = !a | (xor(a, b) | 'a:b')(将a:b括在反引号(`)中,而不是直接引号),例如:

If I understand well, you want to model the two main effects (say, a and b) only together with their interaction (a:b). So how about: subset = !a | (xor(a, b) | 'a:b') (enclose a:b in backticks (`) not straight quotes), e.g:

library(MuMIn)
data(Cement)
fm <- lm(y ~ X1 * X2, Cement, na.action = na.fail)
dredge(fm, subset = !X2 | (xor(X1, X2) | `X1:X2`))

或将此条件包装到函数中以使代码更清晰:

or wrap this condition into a function to have the code more clear:

test <- function(a, b, c) !a | (xor(a, b) | c)
dredge(fm, subset = test(X1, X2, `X1:X2`))

产生以下内容的

: X1 X2 X1 * X2 (但不包括 X1 + X2 )

that produces: null, X1, X2, X1*X2 (and excludes X1 + X2)

这篇关于挖泥机中的子集(MuMIn)-如果存在主要影响,则必须包括交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆