MLE for NB
mle_nb.RdMaximum likelihood estimates (MLE) for two independent negative binomial outcomes.
Usage
mle_nb_null(
data,
equal_dispersion = FALSE,
ratio_null = 1,
method = "nlm_constrained",
...
)
mle_nb_alt(data, equal_dispersion = FALSE, method = "nlm_constrained", ...)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 fromsim_nb().- equal_dispersion
(Scalar logical:
FALSE)
IfTRUE, the MLEs are calculated assuming both groups have the same population dispersion parameter. IfFALSE(default), the MLEs are calculated assuming different dispersions.- ratio_null
(Scalar numeric:
1;(0, Inf))
The ratio of means assumed under the null hypothesis (group 2 / group 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_nb_alt(), a list with the following elements:Slot Name Description 1 mean1MLE for mean of group 1. 2 mean2MLE for mean of group 2. 3 ratioMLE for ratio of means. 4 dispersion1MLE for dispersion of group 1. 5 dispersion2MLE for dispersion of group 2. 6 equal_dispersionWere equal dispersions assumed. 7 n1Sample size of group 1. 8 n2Sample size of group 2. 9 nllMinimum of negative log-likelihood. 10 nparamsNumber of estimated parameters. 11 methodMethod used for the results. 12 mle_methodMethod used for optimization. 13 mle_codeInteger indicating why the optimization process terminated. 14 mle_messageAdditional information from the optimizer. For
mle_nb_null(), a list with the following elements:Slot Name Description 1 mean1MLE for mean of group 1. 2 mean2MLE for mean of group 2. 3 ratio_nullPopulation ratio of means assumed for null hypothesis. mean2 = mean1 * ratio_null.4 dispersion1MLE for dispersion of group 1. 5 dispersion2MLE for dispersion of group 2. 6 equal_dispersionWere equal dispersions assumed. 7 n1Sample size of group 1. 8 n2Sample size of group 2. 9 nllMinimum of negative log-likelihood. 10 nparamsNumber of estimated parameters. 11 methodMethod used for the results. 12 mle_methodMethod used for optimization. 13 mle_codeInteger indicating why the optimization process terminated. 14 mle_messageAdditional information from the optimizer.
Details
These functions are primarily designed for speed in simulation. Missing values are silently excluded.
Suppose \(X_1 \sim \text{NB}(\mu, \theta_1)\) and \(X_2 \sim \text{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 MLEs of \(r\) and \(\mu\) are \(\hat{r} = \frac{\bar{x}_2}{\bar{x}_1}\) and \(\hat{\mu} = \bar{x}_1\). The MLEs of \(\theta_1\) and \(\theta_2\) are found by maximizing the profile log-likelihood \(l(\hat{r}, \hat{\mu}, \theta_1, \theta_2)\) with respect to \(\theta_1\) and \(\theta_2\). When \(r = r_{null}\) is known, the MLE of \(\mu\) is \(\tilde{\mu} = \frac{n_1 \bar{x}_1 + n_2 \bar{x}_2}{n_1 + n_2}\) and \(\tilde{\theta}_1\) and \(\tilde{\theta}_2\) are obtained by maximizing the profile log-likelihood \(l(r_{null}, \tilde{\mu}, \theta_1, \theta_2)\).
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_nb() examples
#----------------------------------------------------------------------------
library(depower)
d <- sim_nb(
n1 = 60,
n2 = 40,
mean1 = 10,
ratio = 1.5,
dispersion1 = 2,
dispersion2 = 8
)
mle_alt <- d |>
mle_nb_alt()
mle_null <- d |>
mle_nb_null()
mle_alt
#> $mean1
#> [1] 10.4
#>
#> $mean2
#> [1] 15.6
#>
#> $ratio
#> [1] 1.5
#>
#> $dispersion1
#> [1] 2.096105
#>
#> $dispersion2
#> [1] 5.692378
#>
#> $equal_dispersion
#> [1] FALSE
#>
#> $n1
#> [1] 60
#>
#> $n2
#> [1] 40
#>
#> $nll
#> [1] 333.6223
#>
#> $nparams
#> [1] 4
#>
#> $method
#> [1] "Alternative hypothesis MLEs for independent negative binomial data"
#>
#> $mle_method
#> [1] "nlm_constrained"
#>
#> $mle_code
#> [1] 0
#>
#> $mle_message
#> [1] "relative convergence (4)"
#>
mle_null
#> $mean1
#> [1] 13.55451
#>
#> $mean2
#> [1] 13.55451
#>
#> $ratio_null
#> [1] 1
#>
#> $dispersion1
#> [1] 1.821658
#>
#> $dispersion2
#> [1] 5.117131
#>
#> $equal_dispersion
#> [1] FALSE
#>
#> $n1
#> [1] 60
#>
#> $n2
#> [1] 40
#>
#> $nll
#> [1] 338.4952
#>
#> $nparams
#> [1] 3
#>
#> $method
#> [1] "Null hypothesis MLEs for independent negative binomial data"
#>
#> $mle_method
#> [1] "nlm_constrained"
#>
#> $mle_code
#> [1] 0
#>
#> $mle_message
#> [1] "relative convergence (4)"
#>