glmm_marginal: Marginal effect from a binomial-logit or Poisson-log GLMM

View source: R/marginal.R

glmm_marginalR Documentation

Marginal effect from a binomial-logit or Poisson-log GLMM

Description

Marginal effect from a binomial-logit or Poisson-log GLMM

Usage

glmm_marginal(
  X,
  beta,
  M,
  family,
  x,
  at = character(0),
  atvals = numeric(0),
  atmeans = character(0),
  average = character(0),
  re_type = c("AtZero", "AtEstimated", "At", "Average"),
  type = c("DyDx", "Diff", "Ratio"),
  xvals = c(0, 1),
  Zu = NULL,
  zu_samples = NULL,
  has_intercept = TRUE
)

Arguments

X

n x P design matrix. Must have column names.

beta

length-P fitted coefficient vector.

M

P x P variance-covariance matrix of beta (caller chooses model-based / sandwich / KR etc.).

family

"binomial" (logit) or "poisson" (log).

x

Name (character) or index (integer) of the column whose marginal effect we want.

at

Character vector of column names to fix at user values.

atvals

Numeric vector matching 'at'.

atmeans

Character vector of column names to fix at column mean.

average

Character vector of column names to average over (their empirical distribution in X is preserved).

re_type

Random-effect treatment: "At" - fix Zu at user value(s) via 'Zu' "AtEstimated" - posterior-mean Zu = rowMeans(zu_samples) "AtZero" - Zu = 0 "Average" - integrate over MCMC draws in zu_samples

type

"DyDx", "Diff", or "Ratio".

xvals

Length-2 numeric. DyDx is evaluated at xvals[1]; Diff and Ratio compare xvals[1] vs xvals[2].

Zu

Used only when re_type = "At". Either a single scalar (when no covariates are averaged) or a length-n vector of pre-computed Z u values (when 'average' is non-empty or only x is named with re_type Average/AtEstimated).

zu_samples

n x iter matrix of MCMC draws of Zu. Required for re_type = "Average" or "AtEstimated".

has_intercept

TRUE if the first / an intercept column is in X and should not be counted among "named" variables. Used only for the 'at' + 'atmeans' + 'average' + 1 == P - int consistency check.

Value

list with elements 'estimate', 'se', plus the input choices.


marginme documentation built on June 7, 2026, 9:08 a.m.