[R] multinom function

ronggui 0034058 at fudan.edu.cn
Thu Mar 31 15:02:34 CEST 2005


i think it is right!
i rearrage your data in the following form and carry multinom angain,it get the same result as yours.

> multinom(k~year+age,data=worms)
....
Call:
multinom(formula = k ~ year + age, data = worms)

Coefficients:
      (Intercept)       year         age
sand    -106.3405 0.05368317 -0.20612839
rocks   -438.4518 0.21899290  0.09911392

Residual Deviance: 1054.121
AIC: 1066.121

> multinom(factor(x4)~X1+X2,weight=X3,data=newdata)
Call:
multinom(formula = factor(x4) ~ X1 + X2, data = newdata, weights = X3)

Coefficients:
  (Intercept)         X1          X2
2   -106.3407 0.05368328 -0.20612838
3   -438.4522 0.21899311  0.09911394

Residual Deviance: 1054.121
AIC: 1066.121


> newdata
      X1 X2 X3 x4
1   2000  1  2  1
2   2000  2  5  1
3   2000  3  0  1
4   2001  1  8  1
5   2001  2  7  1
6   2001  3  7  1
7   2002  1  5  1
8   2002  2  9  1
9   2002  3 14  1
10  2003  1 12  1
11  2003  2  8  1
12  2003  3  7  1
13  2004  1  5  1
14  2004  2 13  1
15  2004  3 11  1
16  2000  1  4  2
21  2000  2  7  2
31  2000  3 13  2
41  2001  1  4  2
51  2001  2 14  2
61  2001  3 13  2
71  2002  1 20  2
81  2002  2 17  2
91  2002  3 15  2
101 2003  1 23  2
111 2003  2 20  2
121 2003  3  9  2
131 2004  1 35  2
141 2004  2 27  2
151 2004  3 18  2
17  2000  1  2  3
22  2000  2  6  3
32  2000  3  7  3
42  2001  1  9  3
52  2001  2  3  3
62  2001  3  2  3
72  2002  1  2  3
82  2002  2 10  3
92  2002  3  5  3
102 2003  1 19  3
112 2003  2 13  3
122 2003  3 17  3
132 2004  1 11  3
142 2004  2 20  3
152 2004  3 29  3



On Thu, 31 Mar 2005 12:44:51 +0100
alexbri <alexbri at netcabo.pt> wrote:

> Dear all:
> 
>  
> 
> I am trying to fit a multinomial log linear model to the following data:
> 
>  
> 
> worms<- data.frame(year= rep(2000:2004, c(3,3,3,3,3)),age=rep(1:3,5), mud=c(2,5,0,8,7,7,5,9,14,12,8,7,5,13,11),sand=c(4,7,13,4,14,13,20,17,15,23,20,9,35,27,18), rocks=c(2,6,7,9,3,2,2,10,5,19,13,17,11,20,29))
> 
>  
> 
> mud, sand and rocks are the 3 factors while age and year are predictors.
> 
> Can I fit a model with the multinom function (nnet library) to the data in this form?
> 
>  
> 
> k<- as.matrix(worms[,3:5])
> 
> m1<- multinom(k~year+age,data=worms)
> 
>  
> 
> Is this correct, or is there another way?
> 
>  
> 
> Thanks for your help, best wishes
> 
>  
> 
> Alex
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list