Home R - Subsetting in dredge (MuMin) – only include interaction with b if also an interaction with a
Reply: 1

R - Subsetting in dredge (MuMin) – only include interaction with b if also an interaction with a

green_chilli
1#
green_chilli Published in 2018-01-09 11:49:59Z

I am new to R and a first-time poster here so forgive me if I haven’t phrased this quite right…

I am wanting to use dredge::MuMIn to explore my data. I only want to include an interaction between I(GISalt^2) and one of the other environmental variables if there is also an interaction between the variable and GISalt.

e.g. I would like to keep:

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

and

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

and to exclude:

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

global model containing all variables for 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"))

Many thanks in advance

Kamil Bartoń
2#
Kamil Bartoń Reply to 2018-01-13 21:42:16Z

You need an expression of form dc(I(A^2):B, A:B) or, more explicitly !{I(A^2):B} || {A:B}, i.e. "either no A^2 * B, or A * B" or (note that A*B in an R formula is a shorthand for A+B+A:B, where A:B is the actual interaction term). There is no out-of-box way in dredge to expand B to "any other variable", but you can generate a suitable expression for a list of terms.

If the general expression is !{I(A^2):VARIABLE} || {A:VARIABLE}, you can use substitute to well, substitute the name VARIABLE with an actual variable name.

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

yields !{I(A^2):B} || {A:B}. Create such expression for each of "the other variables" using && operator. Wrapping all that in a function:

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
}

then:

 subsetExpr <- makeRule(B,C,D,E)

 dredge(model, subset = subsetExpr)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315192 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO