Say I have some predictors, and I know how they affect some dependent variable:
#predictors
x1<- seq(0,10,0.1)
x2<-runif(101,0,1)
#specify how predictors affect dependent variable y
y<- 15*x1 + 10*x1*x2
#introduce random error
y.err<- rnorm(101,0.01)
y<- y + y.err
I can then model y
as a function of x1
and x2
like this:
fit<- lm(y ~ x1 + x1*x2)
which yields this output:
summary(fit)
Call:
lm(formula = y ~ x1 + x1 * x2)
Residuals:
Min 1Q Median 3Q Max
-2.76646 -0.59886 -0.09115 0.70549 2.85311
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.38875 0.41630 0.934 0.353
x1 14.93601 0.07409 201.585 <2e-16 ***
x2 -0.74815 0.79518 -0.941 0.349
x1:x2 10.10469 0.13698 73.768 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.025 on 97 degrees of freedom
Multiple R-squared: 0.9997, Adjusted R-squared: 0.9997
F-statistic: 1.184e+05 on 3 and 97 DF, p-value: < 2.2e-16
So, total model $R^2$ is 0.997.
I would like to know what percentage of that $R^2$ value can be attributed to x1, x2, and the interaction of x1 and x2. I am also aware of a previous post on this topic linked here, where the user has an identical question. However, the solution proposed (as I read it) was to run the correlations individually, square them, and they will sum to the full model $R^2$. This is not the case here.