Description Usage Arguments Details Value References See Also Examples
Full gamma regression modeling the mu (mean) and sigma parameter as functions of explanatory variables using a "log" link for both parameters.
1 2 3 4 5 6 7 |
formula |
a formula expression of the form |
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 |
model |
logical. If |
x, y |
for |
z |
a design matrix with regressors for sigma. |
... |
arguments to be used to form the default |
maxit, start, control |
a list of control parameters passed to |
grad |
logical. Should gradients be used for optimization? If |
hessian |
logical or character. Should a numeric approximation of the
(negative) Hessian matrix be computed? Either |
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.
An object of class "fgamma"
.
Rigby RA, Stasinopoulos DM (2005). Generalized additive models for location, scale and shape,(with discussion). Appl. Statist., 54(3), 507–554.
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"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.