Skip to content
Prev 322797 / 398503 Next

Factors and Multinomial Logistic Regression

Apologies, ares is not needed at all. Please find the correct script at  
the end of the email.
No, I did not. The point is that if I use a variable female, which has two  
levels, then I do not reproduce the results of stata for that variable  
only.
If instead I define a variable "sex" which assumes the numerical values  
0/1, then I reproduce entirely the results by stata.

Hope this helps.

Lorenzo


##################################################################


library(foreign)

## See the Stata example at http://bit.ly/11VG4ha

mydata <- read.dta("http://www.ats.ucla.edu/stat/data/hsb2.dta")


sex <- rep(0, dim(mydata)[1])

sel <- which(mydata$female=="male")

sex[sel] <- 1

mydata$sex <- sex

## IMPORTANT: redefine the base line!!!

mydata$ses2 <- relevel(mydata$ses, ref = "middle")


## NB: for some reason, if I use female (a factor assuming two values)
## I do not reproduce the results of the example.
## I need to use a variable which is numeric and assumes two values
## (that is why I introduced the variable sex))

## mymodel <- multinom(ses2 ~ science+ socst+ sex, data=mydata)


mymodel <- multinom(ses2 ~ science+ socst+ female, data=mydata)




print(summary(mymodel))

print("The relative risk ratio (RRR) is, ")

print(exp(coef(mymodel)))