mc_variance_function: Variance Functions for Generalized Linear Models

View source: R/mc_variance_function.R

mc_variance_functionR Documentation

Variance Functions for Generalized Linear Models

Description

Computes the variance function and its derivatives with respect to regression, dispersion, and power parameters. This function supports standard power variance functions as well as binomial responses. Intended primarily for internal use in model fitting.

Usage

mc_variance_function(
  mu,
  power,
  Ntrial,
  variance,
  inverse,
  derivative_power,
  derivative_mu
)

mc_power(mu, power, inverse, derivative_power, derivative_mu)

mc_binomialP(mu, power, inverse, Ntrial,
                    derivative_power, derivative_mu)

mc_binomialPQ(mu, power, inverse, Ntrial,
                     derivative_power, derivative_mu)

Arguments

mu

Numeric vector of expected values. Typically obtained from mc_link_function.

power

Numeric value (for power and binomialP) or numeric vector of length two (for binomialPQ) representing the power parameters of the variance function.

Ntrial

Positive integer or numeric. Number of trials for binomial response variables.

variance

Character string specifying the variance function type: "power", "binomialP", or "binomialPQ".

inverse

Logical. If TRUE, computes the inverse square root of the variance function.

derivative_power

Logical. If TRUE, computes the derivative with respect to the power parameter.

derivative_mu

Logical. If TRUE, computes the derivative with respect to mu.

Details

The function computes the variance function and its derivatives used in the estimation of generalized linear models for multiple response variables. For binomial responses, it accounts for the number of trials and supports both single (binomialP) and double (binomialPQ) power specifications.

Value

A named list containing one or more of the following elements, depending on the combination of logical arguments:

V_sqrt

Square root of the variance function.

V_inv_sqrt

Inverse square root of the variance function.

D_V_sqrt_power

Derivative of V_sqrt with respect to the power parameter.

D_V_inv_sqrt_power

Derivative of V_inv_sqrt with respect to the power parameter.

D_V_sqrt_mu

Derivative of V_sqrt with respect to mu.

D_V_inv_sqrt_mu

Derivative of V_inv_sqrt with respect to mu.

Author(s)

Wagner Hugo Bonat

Source

Bonat, W. H. and Jorgensen, B. (2016) Multivariate covariance generalized linear models. Journal of the Royal Statistical Society: Series C (Applied Statistics), 65:649–675.

See Also

mc_link_function

Examples

x1 <- seq(-1, 1, length.out = 5)
X <- model.matrix(~x1)
mu <- mc_link_function(beta = c(1, 0.5), X = X, offset = NULL, link = "logit")
mc_variance_function(mu = mu$mu, power = c(2, 1), Ntrial = 1,
                     variance = "binomialPQ", inverse = FALSE,
                     derivative_power = TRUE, derivative_mu = TRUE)


mcglm documentation built on Jan. 9, 2026, 1:07 a.m.