Title: | Chain Binomial Models for Analysis of Infectious Disease Data |
---|---|
Description: | Implements the chain binomial model for analysis of infectious disease data. Contains functions for calculating probabilities of the final size of infectious disease outbreaks using the method from D. Ludwig (1975) <doi:10.1016/0025-5564(75)90119-4> and for outbreaks that are not concluded, from Lindstrøm et al. (2024) <doi:10.48550/arXiv.2403.03948>. The package also contains methods for estimation and regression analysis of secondary attack rates. |
Authors: | Jonas Christoffer Lindstrøm [aut, cre] |
Maintainer: | Jonas Christoffer Lindstrøm <[email protected]> |
License: | GPL-3 |
Version: | 0.1.8 |
Built: | 2024-11-13 05:59:50 UTC |
Source: | https://github.com/opisthokonta/chainbinomial |
Fitting models for Secondary Attack Rate with Chain Binomial response
cbmod( y, s0, x = NULL, i0 = 1, generations = Inf, link = "identity", optim_method = "BFGS" )
cbmod( y, s0, x = NULL, i0 = 1, generations = Inf, link = "identity", optim_method = "BFGS" )
y |
numeric, the number of infected cases. |
s0 |
numeric, the number of initial susceptibles. |
x |
matrix of predictors (design matrix). |
i0 |
numeric, number of initial infected. Default is 1. |
generations |
numeric. |
link |
Link function. Default is 'identity'. |
optim_method |
Optimization method used by optim. |
The following link functions are available: identity
, log
, logit
, and cloglog
.
A list of class cbmod
with the following components:
parameters
The point estimate of the regression coefficients.
se
Standard error of the regression coefficient estimates.
vcov
Variance-Covariance matrix of the regression coefficient estimates.
p_values
P-values of the null hypothesis that the regression regression coefficient estimate is 0.
loglikelihood
the log likelihood value at the point estimate.
npar
Number of parameters.
sar_hat
Vector of fitted secondary attack rates.
fitted_values
Vector of expected outbreak size (final attack rate).
link
Link function used by the regression model.
null_model
= Null model, fitted with estimate_sar()
. This is equivalent to an intercept only model.
warnings
Warning_messages,
est_time
: Time used to fit the model.
omitted_values
Vector indicating data points that were ignored during estimation because of missing values.
Methods for cbmod
objects:
set.seed(234) mydata <- data.frame(infected = rchainbinom(n = 15, s0 = 5, sar = 0.2, i0 = 1, generations = Inf), s0 = 5, i0 = 1, generations = Inf) xmat <- model.matrix(~ 1, data = mydata) res <- cbmod(y = mydata$infected, s0 = mydata$s0, x = xmat, i0 = mydata$i0, generations = mydata$generations) summary(res)
set.seed(234) mydata <- data.frame(infected = rchainbinom(n = 15, s0 = 5, sar = 0.2, i0 = 1, generations = Inf), s0 = 5, i0 = 1, generations = Inf) xmat <- model.matrix(~ 1, data = mydata) res <- cbmod(y = mydata$infected, s0 = mydata$s0, x = xmat, i0 = mydata$i0, generations = mydata$generations) summary(res)
Extract Model Coefficient for cbmod Fits
## S3 method for class 'cbmod' coef(object, ...)
## S3 method for class 'cbmod' coef(object, ...)
object |
a cbmod object. |
... |
other arguments. Ignored. |
Coefficients extracted from the cbmod object.
Confidence intervals for cbmod Object.
## S3 method for class 'cbmod' confint(object, parm = NULL, level = 0.95, ...)
## S3 method for class 'cbmod' confint(object, parm = NULL, level = 0.95, ...)
object |
a cbmod object. |
parm |
Character or number of which coefficient ot compute confidence intervals for. By default intervals are computed for all coefficients. |
level |
Default is 0.95, for 95% confidence intervals. |
... |
other arguments. Ignored. |
A two-column matrix with the lower and upper end of the confidence intervals.
Confidence intervals for sar Object.
## S3 method for class 'sar' confint(object, parm = NULL, level = 0.95, method = "chisq", ...)
## S3 method for class 'sar' confint(object, parm = NULL, level = 0.95, method = "chisq", ...)
object |
a sar object. |
parm |
Ignored. |
level |
Default is 0.95, for 95% confidence intervals. |
method |
Either 'chisq'(default) or 'normal'. |
... |
other arguments. Ignored. |
A numeric of length 2 with the lower and upper end of the confidence interval.
Confidence intervals for sar2 Object.
## S3 method for class 'sar2' confint(object, parm = NULL, level = 0.95, method = "chisq", ...)
## S3 method for class 'sar2' confint(object, parm = NULL, level = 0.95, method = "chisq", ...)
object |
a sar2 object. |
parm |
Ignored. |
level |
Default is 0.95, for 95% confidence intervals. |
method |
Either 'chisq'(default) or 'normal'. |
... |
other arguments. Ignored. |
A numeric of length 2 with the lower and upper end of the confidence interval.
Probability mass function, expected value, and random generation, for the hyper chain binomial distribution, with parameters s0, sar, i0, and s0_obs for the number of observed infected cases in a population of size s0 with s0_obs observed individuals.
dcbhyper(x, s0, sar, s0_obs, i0 = 1) ecbhyper(s0, sar, s0_obs, i0 = 1)
dcbhyper(x, s0, sar, s0_obs, i0 = 1) ecbhyper(s0, sar, s0_obs, i0 = 1)
x |
numeric vector of the number of infected. |
s0 |
the number of initial susceptibles. |
sar |
the secondary attack rate, or the per person risk of infection by an infected. |
s0_obs |
The number of observed individuals. |
i0 |
the number of primary cases. |
Probability mass function, cumulative, expected value, variance function, and random generation, for the chain binomial distribution, with parameters s0, sar, i0, and number of generations, for the number of infected cases in a population of size s0 after a given number of generations.
dchainbinom(x, s0, sar, i0 = 1, generations = Inf) rchainbinom(n, s0, sar, i0 = 1, generations = Inf) pchainbinom(q, s0, sar, i0 = 1, generations = Inf) echainbinom(s0, sar, i0 = 1, generations = Inf) varchainbinom(s0, sar, i0 = 1, generations = Inf)
dchainbinom(x, s0, sar, i0 = 1, generations = Inf) rchainbinom(n, s0, sar, i0 = 1, generations = Inf) pchainbinom(q, s0, sar, i0 = 1, generations = Inf) echainbinom(s0, sar, i0 = 1, generations = Inf) varchainbinom(s0, sar, i0 = 1, generations = Inf)
x |
numeric vector of the number of infected. |
s0 |
the number of initial susceptibles. |
sar |
the secondary attack rate, or the per person risk of infection by an infected. |
i0 |
the number of primary cases. |
generations |
the number of generations. Default is Inf, which represents the entire epidemic. |
n |
number of observations. If length(n) > 1, the length is taken to be the number required. |
q |
numeric vector of the number of infected. |
dchainbinom
gives the probability of x infected, given s0, i0, sar and generations. echainbinom
gives the expected value.
rchainbinom
generates random data.
dchainbinom(x = 0:5, s0 = 5, sar = 0.2, i0 = 1, generations = Inf) rchainbinom(n = 10, s0 = 5, sar = 0.2, i0 = 1, generations = Inf) echainbinom(s0 = 5, sar = 0.2, i0 = 1, generations = Inf) varchainbinom(s0 = 5, sar = 0.2, i0 = 1, generations = Inf)
dchainbinom(x = 0:5, s0 = 5, sar = 0.2, i0 = 1, generations = Inf) rchainbinom(n = 10, s0 = 5, sar = 0.2, i0 = 1, generations = Inf) echainbinom(s0 = 5, sar = 0.2, i0 = 1, generations = Inf) varchainbinom(s0 = 5, sar = 0.2, i0 = 1, generations = Inf)
Given data on the number of infected after a number of generation, initial number of susceptible, and initial number of infected, estimate the secondary attack rate (SAR) using maximum likelihood.
estimate_sar(infected, s0, i0 = 1, generations = Inf, se = TRUE)
estimate_sar(infected, s0, i0 = 1, generations = Inf, se = TRUE)
infected |
numeric. |
s0 |
numeric. |
i0 |
numeric. |
generations |
numeric. |
se |
logical. If TRUE (default), the standard error is computed. |
A list of class sar
with the following components:
sar_hat
The point estimate of the secondary attack rate.
se
Standard error of the estimate (if se = TRUE).
loglikelihood
The log likelihood value at the point estimate.
data
The input data.
confint.sar()
for calculating confidence intervals.
set.seed(234) mydata <- rchainbinom(n = 15, s0 = 5, sar = 0.2, i0 = 1, generations = Inf) res <- estimate_sar(infected = mydata, s0 = 5, i0 = 1, generations = Inf)
set.seed(234) mydata <- rchainbinom(n = 15, s0 = 5, sar = 0.2, i0 = 1, generations = Inf) res <- estimate_sar(infected = mydata, s0 = 5, i0 = 1, generations = Inf)
Given data on the number of infected after a number of generation, initial number of susceptible, and initial number of infected, estimate the secondary attack rate (SAR) using maximum likelihood.
estimate_sar_cbhyper(infected, s0, s0_obs, i0 = 1, se = TRUE)
estimate_sar_cbhyper(infected, s0, s0_obs, i0 = 1, se = TRUE)
infected |
numeric. |
s0 |
numeric. |
s0_obs |
numeric. |
i0 |
numeric. |
se |
logical. If TRUE (default), the standard error is computed. |
A list of class sar2
with the following components:
sar_hat
The point estimate of the secondary attack rate.
se
Standard error of the estimate (if se = TRUE).
loglikelihood
the log likelihood value at the point estimate.
data
the input data.
confint.sar2()
for calculating confidence intervals.
Glance at a cbmod object
## S3 method for class 'cbmod' glance(x, ...)
## S3 method for class 'cbmod' glance(x, ...)
x |
A |
... |
Unused. |
Returns a tibble with the following columns:
logLik
The model's log-likelihood.
npar
Numnber of parameters in the model.
Data presented in Heasman & Reid (1961), originally gathered and analyzed by Brimblecombe et al (1958). The data set describes 664 outbreaks of the common cold in 72 families over two years. All families consists of two parents and three children. The data is available in aggregated form as presented in the paper, with counts of the number of outbreaks that belong to a given classification.
heasman_reid_1961_chains heasman_reid_1961_crowding heasman_reid_1961_intro_case_status heasman_reid_1961_intro_case_status heasman_reid_1961_crowding
heasman_reid_1961_chains heasman_reid_1961_crowding heasman_reid_1961_intro_case_status heasman_reid_1961_intro_case_status heasman_reid_1961_crowding
An object of class data.frame
with 24 rows and 2 columns.
An object of class data.frame
with 5 rows and 5 columns.
An object of class data.frame
with 5 rows and 4 columns.
Each outbreak was classified to a specific chain suitable for analysis by the Chain Binomial model by Heasman & Reid (1961), Table V.
heasman_reid_1961_chains
: A data frame with 24 rows and 2 columns:
the number of infected in each generation, separated by '-', ie the Chain.
Number of outbreaks
Each outbreak classified according to the degree of domestic overcrowding. Heasman & Reid (1961), Table IV. Overcrowded homes have either one or two rooms, crowded homes have three rooms, while uncrowded homes have more than three rooms.
heasman_reid_1961_crowding
: A data frame with 5 rows and 4 columns:
The number of cases in the outbreak, in addition to the primary case.
Number of outbreaks that belong to the overcrowded household category.
Number of outbreaks that belong to the crowded household category.
Number of outbreaks that belong to the uncrowded household category.
Each outbreak classified according to who the the introducing case was. Heasman & Reid (1961), Table II.
heasman_reid_1961_intro_case_status
: A data frame with 5 rows and 5 columns:
The number of cases in the outbreak, in addition to the primary case.
Number of outbreaks with father as the index case.
Number of outbreaks with mother as the index case.
Number of outbreaks with a school child as the index case.
Number of outbreaks with a pre-school child as the index case.
Heasman & Reid (1961) Theory And Observation In Family Epidemics Of The Common Cold. Brit. J. prev. soc. Med.
Brimblecombe et al (1958) Family Studies Of Respiratory Infections. British Medical Journal.
Predict Method for cbmod Fits
## S3 method for class 'cbmod' predict(object, x, type = "link", ...)
## S3 method for class 'cbmod' predict(object, x, type = "link", ...)
object |
a fitted object of class inheriting from "cbmod". |
x |
matrix of predictors (design matrix). Must have the same column names and order as the x matrix used to fit the model. |
type |
the type of prediction, either 'link' (default) or 'sar'. The default is on the scale of the linear predictors. 'sar' gives the predicted secondary attack rate, by transforming the linear predictors by the inverse link function used in the model fit. |
... |
additional arguments. |
a vector of predictions.
set.seed(234) mydata <- data.frame(infected = rchainbinom(n = 15, s0 = 5, sar = 0.2, i0 = 1, generations = Inf), s0 = 5, i0 = 1, generations = Inf) xmat <- model.matrix(~ 1, data = mydata) res <- cbmod(y = mydata$infected, s0 = mydata$s0, x = xmat, i0 = mydata$i0, generations = mydata$generations, link = 'identity') summary(res) predict(res, x = xmat, type = 'sar')
set.seed(234) mydata <- data.frame(infected = rchainbinom(n = 15, s0 = 5, sar = 0.2, i0 = 1, generations = Inf), s0 = 5, i0 = 1, generations = Inf) xmat <- model.matrix(~ 1, data = mydata) res <- cbmod(y = mydata$infected, s0 = mydata$s0, x = xmat, i0 = mydata$i0, generations = mydata$generations, link = 'identity') summary(res) predict(res, x = xmat, type = 'sar')
Extract Model Residuals for cbmod Fits
## S3 method for class 'cbmod' residuals(object, type = "response", ...)
## S3 method for class 'cbmod' residuals(object, type = "response", ...)
object |
a fitted object of class inheriting from "cbmod". |
type |
he type of residuals which should be returned. The alternatives are: "response" (default), "far", and "pearson". |
... |
additional arguments. |
a vector of residuals.
Summary of cbmod Object.
## S3 method for class 'cbmod' summary(object, ...)
## S3 method for class 'cbmod' summary(object, ...)
object |
a cbmod object. |
... |
other arguments. Ignored. |
Returns nothing, but displays a summary of the model fit.
Tidy a cbmod object
## S3 method for class 'cbmod' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
## S3 method for class 'cbmod' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
x |
A |
conf.int |
Logical indicating whether or not to include a confidence interval in the tidied output. Defaults to FALSE. |
conf.level |
The confidence level to use for the confidence interval if conf.int = TRUE. Defaults to 0.95, which corresponds to a 95 percent confidence interval. |
... |
Unused. |
Returns a tibble with the following columns:
term
The coefficients name.
estimate
The point estimates of the coefficients.
std.error
Standard error of the regression coefficient estimates.
p.value
P-values of the null hypothesis that the regression regression coefficient estimate is 0.
conf.low
If conf.int = TRUE
, the lower end of the confidence interval.
conf.high
If conf.int = TRUE
, the upper end of the confidence interval.
Variance-Covariance Matrix of cbmod Object.
## S3 method for class 'cbmod' vcov(object, ...)
## S3 method for class 'cbmod' vcov(object, ...)
object |
a cbmod object. |
... |
other arguments. Ignored. |
A variance-covariance matrix.