Learn R Programming

VGAMextra (version 0.0-1)

gammaRMean: 2--parameter Gamma Distribution

Description

Estimates the 2--parameter gamma distribution by maximum likelihood estimation by modelling its mean.

Usage

gammaRMean(zero = "rate", lmu = "gammaRMeanlink",
                   lrate = "loge", lshape = NULL,
                   irate = NULL,   ishape = NULL,
                   lss = TRUE)

Arguments

zero

Specifies the parameters to be modelled as intercept--only.

See CommonVGAMffArguments for further information.

lmu

The link function applied to model the mean of this distribution: gammaRMeanlink.

lrate, lshape, irate, ishape, lss

Same as gammaR.

Value

An object of class "vglm". See vglm-class for full details.

Details

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) = \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 mean is given by \(\mu = \alpha / \beta\).

Unlike gammaR where the default linear predictors are \(\eta1 = \log \alpha\) and \(\eta2 = \log \beta\), this family function re--defines this structure by setting up \(\eta1 = {\tt{gammaRMeanlink}}(\alpha; \beta)\) and \(\eta2 = \log \beta\) 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 \(\eta_2\), see Links.

This family function also differs from gamma2. The latter is re-parametrization of the gamma distribution to estimate \(\mu\) and \(\alpha\). That is, the density is re--expressed in terms of \(\mu\) and \(\alpha\) 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 $${\tt{gammaRMeanlink}}(\alpha; \beta)$$ are returned as the fitted values, for estimated \(\alpha\) and \(\beta\).

References

Yee, T. W. (2015) Vector Generalized Linear and Additive Models: With an Implementation in R. Springer, New York, USA.

See Also

gammaRMeanlink, CommonVGAMffArguments, gammaR, gamma2, Links.

Examples

Run this code
# NOT RUN {
 
  ### 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)

# }

Run the code above in your browser using DataLab