Julia Simons
Julia Simons

Reputation: 31

Subsetting with dredge function (MuMin)

I'm trying to subset a series of models dredged from a global model that has both linear & non-linear terms. There are no interactions e.g.

Glblm <- Y ~ X1 + X2 + X3 + I(X3^2) + X4 + X5 + X6 + I(X6^2) + X7 + I(X7^2)

I want to specify that X3^2 should never appear without X3, but X3 could appear alone without X3^2 (and the same for X6 & X7).

I have tried the following as I understood from the documentation:

ssm <-dredge (Glblm, subset=(X3| !I(X3^2)) && (X6| !I(X6^2)) && (X7| !I(X7^2))) 

I also tried making a subset first as I read https://stackoverflow.com/questions/55252019/dredge-in-mumin-r-keeps-models-with-higher-order-terms-without-their-respectiv e.g.

hbfsubset <- expression(  dc(X3, `I(X3^2)`) &  dc(`X6`, `I(X6^2)`)&  dc(`X7`, `I(X7^2)`))

ssm <-dredge (Glblm, subset=hbfsubset)

neither has produced a subset of models, instead the full list of models is returned when inspecting 'ssm' using:

model.sel(ssm)

Any help would be greatly appreciated.

Upvotes: 3

Views: 660

Answers (1)

Juan_814
Juan_814

Reputation: 124

A reproducible example from you is needed to pinpoint the issue, specifying what type of model you are fitting.

In simple linear models (lm, those examples provided in MuMIn handbook), the name of fitted terms is exactly the same as what you typed in the global model, but this may not be the case in more complex models (e.g. glmmTMB).

Here is an example:

library(MuMIn)
library(glmmTMB)

# a simple linear model, using Cement data from MuMIn
m1 <- lm(y ~ X1 + I(X1^2) + X2 + I(X2^2), data = Cement, na.action = "na.fail")

# dredge without a subset
d1 <- dredge(m1)
# 16 models produced

# dredge with a subset
d1_sub <- dredge(m1, subset = dc(`X1`, `I(X1^2)`) & dc(`X2`, `I(X2^2)`))
# 9 models produced, works totally fine


# a glmmTMB linear model
m2 <- glmmTMB(y ~ X1 + I(X1^2) + X2 + I(X2^2), data = Cement, na.action = "na.fail")

# dredge without a subset
d2 <- dredge(m2)
# 16 models produced

# dredge with a subset
d2_sub <- dredge(m2, subset = dc(`X1`, `I(X1^2)`) & dc(`X2`, `I(X2^2)`))
# 16 models produced, subset didn't work and no warning or error produced

# this is because the term names of a glmmTMB object in dredge() is not the same as the typed global model anymore:
names(d2_sub) 
# [1] "cond((Int))"   "disp((Int))"   "cond(X1)"      "cond(I(X1^2))" "cond(X2)"      "cond(I(X2^2))" "df"            "logLik"        "AICc"         
# [10] "delta"         "weight"   
# e.g., now the X1 in the typed global model is actually called cond(X1)

# what will work for glmmTMB:
d2_sub <- dredge(m2, subset = dc(`cond(X1)`, `cond(I(X1^2))`) & dc(`cond(X2)`, `cond(I(X2^2))`))
# 9 models produced

Upvotes: 3

Related Questions