[R] Factors and Multinomial Logistic Regression

peter dalgaard pdalgd at gmail.com
Wed May 1 22:01:48 CEST 2013


On May 1, 2013, at 15:48 , Lorenzo Isella wrote:

> Dear All,
> I am trying to reproduce the example that I found online here
> 
> 
> http://bit.ly/11VG4ha
> 
> 
> However, when I run my script (pasted at the end of the email), I notice that there is a factor 2 between the values for the coefficients for the categorical variable female calculated by my script and in the online example.
> Any idea about where this difference comes from?
> Besides, how can I extract the p-values for the calculated coefficients of my model and for the relative risk ratios?
> Best Regards
> 

(A) The example doesn't run for me. library(ares) is not available on current R versions, but even where it is available, it doesn't provide a multinom() function?

(B) If I insert library(nnet), to get a multinom(), I get exactly the same result as Stata does! 

Did you by any chance diddle with options(contrasts=...)?

-pd



> Lorenzo
> 
> ###########################################################################
> library(ares)
> library(foreign)
> 
> ## See the Stata example at http://bit.ly/11VG4ha
> 
> mydata <- read.dta("http://www.ats.ucla.edu/stat/data/hsb2.dta")
> 
> 
> ## IMPORTANT: redefine the base line!!!
> 
> mydata$ses2 <- relevel(mydata$ses, ref = "middle")
> 
> 
> 
> mymodel <- multinom(ses2 ~ science+ socst+ female, data=mydata)
> 
> print(summary(mymodel))
> 
> print("The relative risk ratio (RRR) is, ")
> 
> print(exp(coef(mymodel)))
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list