具有两个分类变量的lm
模型的输出是:
Call:
lm(formula = exit_irr ~ type_exit + domicile, data = pe1)
Residuals:
Min 1Q Median 3Q Max
-0.73013 -0.17926 -0.05142 0.03945 2.85043
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.05333 0.22282 0.239 0.81101
type_exitTrade Sale -0.11871 0.05469 -2.171 0.03081
type_exitUnlisted -0.21208 0.07536 -2.814 0.00525
domicileKSA 0.14593 0.22852 0.639 0.52363
domicileKuwait 0.14679 0.22847 0.643 0.52108
domicileOM 0.08708 0.28225 0.309 0.75791
domicileUAE 0.18623 0.22808 0.817 0.41491
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.3859 on 274 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.04221, Adjusted R-squared: 0.02124
F-statistic: 2.013 on 6 and 274 DF, p-value: 0.06415
如何用分类预测器编写线性回归方程?
答案 0 :(得分:1)
r中的函数lm()
自动考虑分类变量。它会生成分类变量的虚拟变量,并对其进行回归。确保您的分类变量属于类因子。这可以这样做:
pe1$type_exit <- as.factor(pe1$type_exit)
pe1$domicile <- as.factor(pe1$domicile)
我已将type_exit
和domicile
视为您的分类列。