23

I have to do statistical analyses on a data set. I would like to create all the possible models and to test them with the dredge function but it doesn't work. Indeed, when I type:

glm1<-glm(presabs~dca1+dca2+se1+se2, family=binomial(logit))
dredge(glm1)

I got this error:

Erreur in dredge(glm1) : 
'global.model''s 'na.action' argument is not set and options('na.action') is "na.omit"

Can someone help me?

Mornor
  • 3,471
  • 8
  • 31
  • 69

2 Answers2

40

The issue with using options(na.action = "na.fail") is that it changes the global settings of R. If you have a large script, changing the global settings will potentially impact on other sections of your code where you implicitly rely on R's default settings. There are two ways to avoid this:

  1. After using dredge change the settings back via options(na.action = "na.omit").

OR the better way...

  1. Utilise the regression function's ability to set the na.action argument. In your case:
glm1 <- glm(presabs ~ dca1+dca2+se1+se2,
            family=binomial(logit),
            na.action = "na.fail")
Luke Singham
  • 1,536
  • 2
  • 20
  • 38
11

See ?dredge:

# Example from Burnham and Anderson (2002), page 100:
data(Cement)
options(na.action = "na.fail")   #  prevent fitting models to different datasets

fm1 <- lm(y ~ ., data = Cement)
dd <- dredge(fm1)

If you skip the second line, your described error pops up, as the models are fitted to different datasets (due to removal of NAs).

Community
  • 1
  • 1
EDi
  • 13,160
  • 2
  • 48
  • 57
  • You might want to amend this to incorporate the answer below which is a better way of doing this. – bjw Oct 20 '16 at 18:38