Documente Academic
Documente Profesional
Documente Cultură
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
We can also draw some summary plots for those individuals who were colonised:
plot_episodes(mydata, mark.id=T, main="Colonized episodes")
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")
$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"
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"
$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)
##
##
##
##
##
##
##
##
## 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)
##
##
##
##
##
##
##
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)