gammaRff: 2-parameter Gamma Distribution

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/gammaRff.R

Description

Estimates the 2–parameter gamma distribution by maximum likelihood. One linear predictor models the mean.

Usage

1
2
3
4
        gammaRff(zero = "shape", lmu = "gammaRMlink",
                 lrate = NULL, lshape = "loglink",
                  irate = NULL,   ishape = NULL, lss = TRUE)
                       

Arguments

zero

Specifies the parameters to be modelled as intercept–only.

See CommonVGAMffArguments.

lmu

The link function applied to the gamma distribution mean, i.e., gammaRMlink.

lrate, lshape, irate, ishape, lss

Same as gammaR.

Details

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) = rate^(shape) exp(-rate * y) y^(shape - 1) / Γ(shape),

Here, 'shape' and 'rate' are positive shape and rate parameters as in gammaR. The default linear predictors are η1 = gammaRMlink(rate; shape) = log μ = log (rate / shape), and η2 = log (shape), unlike η1 = log (rate) and η2 = log (shape) 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 (μ) is returned as the fitted values.

gammaRff differs from gamma2. The latter estimates a re-parametrization of the gamma distribution in terms μ and shape. This VGAM family function does not handle censored data.

Value

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

Note

The parameters shape and rate match the arguments shape and rate of rgamma.

Multiple responses are handled.

Author(s)

V. Miranda and Thomas W. Yee.

References

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

See Also

gammaRMlink, CommonVGAMffArguments, gammaR, gamma2, Links.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
  ### 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)

VGAMextra documentation built on May 24, 2021, 9:07 a.m.