R multinom()

1 개요[ | ]

R multinom()
  • "Fit Multinomial Log-Linear Models"
R
CPU
0.4s
MEM
72M
0.5s
Copy
options(echo = TRUE)
oc <- options(contrasts = c("contr.treatment", "contr.poly"))
library(MASS)
example(birthwt)
library(nnet)
(bwt.mu <- multinom(low ~ ., bwt))
options(oc)
> oc <- options(contrasts = c("contr.treatment", "contr.poly"))
> library(MASS)
> example(birthwt)

brthwt> bwt <- with(birthwt, {
brthwt+ race <- factor(race, labels = c("white", "black", "other"))
brthwt+ ptd <- factor(ptl > 0)
brthwt+ ftv <- factor(ftv)
brthwt+ levels(ftv)[-(1:2)] <- "2+"
brthwt+ data.frame(low = factor(low), age, lwt, race, smoke = (smoke > 0),
brthwt+            ptd, ht = (ht > 0), ui = (ui > 0), ftv)
brthwt+ })

brthwt> options(contrasts = c("contr.treatment", "contr.poly"))

brthwt> glm(low ~ ., binomial, bwt)

Call:  glm(formula = low ~ ., family = binomial, data = bwt)

Coefficients:
(Intercept)          age          lwt    raceblack    raceother    smokeTRUE  
    0.82302     -0.03723     -0.01565      1.19241      0.74068      0.75553  
    ptdTRUE       htTRUE       uiTRUE         ftv1        ftv2+  
    1.34376      1.91317      0.68020     -0.43638      0.17901  

Degrees of Freedom: 188 Total (i.e. Null);  178 Residual
Null Deviance:	    234.7 
Residual Deviance: 195.5 	AIC: 217.5
> library(nnet)
> (bwt.mu <- multinom(low ~ ., bwt))
# weights:  12 (11 variable)
initial  value 131.004817 
iter  10 value 98.029803
final  value 97.737759 
converged
Call:
multinom(formula = low ~ ., data = bwt)

Coefficients:
(Intercept)         age         lwt   raceblack   raceother   smokeTRUE 
 0.82320102 -0.03723828 -0.01565359  1.19240391  0.74065606  0.75550487 
    ptdTRUE      htTRUE      uiTRUE        ftv1       ftv2+ 
 1.34375901  1.91320116  0.68020207 -0.43638470  0.17900392 

Residual Deviance: 195.4755 
AIC: 217.4755 
> options(oc)
> cat('

2 같이 보기[ | ]

3 참고[ | ]