含qualitative independent variable的multivariate linear regression实现疑问
定性自变量多元线性回归的代码验证问题
我正尝试计算一个自变量为定性变量的多元线性回归,但不确定操作是否正确。目前编写的回归代码如下:
model_1.a <- lm(formula = V34 ~ no.work + common.poor.housing + no.degree, data = df)
其中no.work、common.poor.housing和no.degree是通过within()函数生成的0-1虚拟变量,变量创建代码如下:
df <- within(cr.svy, { degree <- as.numeric(V6==4) no.degree <- as.numeric(V6 == 1| V7 == 2 | V7 == 3) work <- as.numeric(V7==1) no.work <- as.numeric(V7 == 2) common.poor.housing <- as.numeric(V14 == 1 | V14 == 2) uncommon.poor.housing <- as.numeric(V14==3 | V14 == 4) degree[is.na(V6)] <- NA no.degree[is.na(V6)] <- NA work[is.na(V7)] <- NA no.work[is.na(V7)] <- NA common.poor.housing[is.na(V14)] <- NA uncommon.poor.housing[is.na(V14)] <- NA })
我希望验证因变量V34与这些自定义变量之间的关系,但不确定当前结果是否符合预期。
内容的提问来源于stack exchange,提问作者monkegobrrrrrr
相关产品推荐
相关产品推荐

