Learn R Programming

depower (version 2025.1.20)

lrt_nb: Likelihood ratio test for NB ratio of means

Description

Likelihood ratio test for the ratio of means from two independent negative binomial outcomes.

Usage

lrt_nb(data, equal_dispersion = FALSE, ratio_null = 1, ...)

Value

A list with the following elements:

SlotSubslotNameDescription
1chisq\(\chi^2\) test statistic for the ratio of means.
2dfDegrees of freedom.
3pp-value.
4ratioEstimated ratio of means (group 2 / group 1).
5alternativePoint estimates under the alternative hypothesis.
51mean1Estimated mean of group 1.
52mean2Estimated mean of group 2.
53dispersion1Estimated dispersion of group 1.
54dispersion2Estimated dispersion of group 2.
6nullPoint estimates under the null hypothesis.
61mean1Estimated mean of group 1.
62mean2Estimated mean of group 2.
63dispersion1Estimated dispersion of group 1.
64dispersion2Estimated dispersion of group 2.
7n1Sample size of group 1.
8n2Sample size of group 2.
9methodMethod used for the results.
10equal_dispersionWhether or not equal dispersions were assumed.
11ratio_nullAssumed population ratio of means.
12mle_codeInteger indicating why the optimization process terminated.
13mle_messageInformation from the optimizer.

Arguments

data

(list)
A list whose first element is the vector of negative binomial values from group 1 and the second element is the vector of negative binomial values from group 2. NAs are silently excluded. The default output from sim_nb().

equal_dispersion

(Scalar logical: FALSE)
If TRUE, the LRT is calculated assuming both groups have the same population dispersion parameter. If FALSE (default), the LRT is calculated assuming different dispersions.

ratio_null

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

...

Optional arguments passed to the MLE function mle_nb().

Details

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

Suppose \(X_1 \sim NB(\mu, \theta_1)\) and \(X_2 \sim NB(r\mu, \theta_2)\) where \(X_1\) and \(X_2\) are independent, \(X_1\) is the count outcome for items in group 1, \(X_2\) is the count outcome for items in group 2, \(\mu\) is the arithmetic mean count in group 1, \(r\) is the ratio of arithmetic means for group 2 with respect to group 1, \(\theta_1\) is the dispersion parameter of group 1, and \(\theta_2\) is the dispersion parameter of group 2.

The hypotheses for the LRT of \(r\) are

$$ \begin{aligned} H_{null} &: r = r_{null} \\ H_{alt} &: r \neq r_{null} \end{aligned} $$

where \(r = \frac{\bar{X}_2}{\bar{X}_1}\) is the population ratio of arithmetic means for group 2 with respect to group 1 and \(r_{null}\) is a constant for the assumed null population ratio of means (typically \(r_{null} = 1\)).

The LRT statistic is

$$ \begin{aligned} \lambda &= -2 \ln \frac{\text{sup}_{\Theta_{null}} L(r, \mu, \theta_1, \theta_2)}{\text{sup}_{\Theta} L(r, \mu, \theta_1, \theta_2)} \\ &= -2 \left[ \ln \text{sup}_{\Theta_{null}} L(r, \mu, \theta_1, \theta_2) - \ln \text{sup}_{\Theta} L(r, \mu, \theta_1, \theta_2) \right] \\ &= -2(l(r_{null}, \tilde{\mu}, \tilde{\theta}_1, \tilde{\theta}_2) - l(\hat{r}, \hat{\mu}, \hat{\theta}_1, \hat{\theta}_2)) \end{aligned} $$

Under \(H_{null}\), the LRT test statistic is asymptotically distributed as \(\chi^2_1\). The approximate level \(\alpha\) test rejects \(H_{null}\) if \(\lambda \geq \chi^2_1(1 - \alpha)\). Note that the asymptotic critical value is known to underestimate the exact critical value. Hence, the nominal significance level may not be achieved for small sample sizes (possibly \(n \leq 10\) or \(n \leq 50\)).

References

rettiganti_2012depower

aban_2009depower

Examples

Run this code
#----------------------------------------------------------------------------
# lrt_nb() examples
#----------------------------------------------------------------------------
library(depower)

set.seed(1234)
sim_nb(
  n1 = 60,
  n2 = 40,
  mean1 = 10,
  ratio = 1.5,
  dispersion1 = 2,
  dispersion2 = 8
) |>
  lrt_nb()

Run the code above in your browser using DataLab