11
11
mix2poisson(lphi = "logit", llambda = "loge",
12
ephi=list(), el1=list(), el2=list(),
12
ephi = list(), el1 = list(), el2 = list(),
13
13
iphi = 0.5, il1 = NULL, il2 = NULL,
14
qmu = c(0.2, 0.8), nsimEIM=100, zero = 1)
14
qmu = c(0.2, 0.8), nsimEIM = 100, zero = 1)
16
16
%- maybe also 'usage' for other objects documented here.
19
Link function for the parameter \eqn{\phi}{phi}.
20
See \code{\link{Links}} for more choices.
24
Link function applied to each \eqn{\lambda}{lambda} parameter.
19
Link functions for the parameter \eqn{\phi}{phi} and
20
\eqn{\lambda}{lambda}.
25
21
See \code{\link{Links}} for more choices.
50
46
\code{\link[stats]{quantile}}.
54
50
See \code{\link{CommonVGAMffArguments}}.
58
An integer specifying which linear/additive predictor is modelled as
59
intercepts only. If given, the value must be either 1 and/or 2 and/or
60
3, and the default is the first one only, meaning \eqn{\phi}{phi}
61
is a single parameter even when there are explanatory variables.
62
Set \code{zero=NULL} to model all linear/additive predictors as
63
functions of the explanatory variables.
64
See \code{\link{CommonVGAMffArguments}} for more information.
69
55
The probability function can be loosely written as
79
65
\eqn{(logit(\phi), \log(\lambda_1), \log(\lambda_2))^T}{(logit(phi),
80
66
log(lambda1), log(lambda2))^T}.
84
71
An object of class \code{"vglmff"} (see \code{\link{vglmff-class}}).
85
72
The object is used by modelling functions such as \code{\link{vglm}}
86
73
and \code{\link{vgam}}.
89
77
% \references{ ~put references to the literature/web site here ~ }
90
78
\section{Warning }{
96
84
\code{il2}, \code{qmu} is highly recommended. Graphical methods such
97
85
as \code{\link[graphics]{hist}} can be used as an aid.
99
88
With grouped data (i.e., using the \code{weights} argument)
100
89
one has to use a large value of \code{nsimEIM};
101
90
see the example below.
105
95
\author{ T. W. Yee }
107
97
The response must be integer-valued since \code{\link[stats]{dpois}}
110
101
Fitting this model successfully to data can be difficult due to local
111
102
solutions and ill-conditioned data. It pays to fit the model several
112
103
times with different initial values, and check that the best fit
113
104
looks reasonable. Plotting the results is recommended. This function
114
105
works better as \eqn{\lambda_1}{lambda1} and \eqn{\lambda_2}{lambda2}
115
106
become more different.
116
The default control argument \code{trace=TRUE} is to encourage
107
The default control argument \code{trace = TRUE} is to encourage
117
108
monitoring convergence.
122
114
\code{\link[stats:Poisson]{rpois}},
123
115
\code{\link{poissonff}},
124
116
\code{\link{mix2normal1}}.
130
124
mu1 = exp(2.5) # also known as lambda1
132
(phi = logit(-0.5, inverse=TRUE))
126
(phi = logit(-0.5, inverse = TRUE))
133
127
mdata = data.frame(y = ifelse(runif(nn) < phi, rpois(nn, mu1), rpois(nn, mu2)))
134
128
fit = vglm(y ~ 1, mix2poisson, mdata)
135
coef(fit, matrix=TRUE)
129
coef(fit, matrix = TRUE)
137
131
# Compare the results with the truth
138
round(rbind('Estimated'=Coef(fit), 'Truth'=c(phi, mu1, mu2)), dig=2)
132
round(rbind('Estimated' = Coef(fit), 'Truth' = c(phi, mu1, mu2)), dig = 2)
140
134
\dontrun{# Plot the results
141
135
ty = with(mdata, table(y))
142
plot(names(ty), ty, type="h", main="Red=estimate, blue=truth",
143
ylab="Frequency", xlab="y")
144
abline(v=Coef(fit)[-1], lty=2, col="red", lwd=2)
145
abline(v=c(mu1, mu2), lty=2, col="blue", lwd=2) }
136
plot(names(ty), ty, type = "h", main = "Orange=estimate, blue=truth",
137
ylab = "Frequency", xlab = "y")
138
abline(v = Coef(fit)[-1], lty = 2, col = "orange", lwd = 2)
139
abline(v = c(mu1, mu2), lty = 2, col = "blue", lwd = 2) }
147
141
# Example 2: London Times data (Lange, 1997, p.31)
148
142
ltdata1 = data.frame(deaths = 0:9,
150
144
ltdata2 = data.frame(y = with(ltdata1, rep(deaths, freq)))
152
146
# Usually this does not work well unless nsimEIM is large
153
fit = vglm(deaths ~ 1, weight=freq, data=ltdata1,
154
mix2poisson(iphi=0.3, il1=1, il2=2.5, nsimEIM=5000))
147
fit = vglm(deaths ~ 1, weight = freq, data = ltdata1,
148
mix2poisson(iphi = 0.3, il1 = 1, il2 = 2.5, nsimEIM = 5000))
156
150
# This works better in general
157
fit = vglm(y ~ 1, mix2poisson(iphi=0.3, il1=1, il2=2.5), ltdata2)
158
coef(fit, matrix=TRUE)
151
fit = vglm(y ~ 1, mix2poisson(iphi = 0.3, il1 = 1, il2 = 2.5), ltdata2)
152
coef(fit, matrix = TRUE)