Skip to contents

glm_nb_fit() fits a negative binomial GLM with its theta estimated with the coefficients by maximum likelihood, as MASS::glm.nb(): IRLS and Newton's method on theta alternate until both settle. se_theta is MASS's standard error and aic counts theta.

Usage

glm_nb_fit(formula, data, link = "log", offset = NULL, weights = NULL)

tweedie_glm_fit(
  formula,
  data,
  link = "log",
  offset = NULL,
  weights = NULL,
  min_power = 1.01,
  max_power = 1.99
)

tweedie_profile(
  formula,
  data,
  powers,
  link = "log",
  offset = NULL,
  weights = NULL
)

Arguments

formula

A model formula; offset(...) terms are honoured.

data

A data frame.

The link, "log" by default.

offset

Optional offset added to any offset() terms.

weights

Optional prior weights.

min_power, max_power

The power's search bounds, inside (1, 2).

powers

Powers to profile, increasing, inside (1, 2).

Value

A list with model, a glm_model at the estimate (its standard errors conditional on it), and, for glm_nb_fit(), theta, se_theta, log_likelihood and aic; for tweedie_glm_fit(), power, phi, log_likelihood, lower, upper, lower_open, upper_open and at_boundary; for tweedie_profile(), profile (a data frame of power, log_likelihood and dispersion), power, phi and max_log_likelihood.

Details

tweedie_glm_fit() fits a Tweedie GLM with its power estimated with the coefficients and dispersion: the profile log-likelihood over the power (the exact Tweedie density, maximized over the dispersion at each power) is maximized by Brent's method, with a 95% profile-likelihood interval (lower, upper; an end flagged open is a search bound). tweedie_profile() evaluates that profile on a grid of powers, as R's tweedie::tweedie.profile, and refines the best.

Examples

d <- data.frame(x = rep(0:2, 20), y = (0:59 * 7) %% 11)
nb <- glm_nb_fit(y ~ x, d)
nb$theta
#> [1] 3.187665