Quantcast
Channel: Active questions tagged lm - Stack Overflow
Viewing all articles
Browse latest Browse all 124

How to calculate variance explained by a variable of interest, in a lm model with covariates?

$
0
0

I am working in R on linear regressions with covariates, looking like : lm(x ~ y + a + b + c)

With the summary() function, I can get the p value corresponding to each of the variables of the model. However, I only have the R^2 corresponding to the whole model, which isn't informative of the contribution of my variable of interest (y).

How do I get the R^2 corresponding to the part of the variance explained by y alone ?

I tried :

sapply(model,function(x) summary(x)$r.squared)

as advised here : Print R-squared for all of the models fit with lmListbut it returns `

Error in summary(x)$r.squared : $ operator is invalid for atomic vectors"`

I was also advised to calculate the difference between the R^2 of my model and the R^2 of a linear model without my variable of interest. Is that a valid method ?Anyway I would still like to know if there is an easier way to do it, for example included in some package.


Viewing all articles
Browse latest Browse all 124

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>