gamma2.RdEstimates the 2-parameter gamma distribution by maximum likelihood estimation.
gamma2(lmu = "loglink", lshape = "loglink", imethod = 1, ishape = NULL,
parallel = FALSE, deviance.arg = FALSE, zero = "shape")Link functions applied to the (positive) mu and shape
parameters (called \(\mu\) and \(a\) respectively).
See Links for more choices.
Optional initial value for shape.
A NULL means a value is computed internally.
If a failure to converge occurs, try using this argument.
This argument is ignored if used within cqo; see the
iShape argument of qrrvglm.control instead.
An integer with value 1 or 2 which
specifies the initialization method for the \(\mu\) parameter.
If failure to converge occurs
try another value (and/or specify a value for ishape).
Logical. If TRUE, the deviance function
is attached to the object. Under ordinary circumstances, it should
be left alone because it really assumes the shape parameter is at
the maximum likelihood estimate. Consequently, one cannot use that
criterion to minimize within the IRLS algorithm.
It should be set TRUE only when used with cqo
under the fast algorithm.
See CommonVGAMffArguments for information.
Details at CommonVGAMffArguments.
If parallel = TRUE then the constraint is not applied to the intercept.
This distribution can model continuous skewed responses.
The density function is given by
$$f(y;\mu,a) = \frac{\exp(-a y / \mu) \times
(a y / \mu)^{a-1}
\times a}{
\mu \times \Gamma(a)}$$
for
\(\mu > 0\),
\(a > 0\)
and \(y > 0\).
Here,
\(\Gamma(\cdot)\) is the gamma
function, as in gamma.
The mean of Y is \(\mu=\mu\) (returned as the fitted
values) with variance \(\sigma^2 = \mu^2 / a\). If \(0<a<1\) then the density has a
pole at the origin and decreases monotonically as \(y\) increases.
If \(a=1\) then this corresponds to the exponential
distribution. If \(a>1\) then the density is zero at the
origin and is unimodal with mode at \(y = \mu - \mu / a\); this can be achieved with lshape="logloglink".
By default, the two linear/additive predictors are \(\eta_1=\log(\mu)\) and \(\eta_2=\log(a)\). This family function implements Fisher scoring and the working weight matrices are diagonal.
This VGAM family function handles multivariate responses,
so that a matrix can be used as the response. The number of columns is
the number of species, say, and zero=-2 means that all
species have a shape parameter equalling a (different) intercept only.
An object of class "vglmff" (see vglmff-class).
The object is used by modelling functions such as vglm
and vgam.
The parameterization of this VGAM family function is the 2-parameter gamma distribution described in the monograph
McCullagh, P. and Nelder, J. A. (1989). Generalized Linear Models, 2nd ed. London: Chapman & Hall.
The response must be strictly positive. A moment estimator for the shape parameter may be implemented in the future.
If mu and shape are vectors, then rgamma(n = n,
shape = shape, scale = mu/shape) will generate random gamma variates of this
parameterization, etc.;
see GammaDist.
gamma1 for the 1-parameter gamma distribution,
gammaR for another parameterization of
the 2-parameter gamma distribution that is directly matched
with rgamma,
bigamma.mckay
for a bivariate gamma distribution,
gammaff.mm for another,
expexpff,
GammaDist,
CommonVGAMffArguments,
simulate.vlm,
negloglink.
# Essentially a 1-parameter gamma
gdata <- data.frame(y = rgamma(n = 100, shape = exp(1)))
fit1 <- vglm(y ~ 1, gamma1, data = gdata)
fit2 <- vglm(y ~ 1, gamma2, data = gdata, trace = TRUE, crit = "coef")
#> Iteration 1: coefficients = 1.3814077, 1.3970382
#> Iteration 2: coefficients = 1.05717456, 0.42129181
#> Iteration 3: coefficients = 0.99173966, 0.84887395
#> Iteration 4: coefficients = 0.98950307, 1.00245425
#> Iteration 5: coefficients = 0.98950057, 1.01713645
#> Iteration 6: coefficients = 0.98950057, 1.01725643
#> Iteration 7: coefficients = 0.98950057, 1.01725644
coef(fit2, matrix = TRUE)
#> loglink(mu) loglink(shape)
#> (Intercept) 0.9895006 1.017256
c(Coef(fit2), colMeans(gdata))
#> mu shape y
#> 2.689891 2.765597 2.689891
# Essentially a 2-parameter gamma
gdata <- data.frame(y = rgamma(n = 500, rate = exp(-1), shape = exp(2)))
fit2 <- vglm(y ~ 1, gamma2, data = gdata, trace = TRUE, crit = "coef")
#> Iteration 1: coefficients = 3.1629118, 2.7427322
#> Iteration 2: coefficients = 2.9880070, 1.0416195
#> Iteration 3: coefficients = 2.9708050, 1.6282963
#> Iteration 4: coefficients = 2.9706553, 1.9172174
#> Iteration 5: coefficients = 2.9706553, 1.9712896
#> Iteration 6: coefficients = 2.9706553, 1.9728766
#> Iteration 7: coefficients = 2.9706553, 1.9728779
#> Iteration 8: coefficients = 2.9706553, 1.9728779
coef(fit2, matrix = TRUE)
#> loglink(mu) loglink(shape)
#> (Intercept) 2.970655 1.972878
c(Coef(fit2), colMeans(gdata))
#> mu shape y
#> 19.504697 7.191343 19.504697
summary(fit2)
#>
#> Call:
#> vglm(formula = y ~ 1, family = gamma2, data = gdata, trace = TRUE,
#> crit = "coef")
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept):1 2.97066 0.01668 178.13 <2e-16 ***
#> (Intercept):2 1.97288 0.06183 31.91 <2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Names of linear predictors: loglink(mu), loglink(shape)
#>
#> Log-likelihood: -1677.582 on 998 degrees of freedom
#>
#> Number of Fisher scoring iterations: 8
#>
#> No Hauck-Donner effect found in any of the estimates
#>