Title: | Prevalence to Incidence Calculations for Point-Prevalence Studies in a Nosocomial Setting |
---|---|
Description: | Functions to simulate point prevalence studies (PPSs) of healthcare-associated infections (HAIs) and to convert prevalence to incidence in steady state setups. Companion package to the preprint Willrich et al., From prevalence to incidence - a new approach in the hospital setting; <doi:10.1101/554725> , where methods are explained in detail. |
Authors: | Niklas Willrich [aut, cre] |
Maintainer: | Niklas Willrich <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.12.0 |
Built: | 2024-11-29 09:00:11 UTC |
Source: | CRAN |
function to transform the distribution of stays to a fixed point to the distribution of the staying times
A_to_X_dist(dist.point)
A_to_X_dist(dist.point)
dist.point |
vector of probabilities of staying 1:length(dist.point) days |
vector of probabilities of being at the hospital for 1:length(dist.point) days at random time of observation
# generate vector of probabilities for truncated Poisson distribution for # distribution of times of stay X dist.X <- dpois(1:70, 4) plot(dist.X) # transform to distribution of distribution of staying-time up to observation point under # assumption of steady state dist.A <- X_to_A_dist(dist.X) plot(dist.A) # transform back to get original distribution dist.X.2 <- A_to_X_dist(dist.A) plot(dist.X.2)
# generate vector of probabilities for truncated Poisson distribution for # distribution of times of stay X dist.X <- dpois(1:70, 4) plot(dist.X) # transform to distribution of distribution of staying-time up to observation point under # assumption of steady state dist.A <- X_to_A_dist(dist.X) plot(dist.A) # transform back to get original distribution dist.X.2 <- A_to_X_dist(dist.A) plot(dist.X.2)
Asymptotic or bootstrap approximation of confidence intervals for estimates of Ipp with gren method Can use output of calculate_I_* functions as input. The asymptotic method uses the asymptotic normality of the estimator of I.pp to calculate the confidence interval and the method "bs" uses a parametric bootstrap approximation based on the "naive" estimator.
calculate_CI_I_pp(data, method = "asymptotic", alpha = 0.05, n_bs = 10000)
calculate_CI_I_pp(data, method = "asymptotic", alpha = 0.05, n_bs = 10000)
data |
data frame which contains at least the following columns
|
method |
either "asymptotic" for asymptotic confidence interval or "bs" for bootstrap-based confidence interval |
alpha |
confidence level |
n_bs |
number of bootstrap replications if method is "bs" |
tibble with columns CI.lower.Ipp and CI.upper.Ipp
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=5000, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) gren_est <- calculate_I_smooth(data = data.pps.fast, method = "gren") gren_est calculate_CI_I_pp(gren_est, method = "asymptotic", alpha = 0.05)
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=5000, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) gren_est <- calculate_I_smooth(data = data.pps.fast, method = "gren") gren_est calculate_CI_I_pp(gren_est, method = "asymptotic", alpha = 0.05)
Function to calculate different estimators for I from PPS data.
calculate_I(data, data.theo = NULL)
calculate_I(data, data.theo = NULL)
data |
data frame as generated by 'simulate_pps_data' or 'simulate_pps_fast' |
data.theo |
data frame as generated by 'simulate_incidence_stats' or 'simulate incidence_stats_fast“ |
data frame with following columns
n - number of patients sampled
n.noso - number of HAIs
P.hat - estimate of prevalence P
I.hat - estimate of incidence rate I
I.pp.hat - estimate of incidence proportion per admission I.pp
x.loi.hat - estimate of x.loi
x.los.hat - estimate of x.los
method - name of the method
and rows for the estimators gren, rear, pps.median, pps.mean, pps.mixed, rhame.theo, L.full (for a description of the estimators see vignette).
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate incidence based on Rhame-Sudderth formula calculate_I(data = data.pps.fast)
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate incidence based on Rhame-Sudderth formula calculate_I(data = data.pps.fast)
A sigmoid function with parameters a and b (see below) is used to get weights for a combination of the two estimator for x.loi and x.los.
calculate_I_mixed(I.pps.1, I.pps.2, a = 0.01, b = 500, method = "pps.mixed")
calculate_I_mixed(I.pps.1, I.pps.2, a = 0.01, b = 500, method = "pps.mixed")
I.pps.1 |
resulting data frame for first estimator |
I.pps.2 |
resulting data frame for second estimator |
a |
parameter a for the sigmoid function |
b |
parameter b for the sigmoid function |
method |
name of the method |
is achieved in the following way for estimation of x.loi alpha = exp(a*(n.noso-b))/(1+exp(a*(n.noso-b))) x.loi.hat.mixed = alpha*x.loi.hat.1 + (1-alpha)*x.loi.hat.2
alpha = exp(a*(n-b))/(1+exp(a*(n-b))) x.los.hat.mixed = alpha*x.los.hat.1 + (1-alpha)*x.los.hat.2
one-row data frame with following columns
n - number of patients sampled
n.noso - number of HAIs
P.hat - estimate of prevalence P
I.hat - estimate of incidence rate I
I.pp.hat - estimate of incidence proportion per admission I.pp
x.loi.hat - estimate of x.loi
x.los.hat - estimate of x.los
method - name of the method
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate of incidence I.1 <- calculate_I_smooth(data = data.pps.fast, method = "gren") # estimate incidence based on Rhame-Sudderth formula I.2 <- calculate_I_rhame(data = data.pps.fast, x.loi.hat = 8, x.los.hat = 13) # mixed estimator calculate_I_mixed(I.1, I.2)
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate of incidence I.1 <- calculate_I_smooth(data = data.pps.fast, method = "gren") # estimate incidence based on Rhame-Sudderth formula I.2 <- calculate_I_rhame(data = data.pps.fast, x.loi.hat = 8, x.los.hat = 13) # mixed estimator calculate_I_mixed(I.1, I.2)
Function to calculate incidence from PPS data using a Rhame-Sudderth like approach with estimates for x.loi and x.los supplied.
calculate_I_rhame(data, x.loi.hat, x.los.hat = NA, method = "rhame")
calculate_I_rhame(data, x.loi.hat, x.los.hat = NA, method = "rhame")
data |
one-row data frame which contains a column A.loi (only used to calculate P.hat) with lengths of nosocomial infections up to survey (a 0 indicates no HAI present) |
x.loi.hat |
value for estimated expected length of infection x_loi |
x.los.hat |
value for estimated expected length of stay x_los (optional) |
method |
a string with associated name for method |
one-row data frame with following columns
n - number of patients sampled
n.noso - number of HAIs
P.hat - estimate of prevalence P
I.hat - estimate of incidence rate I
I.pp.hat - estimate of incidence proportion per admission I.pp
x.loi.hat - estimate of x.loi
x.los.hat - estimate of x.los
method - name of the method
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate incidence based on Rhame-Sudderth formula calculate_I_rhame(data = data.pps.fast, x.loi.hat = 8, x.los.hat = 13)
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate incidence based on Rhame-Sudderth formula calculate_I_rhame(data = data.pps.fast, x.loi.hat = 8, x.los.hat = 13)
Estimate incidence from PPS by the method proposed in the companion paper. 'data' should be supplied as a data frame with at least a column named 'A.loi' giving lengths of infection up to date of PPS. Values of zero for 'A.loi' indicate absence of a HAI. Optionally, the data frame can also contain a column 'A.los' supplying lengths of stay up to PPS to estimate x.los with the same method as well. If 'correct.one' is 'TRUE', the number infections on their first day will be augmented to be at least as high as the number of infections on their second day for the estimation of x.loi .
calculate_I_smooth(data, method = "gren", correct.one.loi = "no", correct.one.los = "no")
calculate_I_smooth(data, method = "gren", correct.one.loi = "no", correct.one.los = "no")
data |
data frame which contains a column 'A.loi' with lengths of nosocomial infections up to survey point ( zero if none) and possibly a column 'A.los' with length of stay up to survey point |
method |
method to use for smoothing ("gren" ( Grenander ) or "rear" (rearrangement)) |
correct.one.loi |
use correction for underreporting of one day LOIs: "no" if none, "fill.ones" to set the one-day cases to be at least the number of two-day cases, "start.two" to only use P(A=2| A > 1) as a proxy for P(A=1) |
correct.one.los |
use correction for underreporting of one day LOSs: "no" if none, "fill.ones" to set the one-day cases to be at least the number of two-day cases, "start.two" to only use P(A=2| A > 1) as a proxy for P(A=1) |
one-row data frame with following columns
n - number of patients sampled
n.noso - number of HAIs
P.hat - estimate of prevalence P
I.hat - estimate of incidence rate I
I.pp.hat - estimate of incidence proportion per admission I.pp
x.loi.hat - estimate of x.loi
x.los.hat - estimate of x.los
method - name of the method
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate of incidence calculate_I_smooth(data = data.pps.fast, method = "gren")
# create example data for PPS example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=200, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) head(data.pps.fast) # estimate of incidence calculate_I_smooth(data = data.pps.fast, method = "gren")
Implements a bootstrap procedure for estimation of confidence intervals for I.pp based on boostrapping from the length of stay/infection distributions estimated by the gren method.
CI_np_bs(data, n_bs = 1000, alpha = 0.05)
CI_np_bs(data, n_bs = 1000, alpha = 0.05)
data |
data frame which contains a column 'A.loi' with lengths of nosocomial infections up to survey point ( zero if none) and a column 'A.los' with length of stay up to survey point |
n_bs |
number of bootstrap samples to use for calculations |
alpha |
confidence level |
single-row tibble with columns CI.lower.Ipp and CI.upper.Ipp
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=5000, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) gren_est <- calculate_I_smooth(data = data.pps.fast, method = "gren") gren_est CI_np_bs(data.pps.fast, n_bs = 500)
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) data.pps.fast <- simulate_pps_fast(n.sample=5000, P=0.05, dist.X.loi = example.dist, dist.X.los = example.dist.los) gren_est <- calculate_I_smooth(data = data.pps.fast, method = "gren") gren_est CI_np_bs(data.pps.fast, n_bs = 500)
Cuts-off the (possibly unbounded) probability distribution at 'max.dist' and normalizes the resulting vector of probability to sum up to 1.
create_dist_vec(dist, max.dist)
create_dist_vec(dist, max.dist)
dist |
probability mass function to use |
max.dist |
maximum value at which to cutoff distribution |
vector of probabilites for values 1:max.dist
geom_dist_fct(1:70) create_dist_vec(geom_dist_fct, max.dist = 70)
geom_dist_fct(1:70) create_dist_vec(geom_dist_fct, max.dist = 70)
Simulates the occupation of bed and incidence of HAIs of a single bed. Length of HAI is assumed to be additive to length of stay without HAI.
create_patient_history_add(X_los_dist, X_loi_dist, I, steps)
create_patient_history_add(X_los_dist, X_loi_dist, I, steps)
X_los_dist |
vector of probabilities for values 1:length(dist.X.los) of X.los |
X_loi_dist |
vector of probabilities for values 1:length(dist.X.loi) of X.loi |
I |
incidence rate per patient-day at risk |
steps |
number of days to evolve trajectory of bed |
data frame with following columns
pat_nbr - sequential patient number
hai_nbr - sequential HAI number
X_los - predicted total length of stay for patient on current day
X_los_wo_hai -
X_loi - total length of current HAI
X_loi_tot - added total lengths of all HAIs up to day
A_los - length of stay up to day
X_lnint - length of stay after acquiring first HAI
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) bed_hist <- create_patient_history_add(example.dist.los, example.dist, I = 0.08, 1000) tail(bed_hist)
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) example.dist.los <- create_dist_vec(function(x) dpois(x-1, lambda = 12), max.dist = 70) bed_hist <- create_patient_history_add(example.dist.los, example.dist, I = 0.08, 1000) tail(bed_hist)
Calculate empirical probability mass function for a discrete positive distribution starting at 1
epmf(values)
epmf(values)
values |
used for the calculation of the empirical pmf |
vector of probabilities for epmf for the range 1:length(values)
# generate random sample of independent draws from Poisson distribution x <- rpois(200,4) # calculate empirical probability mass function and true probability mass function y.emp <- epmf(x) y.theo <- dpois(1:max(x), 4) plot(y.emp) points(y.theo, col = "red")
# generate random sample of independent draws from Poisson distribution x <- rpois(200,4) # calculate empirical probability mass function and true probability mass function y.emp <- epmf(x) y.theo <- dpois(1:max(x), 4) plot(y.emp) points(y.theo, col = "red")
Function to simulate PPS and data and calculate a number of estimators
generate_I_fast(n.sample, P, dist.X.loi, data.theo = NULL, dist.X.los = NA, one.factor.loi = 1, one.factor.los = 1)
generate_I_fast(n.sample, P, dist.X.loi, data.theo = NULL, dist.X.los = NA, one.factor.loi = 1, one.factor.los = 1)
n.sample |
number of beds to simulate |
P |
average prevalence of nosocomial infections |
dist.X.loi |
vector of probabilities for values 1:length(dist.X.loi) of X.loi |
data.theo |
data frame with theoretical info generated by simulate_incidence_stats_* function |
dist.X.los |
vector of probabilities for values 1:length(dist.X.los) of X.los |
one.factor.loi |
factor by which to approx. reduce number of one day observations for A.loi |
one.factor.los |
factor by which to approx. reduce number of one day observations for A.los |
data frame with following columns
n - number of patients sampled
n.noso - number of HAIs
P.hat - estimate of prevalence P
I.hat - estimate of incidence rate I
I.pp.hat - estimate of incidence proportion per admission I.pp
x.loi.hat - estimate of x.loi
x.los.hat - estimate of x.los
method - name of the method
and rows for the estimators gren, rear, pps.median, pps.mean, pps.mixed, rhame.theo, L.full (for a description of the estimators see vignette).
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) generate_I_fast(200, P = 0.05, example.dist )
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), max.dist = 70) generate_I_fast(200, P = 0.05, example.dist )
Probability mass function for a geometric distribution shifted by one and resulting expected value 8
geom_dist_fct(x)
geom_dist_fct(x)
x |
vector of positive integer values to evaluate |
plot(geom_dist_fct(1:100))
plot(geom_dist_fct(1:100))
Calculate length-biased distribution from discrete length-unbiased distribution starting at 1
length_biased_dist(dist)
length_biased_dist(dist)
dist |
vector of probabilities of distribution to transform |
vector of probabilities of transformed distribution
# geometric distribution starting in 1 and cutoff at 70 with mean at about 8. geom.dist <- create_dist_vec(geom_dist_fct, max.dist = 70) # calculate mean sum(1:length(geom.dist)*geom.dist) # plot original distribution plot(geom.dist) geom.dist.lb <- length_biased_dist(geom.dist) # plot length biased distribution plot(geom.dist.lb)
# geometric distribution starting in 1 and cutoff at 70 with mean at about 8. geom.dist <- create_dist_vec(geom_dist_fct, max.dist = 70) # calculate mean sum(1:length(geom.dist)*geom.dist) # plot original distribution plot(geom.dist) geom.dist.lb <- length_biased_dist(geom.dist) # plot length biased distribution plot(geom.dist.lb)
Calculate mean of length-unbiased distribution from discrete length-biased distribution starting at 1
length_unbiased_mean(dist)
length_unbiased_mean(dist)
dist |
vector of probabilities of length-biased distribution |
mean of length-unbiased distribution
# geometric distribution starting in 1 and cutoff at 70 with mean at about 8. geom.dist <- create_dist_vec(geom_dist_fct, max.dist = 70) # calculate mean of distribution sum(1:length(geom.dist)*geom.dist) # create length-biased distribution in same format geom.dist.lb <- length_biased_dist(geom.dist) # recalculate mean of original distribution based on length-biased distribution length_unbiased_mean(geom.dist.lb)
# geometric distribution starting in 1 and cutoff at 70 with mean at about 8. geom.dist <- create_dist_vec(geom_dist_fct, max.dist = 70) # calculate mean of distribution sum(1:length(geom.dist)*geom.dist) # create length-biased distribution in same format geom.dist.lb <- length_biased_dist(geom.dist) # recalculate mean of original distribution based on length-biased distribution length_unbiased_mean(geom.dist.lb)
using a rearrangement or a Grenander estimator as described in Jankoswski, Wellner, 2009 <doi:10.1214/09-EJS526>
monotone_smoother(values, method = "rear", range = c(1, max(values)))
monotone_smoother(values, method = "rear", range = c(1, max(values)))
values |
observed values of distribution |
method |
method of estimation "rear" rearrangement or "gren" Grenander |
range |
boundaries of the support of the distribution |
vector of estimated pmf (support of distribution is by default assumed to be min(values):max(values) )
# generate sample from geometric distribution A <- rgeom(50, 0.2) # plot empirical probability mass function plot(epmf(A)) dist.A.gren <- monotone_smoother(A, method = "gren") # plot estimated probability mass function points(dist.A.gren, col = "red")
# generate sample from geometric distribution A <- rgeom(50, 0.2) # plot empirical probability mass function plot(epmf(A)) dist.A.gren <- monotone_smoother(A, method = "gren") # plot estimated probability mass function points(dist.A.gren, col = "red")
Probability mass function for a Poisson distribution shifted by one and resulting expected value 8
pois_dist_fct(x)
pois_dist_fct(x)
x |
vector of positive integer values to evaluate |
plot(pois_dist_fct(1:100))
plot(pois_dist_fct(1:100))
The prevtoinc package implements functionality to simulate point-prevalence studies (PPSs) for healtcare-associated infections (HAIs) and estimate incidence based on the PPS data. It is a companion package to the preprint Willrich et al., From prevalence to incidence - a new approach in the hospital setting; <doi:10.1101/554725> , where methods are explained in detail.
Calculate theoretical values like x.los, x.loi and other characteristics of the patient population
simulate_incidence_stats(hospital, steps = 365 * 10000, n.sim.pat = 5000)
simulate_incidence_stats(hospital, steps = 365 * 10000, n.sim.pat = 5000)
hospital |
type of hospital as a list-object (see vignette for details) |
steps |
number of steps to evolve process |
n.sim.pat |
size of simulations to estimate individual characteristics of patients |
list with following components
x.los - average length of stay x_los
x.loi - average length of infection x_loi
x.los.noso.only - average length of stay for patients with HAI
x.los.wo.noso - average length of stay for patients discounting time with HAI
I - theoretical incidence rate per patient day
I.pp - list of theoretical incidences for patient types
patient.stats - list with 'x.los' and 'x.loi' for different patient types
patient.risk.times - list of patient days at risk for different patient types
pat.1 <- list(dist.X.los = create_dist_vec( function(x) dpois(x-1, lambda = 12), 70), I.p = 0.008, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70)) pat.2 <- list(dist.X.los = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70), I.p = 0.02, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 7), 70)) patient.list <- list(pat.1, pat.2) # define distribution of patients pat.1.prob <- 0.4; pat.2.prob <- 0.6 pat.dist.hosp <- c(pat.1.prob, pat.2.prob) hospital.1 <- list(inc.factor = 1, pat.dist = pat.dist.hosp, patient.list = patient.list) data.pps <- simulate_pps_data(n.sample=1000, steps=200, hospital=hospital.1) data.inc.theo <- simulate_incidence_stats(hospital.1, 365 * 1000) # gives incidence rate I data.inc.theo$I # gives incidence proportion per admission data.inc.theo$I.pp
pat.1 <- list(dist.X.los = create_dist_vec( function(x) dpois(x-1, lambda = 12), 70), I.p = 0.008, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70)) pat.2 <- list(dist.X.los = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70), I.p = 0.02, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 7), 70)) patient.list <- list(pat.1, pat.2) # define distribution of patients pat.1.prob <- 0.4; pat.2.prob <- 0.6 pat.dist.hosp <- c(pat.1.prob, pat.2.prob) hospital.1 <- list(inc.factor = 1, pat.dist = pat.dist.hosp, patient.list = patient.list) data.pps <- simulate_pps_data(n.sample=1000, steps=200, hospital=hospital.1) data.inc.theo <- simulate_incidence_stats(hospital.1, 365 * 1000) # gives incidence rate I data.inc.theo$I # gives incidence proportion per admission data.inc.theo$I.pp
Function to calculate theoretical value for x.loi and I
simulate_incidence_stats_fast(P, dist.X.loi, dist.X.los = NA)
simulate_incidence_stats_fast(P, dist.X.loi, dist.X.los = NA)
P |
prevalence of HAIs |
dist.X.loi |
probability mass function of distribution of lengths of infection |
dist.X.los |
vector of probabilities for values 1:length(dist.X.los) of X.los |
list with following components
x.loi - average length of infection
x.los - average length of stay
I - theoretical incidence rate per patient day
I.pp - theoretical incidence proportion per admission
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), 70) data.fast.inc.theo <- simulate_incidence_stats_fast(P=0.05, dist.X.loi = example.dist) data.fast.inc.theo$x.loi data.fast.inc.theo$I
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), 70) data.fast.inc.theo <- simulate_incidence_stats_fast(P=0.05, dist.X.loi = example.dist) data.fast.inc.theo$x.loi data.fast.inc.theo$I
Simulates PPS data for a prespecified hospital according to a steady state model of incidence ( see vignette "Overview of prevtoinc-Package" for details.)
simulate_pps_data(n.sample, steps, hospital)
simulate_pps_data(n.sample, steps, hospital)
n.sample |
number of beds to simulate |
steps |
number of steps to evolve the process |
hospital |
type of hospital as a list-object (see vignette for details) |
data frame with following columns
A.loi - length of infection up to PPS
L.loi - total length of infection
A.los - length of stay up to PPS
L.los - total length of stay
patient.type - patient type
pat.1 <- list(dist.X.los = create_dist_vec(function(x) dpois(x-1, lambda = 12), 70), I.p = 0.008, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70)) pat.2 <- list(dist.X.los = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70), I.p = 0.02, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 7), 70)) patient.list <- list(pat.1, pat.2) # define distribution of patients pat.1.prob <- 0.4; pat.2.prob <- 0.6 pat.dist.hosp <- c(pat.1.prob, pat.2.prob) hospital.1 <- list(inc.factor = 1, pat.dist = pat.dist.hosp, patient.list = patient.list) data.pps <- simulate_pps_data(n.sample=1000, steps=200, hospital=hospital.1)
pat.1 <- list(dist.X.los = create_dist_vec(function(x) dpois(x-1, lambda = 12), 70), I.p = 0.008, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70)) pat.2 <- list(dist.X.los = create_dist_vec(function(x) dpois(x-1, lambda = 10), 70), I.p = 0.02, dist.X.loi = create_dist_vec(function(x) dpois(x-1, lambda = 7), 70)) patient.list <- list(pat.1, pat.2) # define distribution of patients pat.1.prob <- 0.4; pat.2.prob <- 0.6 pat.dist.hosp <- c(pat.1.prob, pat.2.prob) hospital.1 <- list(inc.factor = 1, pat.dist = pat.dist.hosp, patient.list = patient.list) data.pps <- simulate_pps_data(n.sample=1000, steps=200, hospital=hospital.1)
The function 'simulate_pps_fast' can be used to generate PPS data. This functions simulates a PPS on the basis of a given prevalence 'P' using a vector of probabilities 'dist.X.loi' for the values 1:length(dist.X.loi) of X.loi. It directly samples the time of infection up to date based on 'dist.X.loi'. Optionally, the length of stay is sampled independently ( treating the marginal distributions of length of stay and length of infection as independent by assumption) using 'dist.X.los' which is in the same format as 'dist.X.loi'. Because of this non-joint sampling rows should not be interpreted as individual patients.
simulate_pps_fast(n.sample, P, dist.X.loi, dist.X.los = NA, one.factor.loi = 1, one.factor.los = 1)
simulate_pps_fast(n.sample, P, dist.X.loi, dist.X.los = NA, one.factor.loi = 1, one.factor.los = 1)
n.sample |
number of beds to simulate |
P |
prevalence of nosocomial infections |
dist.X.loi |
vector of probabilities for values 1:length(dist.X.loi) of X.loi |
dist.X.los |
vector of probabilities for values 1:length(dist.X.los) of X.los |
one.factor.loi |
factor by which to approx. reduce number of one day observations for A.loi |
one.factor.los |
factor by which to approx. reduce number of one day observations for A.los |
data frame with a row for a each simulated patient and the following columns
A.loi - length of infection up to PPS
L.loi - total length of infection
A.los - length of stay up to PPS
L.los - total length of stay
patient.type - patient type (fixed to 1 for fast method)
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), 70) data.pps.fast <- simulate_pps_fast(n.sample=5000, P=0.05, dist.X.loi = example.dist) head(data.pps.fast)
example.dist <- create_dist_vec(function(x) dpois(x-1, 7), 70) data.pps.fast <- simulate_pps_fast(n.sample=5000, P=0.05, dist.X.loi = example.dist) head(data.pps.fast)
Transform a distribution of times of stay to a distribution of staying-time up to observation point under assumption of steady state.
X_to_A_dist(dist.stays)
X_to_A_dist(dist.stays)
dist.stays |
vector of probabilities of being at the hospital for 1:length(dist.stays) days at random time of observation |
vector of probabilities of staying 1:length(dist.point) days
# generate vector of probabilities for truncated Poisson distribution for # distribution of times of stay X dist.X <- dpois(1:70, 4) plot(dist.X) # transform to distribution of distribution of staying-time up to observation point under # assumption of steady state dist.A <- X_to_A_dist(dist.X) plot(dist.A) # transform back to get original distribution dist.X.2 <- A_to_X_dist(dist.A) plot(dist.X.2)
# generate vector of probabilities for truncated Poisson distribution for # distribution of times of stay X dist.X <- dpois(1:70, 4) plot(dist.X) # transform to distribution of distribution of staying-time up to observation point under # assumption of steady state dist.A <- X_to_A_dist(dist.X) plot(dist.A) # transform back to get original distribution dist.X.2 <- A_to_X_dist(dist.A) plot(dist.X.2)