~ubuntu-branches/ubuntu/trusty/r-cran-vgam/trusty

« back to all changes in this revision

Viewing changes to man/mix2poisson.Rd

  • Committer: Package Import Robot
  • Author(s): Chris Lawrence
  • Date: 2011-11-04 13:13:06 UTC
  • mfrom: (1.2.9)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20111104131306-w9fd83i51rw60gxf
Tags: upstream-0.8-4
ImportĀ upstreamĀ versionĀ 0.8-4

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
}
10
10
\usage{
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)
15
15
}
16
16
%- maybe also 'usage' for other objects documented here.
17
17
\arguments{
18
 
  \item{lphi}{
19
 
    Link function for the parameter \eqn{\phi}{phi}.
20
 
    See \code{\link{Links}} for more choices.
21
 
 
22
 
  }
23
 
  \item{llambda}{
24
 
    Link function applied to each \eqn{\lambda}{lambda} parameter.
 
18
  \item{lphi, llambda}{
 
19
    Link functions for the parameter \eqn{\phi}{phi} and
 
20
    \eqn{\lambda}{lambda}.
25
21
    See \code{\link{Links}} for more choices.
26
22
 
27
23
  }
50
46
    \code{\link[stats]{quantile}}.
51
47
 
52
48
  }
53
 
  \item{nsimEIM}{
 
49
  \item{nsimEIM, zero}{
54
50
  See \code{\link{CommonVGAMffArguments}}.
55
51
 
56
52
  }
57
 
  \item{zero}{
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.
65
 
 
66
 
  }
67
53
}
68
54
\details{
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}.
81
67
 
 
68
 
82
69
}
83
70
\value{
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}}.
87
74
 
 
75
 
88
76
}
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.
98
86
 
 
87
 
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.
102
91
 
 
92
 
103
93
}
104
94
 
105
95
\author{ T. W. Yee }
107
97
  The response must be integer-valued since \code{\link[stats]{dpois}}
108
98
  is invoked.
109
99
 
 
100
 
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.
118
109
 
 
110
 
119
111
}
120
112
 
121
113
\seealso{
122
114
  \code{\link[stats:Poisson]{rpois}},
123
115
  \code{\link{poissonff}},
124
116
  \code{\link{mix2normal1}}.
 
117
 
 
118
 
125
119
}
126
120
 
127
121
\examples{
129
123
nn = 1000
130
124
mu1 = exp(2.5) # also known as lambda1
131
125
mu2 = exp(3)
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)
136
130
 
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)
139
133
 
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) }
146
140
 
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)))
151
145
 
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))
155
149
 
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)
159
153
Coef(fit)
160
154
}
161
155
\keyword{models}