| gammaRff | R Documentation |
Estimates the 2–parameter gamma distribution by maximum likelihood. One linear predictor models the mean.
gammaRff(zero = "shape", lmu = "gammaRMlink",
lrate = NULL, lshape = "loglink",
irate = NULL, ishape = NULL, lss = TRUE)
zero |
Specifies the parameters to be modelled as intercept–only. See |
lmu |
The link function applied to the gamma distribution mean, i.e.,
|
lrate, lshape, irate, ishape, lss |
Same as |
This family function slightly enlarges the functionalities of
gammaR by directly modelling the mean
of the gamma distribution. It performs very much like
gamma2, but involves the ordinary
(not reparametrized) density, given by
f(y; \alpha, \beta) = \frac{ \beta^\alpha }{ \Gamma(\alpha) }
e^{-\beta y} y^{\alpha - 1},
Here, \alpha and \beta are positive shape
and rate parameters as in gammaR.
The default linear predictors are
\eta1 = {\tt{gammaRMlink}}(\alpha; \beta) = \log \mu =
\log (\alpha / \beta), and
\eta2 = \log \alpha,
unlike \eta1 = \log \beta and
\eta2 = \log \alpha
from gammaR.
lmu overrides lrate and no link other than
gammaRMlink is a valid entry
(lmu). To
mimic gammaR simply
set lmu = NULL and lrate = "loglink".
The mean (\mu) is returned as the fitted values.
gammaRff differs from
gamma2. The latter estimates a
re-parametrization
of the gamma distribution in terms \mu and
\alpha.
This VGAM family function does not handle censored data.
An object of class "vglm".
See vglm-class for full details.
The parameters \alpha and \beta
match 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.
gammaRMlink,
CommonVGAMffArguments,
gammaR,
gamma2,
Links.
### Modelling the mean in terms of x2, two responses.
set.seed(2017022101)
nn <- 80
x2 <- runif(nn)
mu <- exp(2 + 0.5 * x2)
# Shape and rate parameters in terms of 'mu'
shape <- rep(exp(1), nn)
rate <- gammaRMlink(theta = log(mu), shape = shape,
inverse = TRUE, deriv = 0)
# Generating some random data
y1 <- rgamma(n = nn, shape = shape, rate = rate)
gdata <- data.frame(x2 = x2, y1 = y1)
rm(y1)
# lmu = "gammaRMlink" replaces lshape, whilst lrate = "loglink"
fit1 <- vglm(cbind(y1, y1) ~ x2,
gammaRff(lmu = "gammaRMlink", lss = TRUE, zero = "shape"),
data = gdata, trace = TRUE, crit = "log")
coef(fit1, matrix = TRUE)
summary(fit1)
# Comparing fitted values with true values.
compare1 <- cbind(fitted.values(fit1)[, 1, drop = FALSE], mu)
colnames(compare1) <- c("Fitted.vM1", "mu")
head(compare1)
### Mimicking gammaR. Note that lmu = NULL.
fit2 <- vglm(y1 ~ x2, gammaRff(lmu = NULL, lrate = "loglink",
lshape = "loglink", lss = FALSE, zero = "shape"),
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)
### Use gamma2()
fit3 <- vglm(y1 ~ x2, gamma2,
data = gdata, trace = TRUE, crit = "log")
fit1.fit3 <- cbind(fitted.values(fit1)[, 1, drop = FALSE],
fitted.values(fit2), fitted.values(fit3))
colnames(fit1.fit3) <- c("Fitted.vM1", "Fitted.vM2", "Fitted.vM3")
head(fit1.fit3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.