Krishna
Krishna

Reputation: 25

Using dredge from MuMIn error: object not found

Code and output

 > dredge(regional ~ national, foreign, tbili2_recip, data = s2)
 Error in eval(.expr_beta_arg) : object 'foreign' not found

Sample data

 s2 <- structure(list(regional = c(0, 0, 0, 0, 0, 1), national = c(0, 
 0, 0, 0, 0, 0), foreign = c(0, 0, 0, 0, 0, 0), tbili2_recip = c(1, 
 1, 0, 1, 0, 0), tbili16_recip = c(0, 0, 0, 0, 0, 0), tbili32_recip = c(0, 
 0, 0, 0, 0, 1), tbili33_recip = c(0, 0, 0, 0, 0, 0), tbil_don1 = c(0, 
 0, 0, 0, 0, 0), tbil_don18 = c(1, 0, 0, 0, 1, 0), tip = c(0, 
 0, 0, 0, 0, 0), wit70 = c(0, 0, 0, 0, 0, 0), wit80 = c(0, 0, 
 0, 0, 0, 0), wit90 = c(0, 0, 0, 0, 0, 0), wit91 = c(0, 0, 0, 
 0, 0, 0), weight_diff = c(-3, -9, -33, 18, -8, -26), weight45 = c(0, 
 0, 0, 0, 0, 0), weight70 = c(0, 0, 0, 0, 0, 0), weight_neg45 = c(0, 
 0, 0, 0, 0, 0), weight_neg70 = c(0, 0, 0, 0, 0, 0), work = c(0, 
 0, 0, 0, 0, 0)), row.names = c(NA, 6L), class = "data.frame")

I am actually trying to do this for a few different variables than shown here, but all are having the same issue. Anything obvious I am overlooking? Variables are all numeric and it works in a typical lm().

I checked the other posts on stackoverflow on this topic with no luck.

Upvotes: 1

Views: 184

Answers (1)

LocoGris
LocoGris

Reputation: 4480

Try this:

model <- lm(regional ~ national + foreign + tbili2_recip, data=s2)
options(na.action = "na.fail")
dredge(model)

You need first to fit a model (I used lm because it is the basic one) and then you can use it as an argument to dredge. Also, as you can see here dredge function error - R package MuMln, you need the options(na.action = "na.fail") in order to make it work. Finally, formulas use + and not , so we need regional ~ national + foreign + tbili2_recip

Upvotes: 1

Related Questions