I wish to estimate a regression model where the dependent variable is a dummy (coded 0/1) and I have five or six ordinal independent variables (that I will dummy out), plus a bunch of other stuff. Can anyone recommend a package that will do the dummying-out with a minimum of fuss or otherwise handle the ordinal RHS variables? thanks
+2
A:
You can do it all with the built-in glm
function, plus appropriate use of factor
around the variables in your formula that should be made into dummy variables.
Example:
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
You may also want to take a look at the dummies
package.
brentonk
2010-07-20 00:41:46