Sunteți pe pagina 1din 20

24 December 2014

Preliminaries
Let us first load the package:
library(bindr)

Let us set the seed to 100 in order to be able to reproduce the results
set.seed(100)

We will first illustrate the usage of BindR using some simulated data.
mydata <- sim.hcai.data(n=300, admrate=3, LOS=5, import=0.07, sens=0.9,
beta=c(0.001,0.005), catname="iso", capacity=20)

The function sim.hcai.data has various option which can be found by looking in the help file
?sim.hcai.data

For example, our dataset (object mydata) is a dataset which consists of 300 patient
admissions, the rate at which new admission occur (Poisson distributed) being equal to 3,
the average length of stay in the ward to be 5 days (also Poisson distribute), the probability
that an individual who is admitted in the ward is already colonised being 0.07, the tests
sensitivity is assumed to be 90% and finally, the rates of colonisation. We are simulating
data from a model under which a susceptible individual is getting pressure from
individuals who are colonised at rate 0.001 and from colonised and isolated being 0.005.
Finally, we also assumed that maximum numbers of occupied beds in the ward is 20.
The object my data is essentially list of length equal to the number of admissions
length(mydata)
## [1] 300

Let us have a closer look to mydata but accessing its first element
mydata[[1]]
##
##
##
##
##
##
##
##
##
##
##
##
##

$id
[1] 1
$adm
[1] 2
$dis
[1] 5
$onadm
[1] 0
$col.time

##
##
##
##
##
##
##
##
##
##

[1] 0
$colsource
[1] NA
$test
[1] 0 -1

$iso
[1] 0 0 0 0

Here are the details we get about the 1st patient:

the individuals id number, i.e. 1


their admission time, i.e. day 2
their discharge time, i.e. day 5
whether or not the individual was colonised on admission; '1' if they were and '0' if
they were not.
their colonisation time; if they were not colonised their colonisation time is set to 0.
their colonisation source; i.e. the id of the individual who colonised that indivudal. If an
individual was not colonised during their stay, then the source is seto 'NA'.
information about the tests; a vector of length equal to the number of days an
individual stayed in the ward: '0' if there was no test on that day, '0' if there was no
test on that day, and '1' if there was a test and it was positive.
information on their covariate information. In this case an individual may have been
isolated ('1' if they were and '0' if they were on any particular day)

Exploratory Data Analysis


Let us look at summary statistics of the dataset:
data.summary(mydata)
## Data Summary
##
## Number of patient episodes: 300
## Total patient days: 1847
## Total colonized days [midpoint]: 140 (7.6%)
## Median length of stay: 6, IQR: (5, 8)
## Number of readmissions (% of total episodes): (%)
## Tests taken (per episode): 612 (2)
## Positive tests (% of total): 42 (6.9%)
## False negative test results (% tests negative following a positive): 3
(6.7%)
## Patient episodes with a positive test (% of total): 21 (7%)
## Number positive on admission [first test positive] (% of admissions): 17
(5.7%)
## Number of acquisitions (% of negative admissions): 4 (1.4%)

We can also draw some summary plots for those individuals who were colonised:
plot_episodes(mydata, mark.id=T, main="Colonized episodes")

or the data from all individuals (both colonised and non-colonised:


plot_episodes(mydata, mark.id=F, all.eps=T, split=100, main="Colonized
episodes")

Instead, one can draw a who-infected-whom:


plot_network(mydata, border=F)

In addition, one can draw a graph which shows the number of colonised and total number
of individuals per day:
plot_colpop(mydata, bty="l", xaxs="i", yaxs="i")

Furthermore, the colonized population broken down by the covariate:


plot_colpop(mydata, cov="iso", fill=T, col=c(rgb(1,0,0,0.5), rgb(0,0,1,0.5)),
bty="l", xaxs="i", yaxs="i")

Fitting Models to Data


Let us first create a simple model first:
m1 <- make.model(mydata)
m1
##
##
##
##
##
##
##
##
##
##
##
##
##

$bg
[1] FALSE
$trans
[1] 1
$trans.var
[1] 0
$sus
[1] 0
$sus.var

##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##

[1] 0
$const.rate
[1] FALSE
$npar
[1] 3
$model.spec
[1] "q(t) = trans.par*C(t)"
$disease.type
[1] FALSE
$split.import
[1] FALSE
attr(,"class")
[1] "HCAImodel"

The above command essentially creates a model in which it is assumed that the rate at
which a new colonisation occurs is
where is the person to person
transmission rate and
denotes the number of colonised individuals in the ward at time
.
One can add a background transmission rate by setting bg=TRUE when calling the
`make.model function above or/add asssume that there are two types of colonsided
individuas, for example, isolated and non-isolate who exert pressure to susceptible
individuals at different rates.
For example, by typing:
m2 <- make.model(mydata, trans.par="iso", bg=T)
m2
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##

$bg
[1] TRUE
$trans
[1] 2
$trans.var
[1] "iso"
$sus
[1] 0
$sus.var
[1] 0

##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##

$const.rate
[1] FALSE
$npar
[1] 5
$model.spec
[1] "q(t) = bg.par + trans.par1*C_1(t)"
$disease.type
[1] FALSE
$split.import
[1] FALSE
attr(,"class")
[1] "HCAImodel"

we have created a model that assumes that the rate of colonisation is

Once we have made the model object, we now need to assign priors to the parameters in
the model. There is a default option for assigning prior:
ps1 <- prior.structure(m1)
ps1
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##

[[1]]
[[1]]$name
[1] "importation.rate"
[[1]]$distribution
[1] "Beta"
[[1]]$par1
[1] 1
[[1]]$par2
[1] 1

[[2]]
[[2]]$name
[1] "test.sensitivity"
[[2]]$distribution
[1] "Beta"
[[2]]$par1
[1] 1

##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##
##

[[2]]$par2
[1] 1

[[3]]
[[3]]$name
[1] "trans.par1"
[[3]]$distribution
[1] "Exponential"
[[3]]$par1
[1] 1e+06

attr(,"class")
[1] "priorstructure"

ps2 <- prior.structure(m2)

For example, a Beta


distribution is assigned to the importantion probabiliy and test`s
sensivity parameters whilst an Exponential
distribution has been assigned to the
colonisation rate in model m1. If we want to change the default priors, for example set
the prior for the colonisation rate to be Exp
we can do something like:
ps1[[3]]$par1 <- 1
ps1[[3]]
##
##
##
##
##
##
##
##

$name
[1] "trans.par1"
$distribution
[1] "Exponential"
$par1
[1] 1

Let us know fit model m1 to the data we have generated using MCMC:
K <- da.mcmc(data=mydata, model=m2, prior=ps2, iterations=10000, da.moves=5,
feedback=3)
##
##
##
##
##
##
##
##

Using default initial values...


Using default proposal variances...
Note: set 'feedback' lower to receive feedback during algorithm
Number of episodes = 300, Total study days = 124
Number of parameters: import=1, background=1, sus=0, trans=2
totpt = 0
Number of importations: 9

## Number of acquisitions: 12
## .Var[bg.par]=0.010000- Acc. rate 0.082
Var[trans.par1]=0.010000- Acc.
rate 0.076
Var[trans.par2]=0.010000+ Acc. rate 0.523
## .Var[bg.par]=0.008000- Acc. rate 0.106
Var[trans.par1]=0.008000- Acc.
rate 0.112
Var[trans.par2]=0.012500+ Acc. rate 0.458
## .Var[bg.par]=0.006400- Acc. rate 0.102
Var[trans.par1]=0.006400- Acc.
rate 0.123
Var[trans.par2]=0.015625 Acc. rate 0.388
## .Var[bg.par]=0.005120 Acc. rate 0.160
Var[trans.par1]=0.005120 Acc.
rate 0.182
Var[trans.par2]=0.015625 Acc. rate 0.366
## .Var[bg.par]=0.005120- Acc. rate 0.119
Var[trans.par1]=0.005120- Acc.
rate 0.141
Var[trans.par2]=0.015625 Acc. rate 0.398
## .Var[bg.par]=0.004096 Acc. rate 0.179
Var[trans.par1]=0.004096 Acc.
rate 0.173
Var[trans.par2]=0.015625+ Acc. rate 0.402
## .Var[bg.par]=0.004096 Acc. rate 0.190
Var[trans.par1]=0.004096 Acc.
rate 0.194
Var[trans.par2]=0.019531 Acc. rate 0.331
## .Var[bg.par]=0.004096 Acc. rate 0.205
Var[trans.par1]=0.004096 Acc.
rate 0.243
Var[trans.par2]=0.019531 Acc. rate 0.311
## .Var[bg.par]=0.004096 Acc. rate 0.173
Var[trans.par1]=0.004096 Acc.
rate 0.210
Var[trans.par2]=0.019531 Acc. rate 0.312
## .
## Iteration 10000
## importation.rate: 0.068274
## test.sensitivity: 0.857709
## bg.par: 0.004072
## trans.par1: 0.001958
## trans.par2: 0.005463
## Col. times added: 1
## Importations: 17, Acquisitions: 5
## True pos: 42, False neg: 4
## Var[bg.par]=0.004096 Acc. rate 0.213 Var[trans.par1]=0.004096 Acc. rate
0.244
Var[trans.par2]=0.019531 Acc. rate 0.316
##
## End time: 2014-12-28 22:12:20
## Process time = 5.0 min

We can change feedback=1 if we want bindr to tell us how many iterations have been
completed yet:
We can look at some summary statistics for the estimated parameters from the MCMC
output:
mcmc.summary(K)
##
##
##
##
##
##
##

MCMC posterior parameter estimates [10000 iterations] (95% CrI)


importation.rate:
test.sensitivity:
bg.par: 0.001 (0,
trans.par1: 0.001
trans.par2: 0.015

0.059 (0.033, 0.091)


0.877 (0.739, 0.966)
0.004)
(0, 0.004)
(0.003, 0.032)

## Number of acquisitions: 7.529 (4, 13)


## Number of importations: 16.669 (13, 20)

One should also look at the trace plots to ensure that convergence has been reached:
layout(rbind(c(1,1,1,2,2,2), c(3,3,4,4,5,5)))
plot_trace(K, burn=0, cri.line=T)

or, a the the (marginal) posterior densities:


plot_density(K)

or, at a pairwise correlations plot:


plot_correlation(K, sample=1000, col="darkred", pch=".")

The advantage of adopting a Bayesian approach to inference via data-augmentation is that


as a by-product we can infer the number of acquisitions (i.e. number those individuals who
were colonised in the ward) and number of importations (i.e. number of individuals who
were colonised on admission)
hist(K$num.acq, main="Number of Acquisitions")

hist(K$num.imp, main="Number of Importations")

S-ar putea să vă placă și