我希望估计一个回归模型,其中因变量是虚拟的(编码为0/1),我有五个或六个序数自变量(我将虚拟出来),还有一堆其他东西。任何人都可以推荐一个能够以最小的麻烦进行dummying-out或以其他方式处理序数RHS变量的软件包吗?感谢
答案 0 :(得分:2)
您可以使用内置的glm
函数完成所有操作,并在公式中的变量周围使用factor
,并将其作为虚拟变量。
示例:
R> y <- rbinom(100, 1, .5)
R> x1 <- sample(1:5, 100, replace = TRUE)
R> x2 <- sample(1:5, 100, replace = TRUE)
R> m1 <- glm(y ~ factor(x1) + factor(x2), family = binomial(link = "probit"))
R> m1
Call: glm(formula = y ~ factor(x1) + factor(x2), family = binomial(link = "probit"))
Coefficients:
(Intercept) factor(x1)2 factor(x1)3 factor(x1)4 factor(x1)5 factor(x2)2
0.335 -0.729 -0.670 -0.639 -0.740 0.327
factor(x2)3 factor(x2)4 factor(x2)5
-0.106 0.624 0.483
Degrees of Freedom: 99 Total (i.e. Null); 91 Residual
Null Deviance: 138
Residual Deviance: 129 AIC: 147
您可能还想查看dummies
包。