从线性回归手动更改beta系数估算R2 [英] Estimating R2 from a linear regression manually changing beta coefficient
本文介绍了从线性回归手动更改beta系数估算R2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种方法可以建立线性回归模型并手动更改beta系数并在此更改后估算R2.
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.
简单的例子:
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
如果我对变量"b"和"c"使用不同的beta,我想知道该模型的R2.
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.
这篇关于从线性回归手动更改beta系数估算R2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文