MLE for BNB
mle_bnb.RdMaximum likelihood estimates (MLE) for bivariate negative binomial outcomes.
Usage
mle_bnb_null(data, ratio_null = 1, method = "nlm_constrained", ...)
mle_bnb_alt(data, method = "nlm_constrained", ...)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 fromsim_bnb().- ratio_null
(Scalar numeric:
1;(0, Inf))
The ratio of means assumed under the null hypothesis (sample 2 / sample 1). Typicallyratio_null = 1(no difference).- method
(string:
"nlm_constrained")
The optimization method. Must choose one of"nlm","nlm_constrained","optim", or"optim_constrained". The default bounds for constrained optimization are[1e-03, 1e06].- ...
Optional arguments passed to the optimization method.
Value
For
mle_bnb_alt, a list with the following elements:Slot Name Description 1 mean1MLE for mean of sample 1. 2 mean2MLE for mean of sample 2. 3 ratioMLE for ratio of means. 4 dispersionMLE for BNB dispersion. 5 nllMinimum of negative log-likelihood. 6 nparamsNumber of estimated parameters. 7 n1Sample size of sample 1. 8 n2Sample size of sample 2. 9 methodMethod used for the results. 10 mle_methodMethod used for optimization. 11 mle_codeInteger indicating why the optimization process terminated. 12 mle_messageAdditional information from the optimizer. For
mle_bnb_null, a list with the following elements:Slot Name Description 1 mean1MLE for mean of sample 1. 2 mean2MLE for mean of sample 2. 3 ratio_nullPopulation ratio of means assumed for null hypothesis. mean2 = mean1 * ratio_null.4 dispersionMLE for BNB dispersion. 5 nllMinimum of negative log-likelihood. 6 nparamsNumber of estimated parameters. 7 n1Sample size of sample 1. 8 n2Sample size of sample 2. 9 methodMethod used for the results. 10 mle_methodMethod used for optimization. 11 mle_codeInteger indicating why the optimization process terminated. 12 mle_messageAdditional information from the optimizer.
Details
These functions are 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 MLEs of \(r\) and \(\mu\) are \(\hat{r} = \frac{\bar{x}_2}{\bar{x}_1}\) and \(\hat{\mu} = \bar{x}_1\). The MLE of \(\theta\) is found by maximizing the profile log-likelihood \(l(\hat{r}, \hat{\mu}, \theta)\) with respect to \(\theta\). When \(r = r_{null}\) is known, the MLE of \(\mu\) is \(\tilde{\mu} = \frac{\bar{x}_1 + \bar{x}_2}{1 + r_{null}}\) and \(\tilde{\theta}\) is obtained by maximizing the profile log-likelihood \(l(r_{null}, \tilde{\mu}, \theta)\) with respect to \(\theta\).
The backend method for numerical optimization is controlled by argument
method which refers to stats::nlm(), stats::nlminb(), or
stats::optim(). If you would like to see warnings from the optimizer,
include argument warnings = TRUE.
References
Rettiganti M, Nagaraja HN (2012). “Power Analyses for Negative Binomial Models with Application to Multiple Sclerosis Clinical Trials.” Journal of Biopharmaceutical Statistics, 22(2), 237–259. ISSN 1054-3406, 1520-5711, doi:10.1080/10543406.2010.528105 .
Aban IB, Cutter GR, Mavinga N (2009). “Inferences and power analysis concerning two negative binomial distributions with an application to MRI lesion counts data.” Computational Statistics & Data Analysis, 53(3), 820–833. ISSN 01679473, doi:10.1016/j.csda.2008.07.034 .
Examples
#----------------------------------------------------------------------------
# mle_bnb() examples
#----------------------------------------------------------------------------
library(depower)
set.seed(1234)
d <- sim_bnb(
n = 40,
mean1 = 10,
ratio = 1.2,
dispersion = 2
)
mle_alt <- d |>
mle_bnb_alt()
mle_null <- d |>
mle_bnb_null()
mle_alt
#> $mean1
#> [1] 9.650008
#>
#> $mean2
#> [1] 11.84999
#>
#> $ratio
#> [1] 1.227978
#>
#> $dispersion
#> [1] 1.532668
#>
#> $nll
#> [1] 241.691
#>
#> $nparams
#> [1] 3
#>
#> $n1
#> [1] 40
#>
#> $n2
#> [1] 40
#>
#> $method
#> [1] "Alternative hypothesis MLEs for bivariate negative binomial data"
#>
#> $mle_method
#> [1] "nlm_constrained"
#>
#> $mle_code
#> [1] 0
#>
#> $mle_message
#> [1] "relative convergence (4)"
#>
mle_null
#> $mean1
#> [1] 10.75
#>
#> $mean2
#> [1] 10.75
#>
#> $ratio_null
#> [1] 1
#>
#> $dispersion
#> [1] 1.532671
#>
#> $n1
#> [1] 40
#>
#> $n2
#> [1] 40
#>
#> $nll
#> [1] 246.2012
#>
#> $nparams
#> [1] 2
#>
#> $method
#> [1] "Null hypothesis MLEs for bivariate negative binomial data"
#>
#> $mle_method
#> [1] "nlm_constrained"
#>
#> $mle_code
#> [1] 0
#>
#> $mle_message
#> [1] "relative convergence (4)"
#>