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 lmList but 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.
It doesn't make much sense to talk about the R-squared of individual variables in a multivariate model. Delta R-squared, as Zephryl mentions, or partial R-squared are two measures that will do something like what you want.
Discussion on delta R-squared and partial R-squared: https://stats.stackexchange.com/questions/64010/importance-of-predictors-in-multiple-regression-partial-r2-vs-standardized
Partial R-squared can be calculate like this: