[R] Factors and Multinomial Logistic Regression

Lorenzo Isella lorenzo.isella at gmail.com
Thu May 2 20:33:49 CEST 2013


On Wed, 01 May 2013 23:49:07 +0200, peter dalgaard <pdalgd at gmail.com>  
wrote:

> It still doesn't work!!!!!
>


Apologies; since I had already imported nnet in my workspace, the script  
worked on my machine even without importing it explicitly (see the script  
at the end of the email).
Sorry for the confusion.

I now mainly have a question about a definition: I can easily calculate  
the relative risk ratio (RRR) and its confidence interval (CI) for a given  
variable of my multinomial regression by exponentiating the variable and  
its original CI.
However, how is the standard error on the RRR defined? This is now the  
only part of the stata calculation which I cannot reproduce.
Cheers

Lorenzo

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



library(foreign)
library(nnet)
## 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)))



More information about the R-help mailing list