I am trying to compare the fit a multinomial logit model using GLM, instead
of MULTINOM so that I will be able to restrict the parameter space of the
logit model. My problem is that for the saturated model, which is the
default in MULTINOM the fitted values are different from those obtained
using GLM. I attach the code used below. The result are close in terms of
the deviance but the fitted values are so different.
set.seed(124)
xvar <- rnorm(10, 0, 1)
set.seed(124)
data1 <- rbinom(10, size = 1, prob = (exp(0.5 + 0.4 * xvar)/(1 + exp(0.5 +
0.4 *
xvar))))
set.seed(421)
data2 <- rbinom(10, size = 1, prob = (exp(1 - 0.3 * xvar)/(1 + exp(1 - 0.3
*
xvar))))
temp.1 <- ifelse(data1a == 1 & data2a == 1, 1, 0)
temp.2 <- ifelse(data1a == 1 & data2a == 0, 1, 0)
temp.3 <- ifelse(data1a == 0 & data2a == 1, 1, 0)
data <- matrix(cbind(temp.1, temp.2, temp.3), ncol = 3)
library(Nnet)
test <- multinom(data ~ xvar)
# weights: 9 (4 variable)
initial value 10.986123
final value 10.086649
converged
test
Call:
multinom(formula = data ~ xvar)
Coefficients:
(Intercept) xvar
2 -1.04266922 -1.0285457
3 -0.01203657 -0.2257753
Residual Deviance: 20.1733
AIC: 28.1733
fitted(test)
[,1] [,2] [,3]
1 0.3974839 0.18505870 0.4174574
2 0.4855567 0.09391712 0.4205262
3 0.2806269 0.35282770 0.3665454
4 0.5488520 0.04935799 0.4017900
5 0.2642819 0.38016742 0.3555507
6 0.4089651 0.17134756 0.4196873
7 0.4735976 0.10434191 0.4220605
8 0.3010403 0.31998196 0.3789778
9 0.4981903 0.08359451 0.4182152
10 0.3413697 0.25940290 0.3992274
data <- rbind(temp.1, temp.2, temp.3)
xvar <- rep(xvar, 3)
temp.1 <- rep(c(0, 1, 0), each = 10)
temp.2 <- rep(c(0, 0, 1), each = 10)
data <- data.frame(data, xvar, temp.1, temp.2)
test <- glm(data ~ xvar * (1 + temp.1 + temp.2), poisson, data = data)
test
Call:
glm(formula = data ~ xvar * (1 + temp.1 + temp.2), family = poisson, data =
data)
Coefficients:
(Intercept) xvar temp.1 temp.2 xvar:temp.1 xvar:temp.2
-0.8967492 0.2682157 -1.031684 -0.01165882 -0.9957705 -0.2182704
Degrees of Freedom: 30 Total; 24 Residual
Residual Deviance: 20.18794
matrix(fitted(test), nrow = 10, ncol = 3)
[,1] [,2] [,3]
[1,] 0.3793512 0.17699156 0.3977560
[2,] 0.4770040 0.09508330 0.4150891
[3,] 0.2927745 0.35738765 0.3790235
[4,] 0.5824457 0.05531380 0.4308163
[5,] 0.2826733 0.39309903 0.3765535
[6,] 0.3899280 0.16426934 0.3997980
[7,] 0.4610806 0.10425614 0.4124730
[8,] 0.3058806 0.31735829 0.3821270
[9,] 0.4950140 0.08598924 0.4179636
[10,] 0.3338564 0.25029432 0.3884054
Thanking you in advance.
Vumani Dlamini
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
|