Skip to contents

Fits a Poisson GLMM for count responses under a KK matching-on-the-fly design. The random intercept per matched pair is integrated out via Gauss-Hermite quadrature.

When use_rcpp = TRUE (default) the likelihood is maximised by an internal Rcpp routine. Set use_rcpp = FALSE to fall back to glmmTMB.

Model. \(Y_{ij} \mid b_i \sim \mathrm{Poisson}(\mu_{ij})\) with \(\log \mu_{ij} = X_{ij}'\beta + \beta_T \cdot W_{ij} + b_i\), where \(i\) indexes matched pairs, \(j \in \{1, 2\}\) the two subjects within a pair, \(W_{ij}\) is the treatment indicator, and \(b_i \sim \mathcal{N}(0, \sigma_b^2)\) is a pair-level random intercept absorbing within-pair correlation induced by matching. \(\beta_T\) is a log-rate (log relative risk) treatment effect: \(\exp(\hat\beta_T)\) is the estimated rate ratio. The random effect is integrated out of the marginal likelihood by adaptive Gauss-Hermite quadrature rather than a Laplace approximation.

Likelihood tier. likelihood_tier = "full": both Wald (model-based standard error) and likelihood-ratio testing types are available. Because the GLMM likelihood alone does not encode the KK design's matched-pair randomization structure, the likelihood-ratio CI/p-value are conservatively widened/calibrated against the design-aware Wald result (see compute_lik_ratio_confidence_interval()/ compute_lik_ratio_two_sided_pval()) so the model-based test is never anti-conservative relative to the design.

Assumptions. Count response modeled as conditionally Poisson given the random intercept (equidispersion conditional on \(b_i\)); pair-level random effects independent across pairs; a KK matching-on-the-fly design.

References

Kapelner, A. and Krieger, A. M. (2014). Matching on-the-fly: Sequential allocation with higher power and efficiency. Biometrics, 70(2), 378-388. doi:10.1111/biom.12148 . (KK14 in REFERENCES.md.)

See also

Analogous Python API for Poisson/count GLMs: statsmodels discrete models. Generalized linear model and Gauss-Hermite quadrature (orientation).

Super class

Inference -> InferenceCountKKGLMM

Methods

+ inherited public methods from Inference


InferenceCountKKGLMM$new()

Initialize a KK Poisson-GLMM inference object for a matched-pair KK design with a count response and prepare the matched-pair random-intercept likelihood machinery; see the class topic for the model.

Usage

InferenceCountKKGLMM$new(
  des_obj,
  model_formula = NULL,
  use_rcpp = TRUE,
  optimization_alg = NULL,
  verbose = FALSE,
  smart_cold_start_default = NULL
)

Arguments

des_obj

A completed KK matching-on-the-fly Design object (DesignSeqOneByOneKK14 or subclass) with a count response.

model_formula

Optional formula for covariate adjustment. If NULL (default), the formula from the design object is used.

use_rcpp

Logical. If TRUE (default), maximize the Gauss-Hermite-quadrature marginal likelihood with the internal Rcpp Poisson-GLMM routine; if FALSE, fall back to glmmTMB.

optimization_alg

Optimization algorithm passed to the likelihood maximizer. If NULL (default), an algorithm is dispatched via the package's optimizer policy.

verbose

Whether to print progress messages.

smart_cold_start_default

Whether to use smart starting values for the optimizer.


InferenceCountKKGLMM$compute_estimate()

Point estimate of the treatment log-rate coefficient \(\beta_T\) from a Poisson GLMM with a matched-pair random intercept, fit by maximizing the Gauss-Hermite-quadrature-integrated marginal likelihood (internal Rcpp routine when use_rcpp = TRUE, else glmmTMB). See the class topic for the model form.

Usage

InferenceCountKKGLMM$compute_estimate(estimate_only = FALSE)

Arguments

estimate_only

If TRUE, skip variance-component calculations.

Returns

Numeric scalar: the treatment coefficient on the log-rate (link) scale, i.e. \(\exp(\hat\beta_T)\) is a rate ratio.


InferenceCountKKGLMM$compute_estimate_with_bootstrap_weights()

Recomputes the KK Poisson-GLMM treatment estimate under nonparametric/ Bayesian-bootstrap subject-or-block weights, refitting the weighted GLMM (compute_weighted_glmm_bootstrap_estimate()). Standard error, degrees of freedom, and the cached summary table are cleared/set to NA/Inf/ NULL since only the point estimate is meaningful under resampling weights. Falls back to the unweighted point estimate when the weights are effectively constant.

Usage

InferenceCountKKGLMM$compute_estimate_with_bootstrap_weights(
  subject_or_block_weights,
  estimate_only = FALSE
)

Arguments

subject_or_block_weights

Numeric vector of nonnegative bootstrap replicate weights, one per subject or per matched block (KK match structure).

estimate_only

If TRUE, compute only the weighted point estimate (this method never computes a weighted standard error regardless of this argument).

Returns

Numeric scalar treatment-effect estimate (log-rate scale) under the given weights.


InferenceCountKKGLMM$compute_wald_confidence_interval()

Wald confidence interval for the treatment log-rate coefficient: \(\hat\beta_T \pm t_{1-\alpha/2,\,df}\cdot \hat{se}(\hat\beta_T)\), using the model-based GLMM standard error. See InferenceAsymp for the shared contract.

Usage

InferenceCountKKGLMM$compute_wald_confidence_interval(alpha = 0.05)

Arguments

alpha

The confidence level in the computed confidence interval is 1 - alpha. The default is 0.05.

Returns

A length-2 numeric vector c(lower, upper) on the log-rate scale.


InferenceCountKKGLMM$compute_wald_two_sided_pval()

Two-sided Wald p-value for \(H_0: \beta_T = \code{delta}\) vs. \(H_1: \beta_T \neq \code{delta}\), using the model-based GLMM standard error.

Usage

InferenceCountKKGLMM$compute_wald_two_sided_pval(delta = 0)

Arguments

delta

The null value of \(\beta_T\) to test against; 0 (the default) tests for any treatment effect at all.

Returns

Numeric scalar p-value in \([0, 1]\).


InferenceCountKKGLMM$compute_lik_ratio_confidence_interval()

Likelihood-ratio confidence interval for the treatment log-rate coefficient, inverting the GLMM's profile likelihood-ratio test against \(\chi^2_1\). Because the GLMM likelihood does not itself account for the KK matched-pair design's randomization structure, this interval is conservatively widened to be at least as wide as the design-aware Wald interval (compute_wald_confidence_interval()) via .conservative_kk_onelik_ci() – guarding against the model-based interval being anti-conservative relative to the design.

Usage

InferenceCountKKGLMM$compute_lik_ratio_confidence_interval(alpha = 0.05)

Arguments

alpha

The confidence level in the computed confidence interval is 1 - alpha. The default is 0.05.

Returns

A length-2 numeric vector c(lower, upper) on the log-rate scale.


InferenceCountKKGLMM$compute_lik_ratio_two_sided_pval()

Two-sided likelihood-ratio p-value for \(H_0: \beta_T = \code{delta}\), from the GLMM's profile likelihood-ratio test referred to \(\chi^2_1\). As with compute_lik_ratio_confidence_interval(), this is conservatively calibrated (via .conservative_kk_onelik_pval()) against the design-aware Wald p-value so the model-based test cannot be anti-conservative relative to the KK matched-pair design.

Usage

InferenceCountKKGLMM$compute_lik_ratio_two_sided_pval(delta = 0)

Arguments

delta

The null value of \(\beta_T\) to test against; 0 (the default) tests for any treatment effect at all.

Returns

Numeric scalar p-value in \([0, 1]\).


InferenceCountKKGLMM$compute_asymp_confidence_interval()

Asymptotic confidence interval, dispatching to compute_wald_confidence_interval() or compute_lik_ratio_confidence_interval() depending on self$get_testing_type() (defaults to Wald if the testing type is neither). See InferenceAsymp for the shared testing-type dispatch contract.

Usage

InferenceCountKKGLMM$compute_asymp_confidence_interval(alpha = 0.05)

Arguments

alpha

The confidence level in the computed confidence interval is 1 - alpha. The default is 0.05.

Returns

A length-2 numeric vector c(lower, upper) on the log-rate scale.


InferenceCountKKGLMM$compute_asymp_two_sided_pval()

Asymptotic two-sided p-value, dispatching to compute_wald_two_sided_pval() or compute_lik_ratio_two_sided_pval() depending on self$get_testing_type() (defaults to Wald if the testing type is neither). See InferenceAsymp for the shared testing-type dispatch contract.

Usage

InferenceCountKKGLMM$compute_asymp_two_sided_pval(delta = 0)

Arguments

delta

The null value of \(\beta_T\) to test against; 0 (the default) tests for any treatment effect at all.

Returns

Numeric scalar p-value in \([0, 1]\).


InferenceCountKKGLMM$clone()

The objects of this class are cloneable with this method.

Usage

InferenceCountKKGLMM$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# \donttest{
seq_des = DesignSeqOneByOneKK14$new(n = 10, response_type = 'count')
for (i in 1:10) {
  seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = rnorm(1), x2 = rnorm(1)))
}
seq_des$add_all_subject_responses(rpois(10, 2))
inf = InferenceCountKKGLMM$new(seq_des)
inf$compute_estimate()
#> [1] -0.01205704
# }