Chapter 7 Multinomial Regression
7.1 Fitting the Model
library(nnet)
m1 <-multinom( y ~ x, data = )
- Replace y with your categorical response variable.
- Replace x with your explanatory variable.
- data = your data set
7.2 Other Useful Codes
summary(m1)
: To get the estimates and standard errors.
coefficients(m1)
: To get the estimates.
AIC(m1)
: To get the AIC.
7.3 Making Predictions
probabilities <- predict(Model, type = "response")
predicted.Y <- levels(data$Y)[which.max(probabilities)]
- The first line creates predicted probability that \(Y_i\) equals each of the K choices of Y for each row \(i\).
- The second row assign all rows with the outcome level associated with the higest probability.
- Replace “model” with the name of your model.
- Replace data with the name of your data set.
- Replace Y with your response variable.