gammaRMean {VGAMextra} | R Documentation |
Estimates the 2–parameter gamma distribution by maximum likelihood estimation by modelling its mean.
gammaRMean(zero = "rate", lmu = "gammaRMeanlink", lrate = "loge", lshape = NULL, irate = NULL, ishape = NULL, lss = TRUE)
zero |
Specifies the parameters to be modelled as intercept–only. See |
lmu |
The link function applied to model the mean of this distribution:
|
lrate, lshape, irate, ishape, lss |
Same as |
This family function slightly enlarges the functionalities of
gammaR
allowing the extent of the
linear predictor to model the mean of the 2–parameter
gamma distribution, with density
f(y; alpha, beta) = rate^(shape) exp(-rate * y) y^(shape - 1) / Γ(shape),
Here, shape and rate are positive shape
and rate parameters as in gammaR
.
The mean is given by
μ = shape / rate.
Unlike gammaR
where
the default linear predictors are
η1 = log (shape) and
η2 = log (rate), this family function
re–defines this structure by setting up
η1 = gammaRMeanlink(shape; rate) and
η2 = log (rate) by default, where
gammaRMeanlink
is
the link function for the mean of Y.
To mimic the work of gammaR
,
set lmu = NULL
and lshape = "loge"
.
Particularly, lss
works exactly as with
gammaR
For further choices on link functions for η2,
see Links
.
This family function also differs from
gamma2
. The latter is re-parametrization
of the gamma distribution to estimate μ and
shape. That is, the density is re–expressed
in terms of μ and shape specifically.
Notice, to model the mean of the gamma distribution with this
family function, the link
gammaRMeanlink
must be necessarily used via lmu
. Here, lmu
overrides the work of lshape
. Then, the transformed mean
gammaRMeanlink(shape; rate)
are returned as the fitted values, for estimated shape and rate.
An object of class "vglm"
.
See vglm-class
for full details.
The fitted values returned are gammaRMeanlink
–transformed,
provided the mean is modelled via lmu
The parameters shape and rate
match with the arguments shape
and rate of
rgamma
.
Multiple responses are handled.
V. Miranda and Thomas W. Yee.
Yee, T. W. (2015) Vector Generalized Linear and Additive Models: With an Implementation in R. Springer, New York, USA.
gammaRMeanlink
,
CommonVGAMffArguments
,
gammaR
,
gamma2
,
Links
.
### Modelling the mean in terms of x2, two responses. set.seed(2017022101) nn <- 80 x2 <- runif(nn) mu <- exp(1 + 0.5 * x2) # Shape and rate parameters in terms of 'mu' rate <- rep(exp(1), nn) shape <- gammaRMeanlink(theta = mu, rate = rate, inverse = TRUE, deriv = 0) # Generate some random data y1 <- rgamma(n = nn, shape = shape, rate = rate) gdata <- data.frame(x2 = x2, y1 = y1) rm(y1) # lmu = "gammaRMeanlink" replaces lshape, whilst lrate = "loge" fit1 <- vglm(cbind(y1, y1) ~ x2, gammaRMean(lmu = "gammaRMeanlink", lss = FALSE, zero = "rate"), data = gdata, trace = TRUE, crit = "log") coef(fit1, matrix = TRUE) summary(fit1) # Compare fitted values with true values. compare1 <- cbind(fitted.values(fit1)[, 1, drop = FALSE], mu) colnames(compare1) <- c("Fitted.vM1", "mu") head(compare1) ### Mimicking gammaR. Notice lmu = NULL. fit2 <- vglm(y1 ~ x2, gammaRMean(lmu = NULL, lshape = "loge", lrate = "loge", lss = FALSE, zero = "rate"), data = gdata, trace = TRUE, crit = "log") # Compare fitted values with true values. compare2 <- with(gdata, cbind(fitted.values(fit2), y1, mu)) colnames(compare2) <- c("Fitted.vM2", "y", "mu") head(compare2) ### Fitted values -- Model1 vs Fitted values -- Model2 fit1vsfit2 <- cbind(fitted.values(fit1)[, 1, drop = FALSE], fitted.values(fit2)) colnames(fit1vsfit2) <- c("Fitted.vM1", "Fitted.vM2") head(fit1vsfit2)