fgamma: Full Gamma Regression

Description Usage Arguments Details Value References See Also Examples

Description

Full gamma regression modeling the mu (mean) and sigma parameter as functions of explanatory variables using a "log" link for both parameters.

Usage

1
2
3
4
5
6
7
fgamma(formula, data, subset, na.action,
  model = TRUE, y = TRUE, x = FALSE,
  control = fgamma_control(...), ...)

fgamma_fit(x, y, z = NULL, control)

fgamma_control(maxit = 5000, start = NULL, grad = TRUE, hessian = TRUE, ...)

Arguments

formula

a formula expression of the form y ~ x | z where y is the response and x and z are regressor variables for the mean and the sigma parameter.

data

an optional data frame containing the variables occurring in the formulas.

subset

an optional vector specifying a subset of observations to be used for fitting.

na.action

a function which indicates what should happen when the data contain NAs.

model

logical. If TRUE model frame is included as a component of the returned value.

x, y

for fgamma: logical. If TRUE the model matrix and response vector used for fitting are returned as components of the returned value. For fgamma_fit: x is a design matrix with regressors for the mean (mu) and y is a vector of observations.

z

a design matrix with regressors for sigma.

...

arguments to be used to form the default control argument if it is not supplied directly.

maxit, start, control

a list of control parameters passed to optim .

grad

logical. Should gradients be used for optimization? If TRUE, the default method is "BFGS". Otherwise method = "Nelder-Mead" is used.

hessian

logical or character. Should a numeric approximation of the (negative) Hessian matrix be computed? Either FALSE (or equivalently "none") or TRUE. Alternatively, in the latter case, hessian = "numDeriv" could be specified to signal that the Hessian should be approximated by hessian. Another option is hessian = "numDeriv" so that optim is used for computing the Hessian.

Details

fgamma fits gamma regression models modeling mu and sigma with maximum likelihood estimation.

fgamma_fit is the lower level function where the actual fitting takes place.

Value

An object of class "fgamma".

References

Rigby RA, Stasinopoulos DM (2005). Generalized additive models for location, scale and shape,(with discussion). Appl. Statist., 54(3), 507–554.

See Also

gamlss

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
## packages
require("Formula")
require("gamlss")

## DGP
dgp <- function(n, coef = c(1, 1.5, 2, .04, .9, .1)) {
  d <- data.frame(
    x1 = runif(n, -1, 1),
    x2 = runif(n, -1, 1)
  )
  mu <- exp(coef[1] + coef[2] * d$x1 + coef[3] * d$x2)
  sigma <- exp(coef[4] + coef[5] * d$x1 + coef[6] * d$x2)
  shape <- 1/sigma^2
  scale <- sigma^2*mu
  d$y <- rgamma(n, shape = shape, scale = scale)
  return(d)
}

## Simulate data
set.seed(2017-05-15)
d <- dgp(500)

## model with fgamma
f1 <- fgamma(y ~ x1 + x2 | x1 + x2, data = d)

## model with gamlss
f2 <- gamlss <- gamlss(y ~ x1 + x2, data = d, family = GA, sigma.formula = ~ x1 + x2)

## compare estimates
# mu estimates
cbind(coef(f1, model = "mu"), coef(f2, what = "mu"))

# sigma estimates
cbind(coef(f1, model = "sigma"), coef(f2, what = "sigma"))

fgamma documentation built on May 2, 2019, 6:13 p.m.