[R] Obtaining R-squared from All Possible Combinations of Linear Models Fitted

John C Frain |r@|nj @end|ng |rom gm@||@com
Mon Jul 17 21:25:59 CEST 2023


MuMln is a package designed to select optimum models mainly based on
information criteria.  R-squared is not a suitable criterion for this
purpose.   As far as I can see is not covered in this package.  (I presume
you already know that R-squared for the model with all possible regressors
is at least as great as R with any subset of the regressors).

If you want to calculate all these R-squared's it should be easy to write a
small routine to estimate them.  I am very curious as to why you wish to do
this.


John C Frain.
3 Aranleigh Park
Rathfarnham
Dublin 14
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
https://jcfrain.wordpress.com/
https://jcfraincv19.wordpress.com/

mailto:frainj using tcd.ie
mailto:frainj using gmail.com


On Mon, 17 Jul 2023 at 18:25, Paul Bernal <paulbernal07 using gmail.com> wrote:

> Dear friends,
>
> I need to automatically fit all possible linear regression models (with all
> possible combinations of regressors), and found the MuMIn package, which
> has the dredge function.
>
> This is the dataset  I am working with:
> > dput(final_frame)
> structure(list(y = c(41.9, 44.5, 43.9, 30.9, 27.9, 38.9, 30.9,
> 28.9, 25.9, 31, 29.5, 35.9, 37.5, 37.9), x1 = c(6.6969, 8.7951,
> 9.0384, 5.9592, 4.5429, 8.3607, 5.898, 5.6039, 4.9176, 6.2712,
> 5.0208, 5.8282, 5.9894, 7.5422), x4 = c(1.488, 1.82, 1.5, 1.121,
> 1.175, 1.777, 1.24, 1.501, 0.998, 0.975, 1.5, 1.225, 1.256, 1.69
> ), x8 = c(22, 50, 23, 32, 40, 48, 51, 32, 42, 30, 62, 32, 40,
> 22), x2 = c(1.5, 1.5, 1, 1, 1, 1.5, 1, 1, 1, 1, 1, 1, 1, 1.5),
>     x7 = c(3, 4, 3, 3, 3, 4, 3, 3, 4, 2, 4, 3, 3, 3)), class =
> "data.frame", row.names = c(NA,
> -14L))
>
> I started with the all regressor model, which I called globalmodel as
> follows:
> #Fitting Regression model with all possible combinations of regressors
> options(na.action = "na.fail") # change the default "na.omit" to prevent
> models
> globalmodel <- lm(y~., data=final_frame)
>
> Then, the following code provides the different coefficients (for
> regressors and the intercept) for each of the possible model combinations:
> combinations <- dredge(globalmodel)
> print(combinations)
>  I would like to retrieve  the R-squared generated by each combination, but
> have not been able to get it thus far.
>
> Any guidance on how to retrieve the R-squared from all linear model
> combinations would be greatly appreciated.
>
> Kind regards,
> Paul
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list