# HINT: # The program assumes that all files are stored in # C:\monographregression\computercode # change directory if code is located elsewhere library("foreign") library("mlogit") # read data setwd("c:/monographregression/computercode") csection <- read.dta("data/stata/caesarian.dta") # define response as factor csection$Y <- factor(csection$Y, levels=1:3, labels=c("Type I", "Type II", "no infection")) # determine a data set without grouping csectionlong <- csection[rep(1:nrow(csection), csection$n),] rownames(csectionlong) <- 1:nrow(csectionlong) # set up data set in mlogit format caesar.mlogit <- mlogit.data(data=csectionlong, choice="Y", shape="wide") head(caesar.mlogit, n=20) # estimate the logit model mlogit.csection <- mlogit(Y ~ 1 | ANTIB + RISK + NPLAN, data=caesar.mlogit) summary(mlogit.csection) # predict probabilities predict.data <- mlogit.data(csection, choice="Y", shape="wide") round(cbind(predict.data[seq(1, 72, by=3),c(4,5,3)], predict(mlogit.csection, newdata=predict.data))[seq(1, 24, by=3),], 3)