Reputation: 503
I want to know if there is a way to make a linear regression model and change the beta coefficient manually and estimate R2 after this change.
Simple example:
a <- c(2000 , 2001 , 2002 , 2003 , 2004)
b <- c(9.34 , 8.50 , 7.62 , 6.93 , 6.60)
c <- c(10.5 , 12.8 , 13.1 , 14.4 , 15.9)
fit=lm(a~b+c)
fit$coefficients
(Intercept) b c
2005.1537642 -0.8948095 0.2866537
summary(fit)$r.squared
[1] 0.9862912
I want to know what would be the R2 of this model if I used different betas for my variables "b" and "c".
Upvotes: 0
Views: 785
Reputation: 1101
You can calculate the coefficient of determination by taking the square of the sample correlation coefficient between the outcomes and their predicted values:
cor(a, -0.8948095 * b + 0.2866537 * c) ** 2
## [1] 0.9862912
Just replace the coefficients from your linear model with the coefficients that you want to test.
Upvotes: 2