Skip to content
Prev 322802 / 398503 Next

Factors and Multinomial Logistic Regression

Look at the output of str(mydata)
   'data.frame':   200 obs. of  11 variables:
    $ id     : num  70 121 86 141 172 113 50 11 84 48 ...
    $ female : Factor w/ 2 levels "male","female": 1 2 1 1 1 1 1 1 1 1 ...
    $ race   : Factor w/ 4 levels "hispanic","asian",..: 4 4 4 4 4 4 3 1 4 3 ...
    $ ses    : Factor w/ 3 levels "low","middle",..: 1 2 3 3 2 2 2 2 2 2 ...

mydata$female is a factor with levels "male" and "female", in that order.

You constructed mydata$sex so that it has values 0 for female and 1 for male,
opposite the order for mydata$female.
   > with(mydata, table(female, sex))
           sex
   female     0   1
     male     0  91
     female 109   0

Thus your coefficients ought to be different but fitted values ought to be the same.
You can make the coefficients the same by reversing the order of the levels of
female or by using contr.SAS for the contrast function for that variable.

(I would have expected the variable "female" to be a logical, or maybe a numeric 0/1,
and the equivalent "sex" to be the factor.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com