简体   繁体   English

MuMIn::dredge()。 仅排除包含主效应的模型,仅保留具有交互作用的模型

[英]MuMIn::dredge(). Exclude models only including main effect, keep only models with interactions

Is it possible to make a general logical statement for subsetting away (exclude) all potential models that only include the main effect of eg A?是否可以为子集化(排除)所有仅包括例如 A 的主要影响的潜在模型做出一般逻辑陈述?

y ~ A + B + C + A:C + A:B y ~ A + B + C + A:C + A:B

For models including A, only include those where A is a part of an interaction (as the relationship y~A would make no sense by itself).对于包括 A 的模型,只包括那些 A 是交互一部分的模型(因为关系 y~A 本身没有意义)。

Either !A || {A:B} || {A:C} 要么!A || {A:B} || {A:C} !A || {A:B} || {A:C} !A || {A:B} || {A:C} or dc(A:B, A) && dc(A:C, A) but there is no notation for specifying "any interaction containing A". !A || {A:B} || {A:C}dc(A:B, A) && dc(A:C, A)但没有指定“任何包含A的交互”的符号。

Update: In MuMIn >= 1.42.3 (for the time being, on R-Forge) you can use the dot . 更新:在MuMIn> = 1.42.3(暂时在R-Forge上)中,您可以使用点. pseudo-function to specify any or all interaction containing specific first-order term. 伪函数,用于指定包含特定一阶项的任何或所有交互。 For example .(A, 2:100) includes models if they contain any 2nd to 100-th order interaction terms with A . 例如.(A, 2:100)如果包含与A任何2到100阶交互项,则包括模型。 It is still experimental feature, so check if you get what you expected. 它仍然是实验性功能,因此请检查您是否达到了预期。

An inelegant solution I arrived at (after noticing how dredge() worked with poly() terms; including or excluding the entire nx power matrix, not the individual columns) was to create a little function called "int" to create a similar matrix out of two predictors and their interaction.我得出的一个不优雅的解决方案(在注意到 dredge() 如何与 poly() 项一起工作;包括或排除整个 nx 幂矩阵,而不是各个列)是创建一个名为“int”的小函数来创建一个类似的矩阵两个预测变量及其相互作用。 I called the elements produced "a", "b", and "a:b" following the convention of poly(), which calls its two elements "1" and "2".根据 poly() 的约定,我将产生的元素称为“a”、“b”和“a:b”,poly() 将其两个元素称为“1”和“2”。

int = function(a,b){
      matOut = matrix(c(a,b,a*b),nrow=length(a))
      dimnames(matOut) =list(NULL,c("a","b","a:b"))
      return(matOut)}

Let's use the mtcars data set as an example, using "carb" instead of A, "gear" instead of B, and "am" instead of C to predict "mpg".我们以mtcars数据集为例,用“carb”代替A,用“gear”代替B,用“am”代替C来预测“mpg”。 Starting with the standard approach, we might try this.从标准方法开始,我们可以试试这个。

require(MuMIn)
data(mtcars)

fm = lm(mpg ~ carb*gear + carb*am, mtcars,na.action=na.fail)
length(dredge(fm))

This produces 11 possible models with all combinations of the three linear terms and the two interaction terms.这会产生 11 个可能的模型,其中包含三个线性项和两个交互项的所有组合。

Now, if we use int() instead of *, we see we only get four models;现在,如果我们使用 int() 而不是 *,我们会看到我们只得到四个模型; each interaction, their combination, and the null model.每个交互、它们的组合和空模型。 All models are excluded that contain linear terms without the interaction.排除包含没有交互作用的线性项的所有模型。

fm = lm(mpg ~ int(carb,gear) + int(carb,am), mtcars,na.action=na.fail)
length(dredge(fm))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM