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".
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.