[R] Problem with multinom ?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Jun 11 16:31:04 CEST 2005
On Sat, 11 Jun 2005, John Fox wrote:
> Dear Marc,
>
> I get the same results -- same coefficients, standard errors, and fitted
> probabilities -- from multinom() and glm(). It's true that the deviances
> differ, but they, I believe, are defined only up to an additive constant:
Yes. There are many variations on the definition of (residual) deviance,
but it compares -2 log likelihood with a `saturated' model. For grouped
data you have a choice: a separate term for each group or for each
observation. A binomial GLM uses the first but the second is more
normal in logistic regression (since it has a direct interpretation via
log-probability scoring).
multinom() is support software for a book (which the R posting guide does
ask you to consult): this is discussed with a worked example on pp 203-4.
>> dt
> output factor n
> 1 m 1.2 10
> 2 f 1.2 12
> 3 m 1.3 14
> 4 f 1.3 14
> 5 m 1.4 15
> 6 f 1.4 12
>
>> dt.m <- multinom(output ~ factor, data=dt, weights=n)
> # weights: 3 (2 variable)
> initial value 53.372333
> iter 10 value 53.115208
> iter 10 value 53.115208
> iter 10 value 53.115208
> final value 53.115208
> converged
>
>> dt2
> m f factor
> 1 10 12 1.2
> 2 14 14 1.3
> 3 15 12 1.4
>
>> dt.b <- glm(cbind(m,f) ~ factor, data=dt2, family=binomial)
>
>> summary(dt.m)
> Call:
> multinom(formula = output ~ factor, data = dt, weights = n)
>
> Coefficients:
> Values Std. Err.
> (Intercept) -2.632443 3.771265
> factor 2.034873 2.881479
>
> Residual Deviance: 106.2304
> AIC: 110.2304
>
> Correlation of Coefficients:
> [1] -0.9981598
>
>> summary(dt.b)
>
> Call:
> glm(formula = cbind(m, f) ~ factor, family = binomial, data = dt2)
>
> Deviance Residuals:
> 1 2 3
> 0.01932 -0.03411 0.01747
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) -2.632 3.771 -0.698 0.485
> factor 2.035 2.881 0.706 0.480
>
> (Dispersion parameter for binomial family taken to be 1)
>
> Null deviance: 0.5031047 on 2 degrees of freedom
> Residual deviance: 0.0018418 on 1 degrees of freedom
> AIC: 15.115
>
> Number of Fisher Scoring iterations: 2
>
>> predict(dt.b, type="response")
> 1 2 3
> 0.4524946 0.5032227 0.5538845
>
>> predict(dt.m, type="probs")
> 1 2 3 4 5 6
> 0.4524948 0.4524948 0.5032229 0.5032229 0.5538846 0.5538846
>
> These fitted probabilities *are* correct: Since the members of each pair
> (1,2), (3,4), and (5,6) have identical values of factor they are identical
> fitted probabilities.
>
> (Note, by the way, the large negative correlation between the coefficients,
> produced by the configuration of factor values.)
>
> I hope this helps,
> John
>
> --------------------------------
> John Fox
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox
> --------------------------------
>
>> -----Original Message-----
>> From: r-help-bounces at stat.math.ethz.ch
>> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Marc Girondot
>> Sent: Saturday, June 11, 2005 3:06 AM
>> To: John Fox
>> Cc: r-help at stat.math.ethz.ch
>> Subject: [R] Problem with multinom ?
>>
>> Thanks for your response.
>> OK, multinom() is a more logical in this context.
>>
>> But similar problem occurs:
>>
>> Let these data to be analyzed using classical glm with binomial error:
>>
>> m f factor m theo f theo
>> -Ln L model -Ln L full interecept
>> f
>> 10 12 1.2 0.452494473 0.547505527
>> 1.778835688 1.778648963 2.632455675
>> -2.034882223
>> 14 14 1.3 0.503222759 0.496777241 1.901401922 1.900820284
>> 15 12 1.4 0.553884782 0.446115218 1.877062369 1.876909821
>>
>> Sum -Ln L
>> 5.557299979 5.556379068 Residual deviance
>> Deviance
>> 11.11459996 11.11275814 0.001841823
>>
>> If I try to use multinom() function to analyze these data,
>> the fitted parameters are correct but the residual deviance not.
>>
>>> dt<-read.table('/try.txt'. header=T)
>>> dt
>> output factor n
>> 1 m 1.2 10
>> 2 f 1.2 12
>> 3 m 1.3 14
>> 4 f 1.3 14
>> 5 m 1.4 15
>> 6 f 1.4 12
>>> dt.plr <- multinom(output ~ factor. data=dt. weights=n. maxit=1000)
>> # weights: 3 (2 variable)
>> initial value 53.372333
>> iter 10 value 53.115208
>> iter 10 value 53.115208
>> iter 10 value 53.115208
>> final value 53.115208
>> converged
>>> dt.plr
>> Call:
>> multinom(formula = output ~ factor. data = dt. weights = n.
>> maxit = 1000)
>>
>> Coefficients:
>> (Intercept) factor
>> -2.632443 2.034873
>>
>> Residual Deviance: 106.2304
>> AIC: 110.2304
>>
>>> dt.pr1<-predict(dt.plr. . type="probs")
>>> dt.pr1
>> 1 2 3 4 5 6
>> 0.4524948 0.4524948 0.5032229 0.5032229 0.5538846 0.5538846
>>
>> Probability for 2. 4 and 6 are not correct and its explain
>> the non-correct residual deviance obtained in R.
>> Probably the problem I have is due to an incorrect data
>> format... could someone help me...
>> Thanks
>>
>> (I know there is a simple way to analyze binomial data. but
>> in fine I want to use multinom() for 5 categories of outputs.
>>
>>
>> Thanks a lot
>>
>> Marc
>> --
>>
>> __________________________________________________________
>> Marc Girondot, Pr
>> Laboratoire Ecologie, Systématique et Evolution Equipe de
>> Conservation des Populations et des Communautés CNRS, ENGREF
>> et Université Paris-Sud 11 , UMR 8079 Bâtiment 362
>> 91405 Orsay Cedex, France
>>
>> Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1 69
>> 15 56 96 e-mail: marc.girondot at ese.u-psud.fr
>> Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
>> Skype: girondot
>> Fax in US: 1-425-732-6934
>>
>> ______________________________________________
>> 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
>
> ______________________________________________
> 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
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list