wald_test_bnb: Wald test for BNB ratio of means

View source: R/wald_test_bnb.r

wald_test_bnbR Documentation

Wald test for BNB ratio of means

Description

Wald test for the ratio of means from bivariate negative binomial outcomes.

Usage

wald_test_bnb(
  data,
  ci_level = NULL,
  link = "log",
  ratio_null = 1,
  distribution = asymptotic(),
  ...
)

Arguments

data

(list)
A list whose first element is the vector of negative binomial values from sample 1 and the second element is the vector of negative binomial values from sample 2. Each vector must be sorted by the subject/item index and must be the same sample size. NAs are silently excluded. The default output from sim_bnb().

ci_level

(Scalar numeric: NULL; ⁠(0, 1)⁠)
If NULL, confidence intervals are set as NA. If in ⁠(0, 1)⁠, confidence intervals are calculated at the specified level.

link

(Scalar string: "log")
The one-to-one link function for transformation of the ratio in the test hypotheses. Must be one of "log" (default), "sqrt", "squared", or "identity". See 'Details' for additional information.

ratio_null

(Scalar numeric: 1; ⁠(0, Inf)⁠)
The (pre-transformation) ratio of means assumed under the null hypothesis (sample 2 / sample 1). Typically ratio_null = 1 (no difference). See 'Details' for additional information.

distribution

(function: asymptotic() or simulated())
The method used to define the distribution of the \chi^2 Wald test statistic under the null hypothesis. See 'Details' and asymptotic() or simulated() for additional information.

...

Optional arguments passed to the MLE function mle_bnb().

Details

This function is primarily designed for speed in simulation. Missing values are silently excluded.

Suppose X_1 \mid G = g \sim \text{Poisson}(\mu g) and X_2 \mid G = g \sim \text{Poisson}(r \mu g) where G \sim \text{Gamma}(\theta, \theta^{-1}) is the random item (subject) effect. Then X_1, X_2 \sim \text{BNB}(\mu, r, \theta) is the joint distribution where X_1 and X_2 are dependent (though conditionally independent), X_1 is the count outcome for sample 1 of the items (subjects), X_2 is the count outcome for sample 2 of the items (subjects), \mu is the conditional mean of sample 1, r is the ratio of the conditional means of sample 2 with respect to sample 1, and \theta is the gamma distribution shape parameter which controls the dispersion and the correlation between sample 1 and 2.

The hypotheses for the Wald test of r are

\begin{aligned} H_{null} &: f(r) = f(r_{null}) \\ H_{alt} &: f(r) \neq f(r_{null}) \end{aligned}

where f(\cdot) is a one-to-one link function with nonzero derivative, r = \frac{\bar{X}_2}{\bar{X}_1} is the population ratio of arithmetic means for sample 2 with respect to sample 1, and r_{null} is a constant for the assumed null population ratio of means (typically r_{null} = 1).

\insertCite

rettiganti_2012;textualdepower found that f(r) = r^2, f(r) = r, and f(r) = r^{0.5} had greatest power when r < 1. However, when r > 1, f(r) = \ln r, the likelihood ratio test, and f(r) = r^{0.5} had greatest power. f(r) = r^2 was biased when r > 1. Both f(r) = \ln r and f(r) = r^{0.5} produced acceptable results for any r value. These results depend on the use of asymptotic vs. exact critical values.

The Wald test statistic is

W(f(\hat{r})) = \left( \frac{f \left( \frac{\bar{x}_2}{\bar{x}_1} \right) - f(r_{null})}{f^{\prime}(\hat{r}) \hat{\sigma}_{\hat{r}}} \right)^2

where

\hat{\sigma}^{2}_{\hat{r}} = \frac{\hat{r} (1 + \hat{r}) (\hat{\mu} + \hat{r}\hat{\mu} + \hat{\theta})}{n \left[ \hat{\mu} (1 + \hat{r}) (\hat{\mu} + \hat{\theta}) - \hat{\theta}\hat{r} \right]}

Under H_{null}, the Wald test statistic is asymptotically distributed as \chi^2_1. The approximate level \alpha test rejects H_{null} if W(f(\hat{r})) \geq \chi^2_1(1 - \alpha). However, the asymptotic critical value is known to underestimate the exact critical value and the nominal significance level may not be achieved for small sample sizes. The level of significance inflation also depends on f(\cdot) and is most severe for f(r) = r^2 where only the exact critical value should be used. Argument distribution allows control of the distribution of the \chi^2_1 test statistic under the null hypothesis by use of functions asymptotic() and simulated().

Value

A list with the following elements:

Slot Subslot Name Description
1 chisq \chi^2 test statistic for the ratio of means.
2 df Degrees of freedom.
3 p p-value.
4 ratio Estimated ratio of means (group 2 / group 1).
4 1 estimate Point estimate.
4 2 lower Confidence interval lower bound.
4 3 upper Confidence interval upper bound.
5 mean1 Estimated mean of sample 1.
6 mean2 Estimated mean of sample 2.
7 dispersion Estimated dispersion.
8 n1 The sample size of sample 1.
9 n2 The sample size of sample 2.
10 method Method used for the results.
11 ci_level The confidence level.
12 link Link function used to transform the ratio of means in the test hypotheses.
13 ratio_null Assumed ratio of means under the null hypothesis.
14 mle_code Integer indicating why the optimization process terminated.
15 mle_message Information from the optimizer.

References

\insertRef

rettiganti_2012depower

\insertRef

aban_2009depower

See Also

lrt_bnb()

Examples

#----------------------------------------------------------------------------
# wald_test_bnb() examples
#----------------------------------------------------------------------------
library(depower)

set.seed(1234)
sim_bnb(
  n = 40,
  mean1 = 10,
  ratio = 1.2,
  dispersion = 2
) |>
  wald_test_bnb()


depower documentation built on Nov. 5, 2025, 5:21 p.m.