How to set specific contrasts in multinom () in nnet package?

I have a problem with 3 classes requiring classification. I want to use multinomial logistic regression in a package nnet. The class result has 3 factors: P, Q, R. I want to consider Q as a basic factor.

So, I tried to write such contrasts:

P <- c(1,0,0)
R <- c(0,0,1)
contrasts(trainingLR$Class) <- cbind(P,R)

checked:

> contrasts(trainingLR$Class)
  P R
P 1 0
Q 0 0
R 0 1 

Now multinom():

library(nnet)
multinom(Class ~., data=trainingLR)

Output:

> multinom(Class ~., data=trainingLR)
# weights:  39 (24 variable)
initial  value 180.172415 
iter  10 value 34.990665
iter  20 value 11.765136
iter  30 value 0.162491
iter  40 value 0.000192
iter  40 value 0.000096
iter  40 value 0.000096
final  value 0.000096 
converged
Call:
multinom(formula = Class ~ ., data = trainingLR)

Coefficients:
  (Intercept)        IL8     IL17A      IL23A     IL23R
Q   -116.2881 -16.562423 -34.80174   3.370051  6.422109
R    203.2414   6.918666 -34.40271 -10.233787 31.446915
       EBI3     IL6ST     IL12A   IL12RB2     IL12B
Q -8.316808  12.75168 -7.880954  5.686425 -9.665776
R  5.135609 -20.48971 -2.093231 37.423452 14.669226
    IL12RB1    IL27RA
Q -6.921755 -1.307048
R 15.552842 -7.063026

Residual Deviance: 0.0001922658 
AIC: 48.00019 

Question:
So, as you can see, since the class P did not appear in the output, this means that it was considered basic, being the first in alphabetical order, as expected when working with factor variables in R, and class Q was not considered as a basic level in In this case, how to make it the basis for two other levels?

+3
source share
1

, relevel .

trainingLR$Class <- relevel(trainingLR$Class, ref = "P")

"P" . "Q" "R".

R (?relevel) " contr.treatment, ".

, , , , .

+1

All Articles