【问题标题】:R - Subsetting in dredge (MuMin) – only include interaction with b if also an interaction with aR - 挖泥机中的子集 (MuMin) - 如果还与 a 交互,则仅包括与 b 的交互
【发布时间】:2018-06-18 10:52:22
【问题描述】:

我想使用 dredge::MuMIn 来探索我的数据。如果变量和GISalt 之间也存在交互,我只想包含I(GISalt^2) 和其他环境变量之一之间的交互。

例如我想保留:

(GISalt * Forest) AND (I(GISalt^2) * Forest)
mod1 <- glm(MLE2017 ~ MLE200405 + (GISalt * Forest) + Scrub + I(GISalt^2) * Forest)

(GISalt * Forest) but NOT I(GISalt^2) * Forest)
mod2 <- glm(MLE2017 ~ MLE200405 + (GISalt * Forest) + Scrub)

并排除:

I(GISalt^2) * Forest) 但不是 GISalt * Forest) mod3

包含dredge() 的所有变量的全局模型

globmod <- glm(MLE2017 ~ MLE200405 + GISalt * Forest + GISalt * Scrub 
    + GISalt * Meadow + GISalt * RiverLgthm + GISalt * DailySunHrs  + 
    I(GISalt^2) * Forest + I(GISalt^2) * Scrub + I(GISalt^2) * Meadow +
    I(GISalt^2) * RiverLgthm + I(GISalt^2) * DailySunHrs, 
    data = GLMdata, family = x.quasipoisson(link = "log"))

【问题讨论】:

    标签: r variables subset interaction mumin


    【解决方案1】:

    您需要dc(I(A^2):B, A:B) 或更明确的!{I(A^2):B} || {A:B} 形式的表达式,即“没有A^2 * BA * B”或(请注意,R 公式中的A*BA+B+A:B 的简写,其中A:B 是实际的交互项)。 dredge 中没有现成的方式将 B 扩展为“任何其他变量”,但您可以为术语列表生成合适的表达式。

    如果通用表达式为!{I(A^2):VARIABLE} || {A:VARIABLE},则可以使用substitute,将名称VARIABLE替换为实际变量名。

    substitute((!{I(A^2):VARIABLE} || {A:VARIABLE}), list(VARIABLE = as.name("B")))
    

    产生!{I(A^2):B} || {A:B}。使用&amp;&amp; 运算符为每个“其他变量”创建这样的表达式。 将所有内容包装在一个函数中:

    makeRule <- function(...) {
        exprList <- lapply(sys.call()[-1], function(x) substitute((! {I(A^2):VAR} || {A:VAR}), list(VAR = x)))
        rval <- exprList[[1]]
        for(x in exprList[-1]) rval <- call("&&", rval, x)
        rval
    }
    

    然后:

     subsetExpr <- makeRule(B,C,D,E)
    
     dredge(model, subset = subsetExpr)
    

    【讨论】:

      猜你喜欢
      • 2014-04-10
      • 1970-01-01
      • 2013-09-20
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 2019-04-09
      • 1970-01-01
      相关资源
      最近更新 更多