Error when requesting adjusted r-squared using dredge()

When I run the following command

dredge(FULL.MODEL, evaluate = TRUE, rank ="AICc", extra = "adjR^2", m.lim = c(0, No.MODEL.PRED), trace = 2)

I get the error "Error: object of type 'symbol' is not subsettable".

If I remove the "adjR^2" and replace it with "rsq", everything works fine. The problem is that I need the Adjusted R2, not the regular R2. The documentation of the dredge function says I need to use "adjR^2" to request the Adjusted R2, but it is not working. Any ideas on how to solve this?

JJ

Hi @jj31,
Welcome to the RStudio Community Forum.
The following Reproducible Example shows that the function works as you require. Perhaps your value for No.MODEL.PRED is not set correctly as a numeric?

library(MuMIn)

No.MODEL.PRED <- 4

# Code from help(dredge)
options(na.action = "na.fail")

FULL.MODEL <- lm(y ~ ., data = Cement)
dredge(FULL.MODEL, 
       evaluate = TRUE, 
       rank ="AICc", 
       extra = "adjR^2", 
       m.lim = c(0, No.MODEL.PRED), 
       trace = 2)
#> Fixed term is "(Intercept)"
#>   |                                                                              |                                                                      |   0%  |                                                                              |====                                                                  |   6%  |                                                                              |=========                                                             |  12%  |                                                                              |=============                                                         |  19%  |                                                                              |==================                                                    |  25%  |                                                                              |======================                                                |  31%  |                                                                              |==========================                                            |  38%  |                                                                              |===============================                                       |  44%  |                                                                              |===================================                                   |  50%  |                                                                              |=======================================                               |  56%  |                                                                              |============================================                          |  62%  |                                                                              |================================================                      |  69%  |                                                                              |====================================================                  |  75%  |                                                                              |=========================================================             |  81%  |                                                                              |=============================================================         |  88%  |                                                                              |==================================================================    |  94%
#> Global model call: lm(formula = y ~ ., data = Cement)
#> ---
#> Model selection table 
#>    (Intrc)    X1      X2      X3      X4 adjR^2 df  logLik  AICc delta weight
#> 4    52.58 1.468  0.6623                 0.9790  4 -28.156  69.3  0.00  0.566
#> 12   71.65 1.452  0.4161         -0.2365 0.9826  5 -26.933  72.4  3.13  0.119
#> 8    48.19 1.696  0.6569  0.2500         0.9826  5 -26.952  72.5  3.16  0.116
#> 10  103.10 1.440                 -0.6140 0.9727  4 -29.817  72.6  3.32  0.107
#> 14  111.70 1.052         -0.4100 -0.6428 0.9816  5 -27.310  73.2  3.88  0.081
#> 15  203.60       -0.9234 -1.4480 -1.5570 0.9731  5 -29.734  78.0  8.73  0.007
#> 16   62.41 1.551  0.5102  0.1019 -0.1441 0.9827  6 -26.918  79.8 10.52  0.003
#> 13  131.30               -1.2000 -0.7246 0.9356  4 -35.372  83.7 14.43  0.000
#> 7    72.07        0.7313 -1.0080         0.8473  4 -40.965  94.9 25.62  0.000
#> 9   117.60                       -0.7382 0.6747  3 -45.872 100.4 31.10  0.000
#> 3    57.42        0.7891                 0.6665  3 -46.035 100.7 31.42  0.000
#> 11   94.16        0.3109         -0.4569 0.6803  4 -45.761 104.5 35.21  0.000
#> 2    81.48 1.869                         0.5341  3 -48.206 105.1 35.77  0.000
#> 6    72.35 2.312          0.4945         0.5483  4 -48.005 109.0 39.70  0.000
#> 5   110.20               -1.2560         0.2860  3 -50.980 110.6 41.31  0.000
#> 1    95.42                               0.0000  2 -53.168 111.5 42.22  0.000
#> Models ranked by AICc(x)

Created on 2021-06-18 by the reprex package (v2.0.0)

Hi @DavoWW ,

Thanks for your reply. I solved the problem by defining the model directly into the lm() function. I was getting the error when I was defining the model in the following way:

library(MuMIn)
model.formula <- y ~ (X1 + X2 + X3 + X4)
model.data <- Cement
FULL.MODEL <- lm(model.formula, data=model.data)

No.MODEL.PRED <- 4

# Code from help(dredge)
options(na.action = "na.fail")
dredge(FULL.MODEL, 
       evaluate = TRUE, 
       rank ="AICc", 
       extra = "adjR^2", 
       m.lim = c(0, No.MODEL.PRED), 
       trace = 2)

#>Fixed term is "(Intercept)"
#>Error: object of type 'symbol' is not subsettable

However, the problem is gone when I define the model as follows:

library(MuMIn)
FULL.MODEL <- lm( y ~ (X1 + X2 + X3 + X4), data=Cement)

No.MODEL.PRED <- 4

# Code from help(dredge)
options(na.action = "na.fail")
dredge(FULL.MODEL, 
       evaluate = TRUE, 
       rank ="AICc", 
       extra = "adjR^2", 
       m.lim = c(0, No.MODEL.PRED), 
       trace = 2)

#>Fixed term is "(Intercept)"
  #>|=========================================================================================#>=============================        |  94%
#>Global model call: lm(formula = y ~ (X1 + X2 + X3 + X4), data = Cement)
#>---
#>Model selection table 
   #>(Intrc)    X1      X2      X3      X4 adjR^2 df  logLik  AICc delta weight
#>4    52.58 1.468  0.6623                 0.9790  4 -28.156  69.3  0.00  0.566
#>12   71.65 1.452  0.4161         -0.2365 0.9826  5 -26.933  72.4  3.13  0.119
#>8    48.19 1.696  0.6569  0.2500         0.9826  5 -26.952  72.5  3.16  0.116
#>10  103.10 1.440                 -0.6140 0.9727  4 -29.817  72.6  3.32  0.107
#>14  111.70 1.052         -0.4100 -0.6428 0.9816  5 -27.310  73.2  3.88  0.081
#>15  203.60       -0.9234 -1.4480 -1.5570 0.9731  5 -29.734  78.0  8.73  0.007
#>16   62.41 1.551  0.5102  0.1019 -0.1441 0.9827  6 -26.918  79.8 10.52  0.003
#>13  131.30               -1.2000 -0.7246 0.9356  4 -35.372  83.7 14.43  0.000
#>7    72.07        0.7313 -1.0080         0.8473  4 -40.965  94.9 25.62  0.000
#>9   117.60                       -0.7382 0.6747  3 -45.872 100.4 31.10  0.000
#>3    57.42        0.7891                 0.6665  3 -46.035 100.7 31.42  0.000
#>11   94.16        0.3109         -0.4569 0.6803  4 -45.761 104.5 35.21  0.000
#>2    81.48 1.869                         0.5341  3 -48.206 105.1 35.77  0.000
#>6    72.35 2.312          0.4945         0.5483  4 -48.005 109.0 39.70  0.000
#>5   110.20               -1.2560         0.2860  3 -50.980 110.6 41.31  0.000
#>1    95.42                               0.0000  2 -53.168 111.5 42.22  0.000
#>Models ranked by AICc(x) 

I think it's a weird problem because either way works when I use extra = "rsq".

library(MuMIn)
model.formula <- y ~ (X1 + X2 + X3 + X4)
model.data <- Cement
FULL.MODEL <- lm(model.formula, data=model.data)

No.MODEL.PRED <- 4

# Code from help(dredge)
options(na.action = "na.fail")
dredge(FULL.MODEL, 
       evaluate = TRUE, 
       rank ="AICc", 
       extra = "rsq", 
       m.lim = c(0, No.MODEL.PRED), 
       trace = 2)

I guess the dredge() function doesn't like my first method to define the model when I'm using "adjr R^2"

Thanks for your help!

JJ

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.