glm_nb | R Documentation |
Generalized linear model for two independent negative binomial outcomes.
glm_nb(data, equal_dispersion = FALSE, test = "wald", ci_level = NULL, ...)
data |
(list) |
equal_dispersion |
(Scalar logical: |
test |
(String: |
ci_level |
(Scalar numeric: |
... |
Optional arguments passed to |
Uses glmmTMB::glmmTMB()
in the form
glmmTMB( formula = value ~ condition, data = data, dispformula = ~ condition, family = nbinom2 )
to model independent negative binomial outcomes
X_1 \sim \text{NB}(\mu, \theta_1)
and X_2 \sim \text{NB}(r\mu, \theta_2)
where \mu
is the mean of group 1, r
is the ratio of the means of
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 and Wald test of r
are
\begin{aligned}
H_{null} &: log(r) = 0 \\
H_{alt} &: log(r) \neq 0
\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
log(r_{null}) = 0
assumes the population means are identical.
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 group 1. | |
5 | 1 | estimate | Point estimate. |
5 | 2 | lower | Confidence interval lower bound. |
5 | 3 | upper | Confidence interval upper bound. |
6 | mean2 | Estimated mean of group 2. | |
6 | 1 | estimate | Point estimate. |
6 | 2 | lower | Confidence interval lower bound. |
6 | 3 | upper | Confidence interval upper bound. |
7 | dispersion1 | Estimated dispersion of group 1. | |
7 | 1 | estimate | Point estimate. |
7 | 2 | lower | Confidence interval lower bound. |
7 | 3 | upper | Confidence interval upper bound. |
8 | dispersion2 | Estimated dispersion of group 2. | |
8 | 1 | estimate | Point estimate. |
8 | 2 | lower | Confidence interval lower bound. |
8 | 3 | upper | Confidence interval upper bound. |
9 | n1 | Sample size of group 1. | |
10 | n2 | Sample size of group 2. | |
11 | method | Method used for the results. | |
12 | test | Type of hypothesis test. | |
13 | alternative | The alternative hypothesis. | |
14 | equal_dispersion | Whether or not equal dispersions were assumed. | |
15 | ci_level | Confidence level of the intervals. | |
16 | hessian | Information about the Hessian matrix. | |
17 | convergence | Information about convergence. |
hilbe_2011depower
\insertRefhilbe_2014depower
glmmTMB::glmmTMB()
#----------------------------------------------------------------------------
# glm_nb() examples
#----------------------------------------------------------------------------
library(depower)
set.seed(1234)
d <- sim_nb(
n1 = 60,
n2 = 40,
mean1 = 10,
ratio = 1.5,
dispersion1 = 2,
dispersion2 = 8
)
lrt <- glm_nb(d, equal_dispersion = FALSE, test = "lrt", ci_level = 0.95)
lrt
wald <- glm_nb(d, equal_dispersion = FALSE, test = "wald", ci_level = 0.95)
wald
#----------------------------------------------------------------------------
# Compare results to manual calculation of chi-square statistic
#----------------------------------------------------------------------------
# Use the same data, but as a data frame instead of list
set.seed(1234)
d <- sim_nb(
n1 = 60,
n2 = 40,
mean1 = 10,
ratio = 1.5,
dispersion1 = 2,
dispersion2 = 8,
return_type = "data.frame"
)
mod_alt <- glmmTMB::glmmTMB(
formula = value ~ condition,
data = d,
dispformula = ~ condition,
family = glmmTMB::nbinom2,
)
mod_null <- glmmTMB::glmmTMB(
formula = value ~ 1,
data = d,
dispformula = ~ condition,
family = glmmTMB::nbinom2,
)
lrt_chisq <- as.numeric(-2 * (logLik(mod_null) - logLik(mod_alt)))
lrt_chisq
wald_chisq <- summary(mod_alt)$coefficients$cond["condition2", "z value"]^2
wald_chisq
anova(mod_null, mod_alt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.