Title: | Side Effect Risks in Hospital : Simulation and Estimation |
Version: | 1.10 |
Author: | Christophe Dutang and Julie Barthes |
Description: | Evaluating risk (that a patient arises a side effect) during hospitalization is the main purpose of this package. Several methods (Parametric, non parametric and De Vielder estimation) to estimate the risk constant (R) are implemented in this package. There are also functions to simulate the different models of this issue in order to quantify the previous estimators. It is necessary to read at least the first six pages of the report to understand the topic. |
Maintainer: | Christophe Dutang <christophe.dutang@ensimag.fr> |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
NeedsCompilation: | no |
Packaged: | 2018-08-07 19:35:50 UTC; dutang |
Repository: | CRAN |
Date/Publication: | 2018-08-07 19:50:03 UTC |
implements the De Vielder approximation
Description
DV computes the De Vielder approximation whose goal is to identify the first
two moments of a general case of the first model where p(x) is unknown to the first two moments
of the specific case of the first model where p(x) = 1- exp(-mu *x)
Usage
DV(T)
Arguments
T |
a vector of the observations of the random variable T associated with the first model |
Value
a vector of lambda and mu of the De Vielder method
Author(s)
Christophe Dutang and Julie Barthes
Examples
T<-c(12.9622796, 1.4146460, 1.3146761, 14.9147353, 7.5131105,
8.5130874, 6.5943351, 10.6954653, 14.1000977, 12.4673316, 2.7185478,
9.6297777, 10.0930441, 0.6270543, 26.7937074, 7.6082447)
res<-DV(T)
plots a survival function with a Kaplan Meier variant
Description
plots the survival function of patients knowing censored data. Model : a variant of Kaplan-Meier's model
Usage
KM(fileName, toplot = TRUE, header = TRUE)
Arguments
fileName |
the file with the data use |
toplot |
a logical variable to plot the result of this estimation |
header |
a logical for : has the input file an header |
Value
No values returned, just plot the survival function and the theoretical distribution of our model with exponential stays and a constant side effect probability
Author(s)
Christophe Dutang and Julie Barthes
Examples
#KM("data.rda",TRUE,TRUE)
make an array of bias, variance and R for different distribution and estimators
Description
this function prints an array of the bias, variance, risk constants R and CR for three estimators (parametric, non parametric and De Vielder) with different side effect probability for p
Usage
Table(file, nb = 10, mod)
Arguments
file |
the file in wich the simulation will be done |
nb |
the number of simulation for each estimators |
mod |
first mod makes simulation for an estimator in different cases (arg2) second mod makes simulation for a case with different estimators third mod makes simulation for a case with the parametric and non parametric estimatorse |
Value
Null.
Author(s)
Christophe Dutang and Julie Barthes
Examples
#Table("d.rda",100,3)
# plot the following result
#[1] "arg2Exp"
# nonpar par
#bias 4.407856e-02 -3.503516e-06
#var 6.001352e-05 1.972828e-05
#R 9.405885e-02 4.997679e-02
#CR 8.492920e+00 1.455619e+01
#[1] "arg2Cst"
# nonpar par
#bias 1.575410e-02 4.573187e-04
#var 1.714712e-05 5.675577e-06
#R 3.242554e-02 1.712875e-02
#CR 2.197198e+01 4.066553e+01
#[1] "arg2Comp"
# nonpar par
#bias 3.247060e-02 -5.558817e-05
#var 4.621880e-05 1.006148e-05
#R 6.880894e-02 3.628275e-02
#CR 1.101930e+01 1.967524e+01
#[1] "arg2Gamma"
# nonpar par
#bias 1.832645e-02 -7.552530e-04
#var 2.267637e-05 7.363311e-06
#R 3.778277e-02 1.870107e-02
#CR 1.911443e+01 3.773611e+01
#[1] "arg2Lnorm"
# nonpar par
#bias 4.556463e-02 1.017082e-03
#var 7.013414e-05 3.104221e-05
#R 1.005464e-01 5.599889e-02
#CR 8.101552e+00 1.318976e+01
#[1] "arg2Unif"
# nonpar par
#bias 2.514426e-02 2.598740e-04
#var 3.878331e-05 1.073282e-05
#R 5.236710e-02 2.748271e-02
#CR 1.408411e+01 2.580822e+01
#[1] "arg2Weib"
# nonpar par
#bias 4.588473e-03 1.540856e-04
#var 5.405285e-06 1.589171e-06
#R 9.367470e-03 4.933083e-03
#CR 7.709814e+01 1.468196e+02
#
test the adequation of a random variable to the exponential distribution
Description
In order to test the adequation of a random variable, this function plot the probabilit plot with reference distribution exponential of the variable and calculates the Kolmogorov Smirnov test.
Usage
adequadExp(T, toplot = FALSE)
Arguments
T |
the random variable on which we want to test the adequation |
toplot |
a logical to plot the probability graph |
Value
a list of the following components
LinearRegression |
the result of the linear regression of the ordinate on the abcisse of the probability plot |
KolmogorvSmirnovTest |
the result of the Kolmogorvo Smirnoc test |
Author(s)
Christophe Dutang and Julie Barthes
Examples
## Not run:
T <- c(12.9622796, 1.4146460, 1.3146761, 14.9147353, 7.5131105,
8.5130874, 6.5943351, 10.6954653, 14.1000977, 12.4673316, 2.7185478,
9.6297777, 10.0930441, 0.6270543, 26.7937074, 7.6082447)
adequadExp(T,TRUE)
## End(Not run)
compute the bias, variance of the De Vielder approximation
Description
calcErrorDV computes the risk constant R with the De Vielder estimator and its bias and variance.
Usage
calcErrorDV(file, nb = 10, disXi, disP, plot = TRUE)
Arguments
file |
the file in which the simulated data will be stored |
nb |
the number of simulation |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disP |
the side effect probability (success probability of Zi) p : disP is a 3 elements list : disfun stands for a distribution function ; nbparam for number of parameter of this distribution and param for a list of parameters |
plot |
a logical variable to plot the variable Zi |
Value
a list of the following components
bias |
the bias of this estimator |
var |
the variance of this estimator |
R |
the risk constant estimated |
CR |
the CR risk constant calculated with R |
Author(s)
Christophe Dutang and Julie Barthes
Examples
## Not run:
arg1Exp<-list(rangen=rexp,nbparam=1,param=list(1/3));
arg2Exp<-list(disfun=pexp,nbparam=1,param=list(1/5));
res<-calcErrorDV("data.rda",25,arg1Exp,arg2Exp,TRUE)
## End(Not run)
compute the bias, variance of the non parametric estimator
Description
calcErrorNonParam computes the risk constant R with the non parametric estimator and its bias and variance.
Usage
calcErrorNonParam(file, nb = 10, disXi, disP, plot = TRUE)
Arguments
file |
the file in which the simulated data will be stored |
nb |
the number of simulation |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disP |
the side effect probability (success probability of Zi) p : disP is a 3 elements list : disfun stands for a distribution function ; nbparam for number of parameter of this distribution and param for a list of parameters |
plot |
a logical variable to plot the variable Zi |
Value
a list of the following components
bias |
the bias of this estimator |
var |
the variance of this estimator |
R |
the risk constant estimated |
CR |
the CR risk constant calculated with R |
Author(s)
Christophe Dutang and Julie Barthes
Examples
#arg1Exp<-list(rangen=rexp,nbparam=1,param=list(1/3));
#arg2Exp<-list(disfun=pexp,nbparam=1,param=list(1/5));
#res<-calcErrorNonParam("data.rda",25,arg1Exp,arg2Exp,TRUE)
compute the bias, variance of the non parametric estimator
Description
calcErrorNonParam computes the risk constant R with the non parametric estimator and its bias and variance.
Usage
calcErrorParam(file, nb = 10, disXi, disP, plot = TRUE)
Arguments
file |
the file in which the simulated data will be stored |
nb |
the number of simulation |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disP |
the side effect probability (success probability of Zi) p : disP is a 3 elements list : disfun stands for a distribution function ; nbparam for number of parameter of this distribution and param for a list of parameters |
plot |
a logical variable to plot the variable Zi |
Value
a list of the following components
bias |
the bias of this estimator |
var |
the variance of this estimator |
R |
the risk constant estimated |
CR |
the CR risk constant calculated with R |
Author(s)
Christophe Dutang and Julie Barthes
Examples
#arg1Exp<-list(rangen=rexp,nbparam=1,param=list(1/3));
#arg2Exp<-list(disfun=pexp,nbparam=1,param=list(1/5));
#res<-calcErrorNonParam("data.rda",25,arg1Exp,arg2Exp,TRUE)
compute the De Vielder estimator
Description
compute the De Vielder estimator, in other words, do the same function as DV
but returns more details about this estimator whereas DV
only compute the lambda
and mu of the De Vielder method
Usage
estimDV(fileName, toplot = TRUE, header = TRUE, ks = FALSE)
Arguments
fileName |
the file in which the simulated data will be stored |
toplot |
a logical variable to plot the result of this estimation |
header |
a logical for : has the input file an header |
ks |
a logical for : do you want the Kolmogorv Smirnov test |
Value
a list of the following components
CR |
the CR risk constant calculated with the value of R |
R |
the risk constant estimated by this estimation |
T |
the vector of observations of the random variable T |
lambdaHat |
the best estimation of lambda |
muHat |
the best estimation of mu |
lambdaEmp |
the estimation of the lambda of the De Vielder method (in this case the same value as lambdaHat) |
muEmp |
the estimation of the mu of the De Vielder method (in this case the same value as mu) |
Author(s)
Christophe Dutang and Julie Barthes
Examples
#res<-estimDV("data.rda",TRUE,TRUE)
compute the parametric estimation
Description
estimParam compute the parametric estimation of the first model on the input file
containing the stay duration Xi and the side effect reporting Zi. this estimator of R (and not mu)
is the smallest root of the equation (*) : P(Zi=0)E[exp(-RXi)/Zi=0]=1
Usage
estimNonParam(fileName, toplot = TRUE, header = TRUE, ks = FALSE, DV = FALSE)
Arguments
fileName |
the file in which the simulated data will be stored |
toplot |
a logical variable to plot the result of this estimation |
header |
a logical for : has the input file an header |
ks |
a logical for : do you want the Kolmogorv Smirnov test |
DV |
a logical for : do you want to calculate the De Vielder estimation |
Value
a list of the following components
CR |
the CR risk constant calculated with the value of R |
R |
the risk constant estimated by this estimation |
T |
the vector of observations of the random variable T |
lambdaHat |
the best estimation of lambda : the ESBVM of lambda |
muHat |
not available with this estimation |
lambdaEmp |
the estimation of the lambda of the De Vielder method (only available if |
muEmp |
the estimation of the mu of the De Vielder method (only available if |
Author(s)
Christophe Dutang and Julie Barthes
Examples
#res<-estimDV("data.rda",TRUE,TRUE)
compute the parametric estimation
Description
estimParam compute the parametric estimation of the first model on the input file
containing the stay duration Xi and the side effect reporting Zi. this estimator of mu
is the estimator of maximum likelihood of the random variable Zi / Xi=x
. the risk constant
R is given by the equation (star) R=mu
.
Usage
estimParam(fileName, toplot = TRUE, header = TRUE, ks = FALSE, DV = FALSE)
Arguments
fileName |
the file in which the simulated data will be stored |
toplot |
a logical variable to plot the result of this estimation |
header |
a logical for : has the input file an header |
ks |
a logical for : do you want the Kolmogorv Smirnov test |
DV |
a logical for : do you want to calculate the De Vielder estimation |
Value
a list of the following components
CR |
the CR risk constant calculated with the value of R |
R |
the risk constant estimated by this estimation |
T |
the vector of observations of the random variable T |
lambdaHat |
the best estimation of lambda : the ESBVM of lambda |
muHat |
the best estimation of mu : the value of mu which maximize the loglikelihood |
lambdaEmp |
the estimation of the lambda of the De Vielder method (only available if |
muEmp |
the estimation of the mu of the De Vielder method (only available if |
Author(s)
Christophe Dutang and Julie Barthes
Examples
#res<-estimDV("data.rda",TRUE,TRUE)
plot the histogram of the variable T
Description
plot of the random variable T and the equivalent function (t->CR*exp(-R*t)
).
in some cases, there are also plotted the theoretical and the De Vielder functions
Usage
histo(X, disXi = NULL, disP = NULL, plotDV = FALSE)
Arguments
X |
a list with the following components : T the observation of the random variable ; R the risk constant (estimated or theoretical calculated)
; CR the risk constand deduced from R ; lambdaEmp the estimation of the lambda of the De Vielder method (only available if |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disP |
he side effect probability (success probability of Zi) p : disP is a 3 elements list : disfun stands for a distribution function ; nbparam for number of parameter of this distribution and param for a list of parameters |
plotDV |
a logical for : do you want to plot the De Vielder "function" |
Value
a NULL object.
Author(s)
Christophe Dutang and Julie Barthes
Examples
#use mainSimul to make the first argument
arg1Exp <- list(rangen=rexp,nbparam=1,param=list(1/3));
arg1Bin <- list(rangen=rbinom,nbparam=2,param=list(1,1/20));
arg1Unif <- list(rangen=runif,nbparam=2,param=list(0,20));
arg1Lnorm <- list(rangen=rlnorm,nbparam=2,param=list(1/4,1));
arg2Exp <- list(disfun=pexp,nbparam=1,param=list(1/5));
arg2Cst <- list(disfun=pcst <- function(x,p) p ,nbparam=1,param=list(1/3));
arg2Comp <- list(disfun=pcomp <- function(x,mu1,mu2,mu3)
{1-1/3*exp(-mu1* x)-1/2*exp(-mu2 *x)-1/6*exp(-mu3 *x)}
,nbparam=3,param=list(1/3,1/5,1/10));
arg2Gamma <- list(disfun=pgamma,nbparam=2,param=list(3,1/3));
arg2Lnorm <- list(disfun=plnorm,nbparam=2,param=list(1/20,2));
T <- mainSimul(100,100,arg1Exp,arg2Exp)
histo(T,arg1Exp,arg2Exp)
simulate many times the first model and calculate the risk constant
Description
main simulates nbBed times the first model with the function simul
and calculates the risk constant R and CR by solving the renewal equation (star).
this renewal equation is only valid if the Xi forms a poisson process.
R and CR are defined such that the equivalent survival function is CR *exp(-R*x)
.
Usage
mainSimul(nbBed, nbPatient, disXi, disP, toplot = FALSE, calc = TRUE)
Arguments
nbBed |
the number of beds |
nbPatient |
the number of patient in each bed |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disP |
the distribution of the success probability of Zi : p : disP is a 3 elements list : disfun stands for a distribution function ; nbparam for number of parameter of this distribution and param for a list of parameters |
toplot |
a logical variable to plot the variable Zi |
calc |
should the risk constants calculate? |
Details
make simulation and estimation on the sample
Value
Describe the value returned If it is a LIST, use
CR |
CR constant used in the exponential bound |
R |
the risk constant |
T |
the vector of durations between two declared side effects |
lambdaEmp |
estimate of lambda |
muEmp |
estimate of mu |
Author(s)
Christophe Dutang and Julie Barthes
Examples
arg1Exp <- list(rangen=rexp,nbparam=1,param=list(1/3));
arg1Bin <- list(rangen=rbinom,nbparam=2,param=list(1,1/20));
arg1Unif <- list(rangen=runif,nbparam=2,param=list(0,20));
arg1Lnorm <- list(rangen=rlnorm,nbparam=2,param=list(1/4,1));
arg2Exp <- list(disfun=pexp,nbparam=1,param=list(1/5));
arg2Cst <- list(disfun=pcst <- function(x,p) p ,nbparam=1,param=list(1/3));
arg2Comp <- list(disfun=pcomp <- function(x,mu1,mu2,mu3)
{1-1/3*exp(-mu1* x)-1/2*exp(-mu2 *x)-1/6*exp(-mu3 *x)}
,nbparam=3,param=list(1/3,1/5,1/10));
arg2Gamma <- list(disfun=pgamma,nbparam=2,param=list(3,1/3));
arg2Lnorm <- list(disfun=plnorm,nbparam=2,param=list(1/20,2));
T <- mainSimul(100,100,arg1Exp,arg2Exp)
simulate many times the second model
Description
main simulates nbBed times the second model with the function simul
Usage
mainSimul2(nbBed, nbPatient, disXi, disYi, toplot = FALSE)
Arguments
nbBed |
the number of beds |
nbPatient |
the number of patient in each bed |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disYi |
the distribution of the variable Yi : disYi is a 3 elements list : rangen for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
toplot |
a logical variable to plot the variable Zi |
Details
If necessary, more details than the description above
Value
return a list of the following components
T |
T the vector of durations between two declared side effects |
R |
R a risk constant |
CR |
CR a risk constant |
Author(s)
Christophe Dutang and Julie Barthes
Examples
arg1ExpMod2 <- list(rangen=rexp,nbparam=1,param=list(1/2));
arg1BinMod2 <- list(rangen=rbinom,nbparam=2,param=list(1,1/20));
arg1UnifMod2 <- list(rangen=runif,nbparam=2,param=list(0,20));
arg1LnormMod2 <- list(rangen=rlnorm,nbparam=2,param=list(1/4,1));
arg2ExpMod2 <- list(rangen=rexp,nbparam=1,param=list(1/5));
# arg2-cst <- list(rangen=pcst <- function(x,p) p ,nbparam=1,param=list(1/10));
arg2GammaMod2 <- list(rangen=rgamma,nbparam=2,param=list(3,1/5));
T <- mainSimul2(100,100,arg1ExpMod2,arg2ExpMod2)
create a sample of the first model stored in a file
Description
make a sample of the first model, that is to say simulate the sequence of the random variables Xi (stay duration) and the sequence of Zi (side effect reporting)
Usage
makeSample(file, nbPatient, disXi, disP)
Arguments
file |
the filename in which the simulation will be stored |
nbPatient |
the number of patients for the simulation |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disP |
the side effect probability (success probability of Zi) p : disP is a 3 elements list : disfun stands for a distribution function ; nbparam for number of parameter of this distribution and param for a list of parameters |
Value
a NULL object.
Author(s)
Christophe Dutang and Julie Barthes
Examples
arg1Exp<-list(rangen=rexp,nbparam=1,param=list(1/3));
arg2Exp<-list(disfun=pexp,nbparam=1,param=list(1/5));
makeSample("mydata.rda",200,arg1Exp,arg2Exp)
create a sample of the second model stored in a file
Description
make a sample of the first model, that is to say simulate the sequence of the random variables Xi (stay duration) the sequence of Yi (exposure time) and the sequence of Zi (side effect reporting)
Usage
makeSample2(file, nbPatient, disXi, disYi)
Arguments
file |
the filename in which the simulation will be stored |
nbPatient |
the number of patients for the simulation |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disYi |
the distribution of the variable Yi : disYi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
Value
a NULL object.
Author(s)
Christophe Dutang and Julie Barthes
Examples
arg1ExpMod2<-list(rangen=rexp,nbparam=1,param=list(1/2));
arg1BinMod2<-list(rangen=rbinom,nbparam=2,param=list(1,1/20));
arg1UnifMod2<-list(rangen=runif,nbparam=2,param=list(0,20));
arg1LnormMod2<-list(rangen=rlnorm,nbparam=2,param=list(1/4,1));
arg2ExpMod2<-list(rangen=rexp,nbparam=1,param=list(1/5));
# arg2-cst<-list(rangen=pcst<-function(x,p) p ,nbparam=1,param=list(1/10));
arg2GammaMod2<-list(rangen=rgamma,nbparam=2,param=list(3,1/5));
makeSample2("thedata.rda",200,arg1ExpMod2,arg2ExpMod2)
simulate the first model of the hospital risk
Description
simul simulate the first model of the hospital that is to say simulating the sequence of variables Xi (which follow the disxi distribution passed as an argument) and the sequence of Zi (where the probability of succes p is passed as an argument) simul returns T the vector of durations between two declared side effects
Usage
simul(nbPatient, disXi, disP, toplot = TRUE)
Arguments
nbPatient |
the number of patient of the simulation |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disP |
the side effect probability (success probability of Zi) p : disP is a 3 elements list : disfun stands for a distribution function ; nbparam for number of parameter of this distribution and param for a list of parameters |
toplot |
a logical variable to plot the variable Zi |
Value
T the vector of durations between two declared side effects
Note
further notes
Author(s)
Christophe Dutang and Julie Barthes
See Also
simul2
Examples
arg1Exp <- list(rangen=rexp,nbparam=1,param=list(1/3));
arg1Bin <- list(rangen=rbinom,nbparam=2,param=list(1,1/20));
arg1Unif <- list(rangen=runif,nbparam=2,param=list(0,20));
arg1Lnorm <- list(rangen=rlnorm,nbparam=2,param=list(1/4,1));
arg2Exp <- list(disfun=pexp,nbparam=1,param=list(1/5));
arg2Cst <- list(disfun=pcst <- function(x,p) p ,nbparam=1,param=list(1/3));
arg2Comp <- list(disfun=pcomp <- function(x,mu1,mu2,mu3)
{1-1/3*exp(-mu1* x)-1/2*exp(-mu2 *x)-1/6*exp(-mu3 *x)}
,nbparam=3,param=list(1/3,1/5,1/10));
arg2Gamma <- list(disfun=pgamma,nbparam=2,param=list(3,1/3));
arg2Lnorm <- list(disfun=plnorm,nbparam=2,param=list(1/20,2));
T <- simul(100,arg1Exp,arg2Exp)
T <- simul(100,arg1Bin,arg2Cst)
T <- simul(100,arg1Unif,arg2Comp)
T <- simul(100,arg1Lnorm,arg2Gamma)
simulate the second model of the hospital risk
Description
simul simulate the first model of the hospital that is to say simulating the sequence of variables Xi (which follow the disxi distribution passed as an argument) and the sequence of Zi (where the probability of succes p is passed as an argument) simul returns T the vector of durations between two declared side effects
Usage
simul2(nbPatient, disXi, disYi, toplot = TRUE)
Arguments
nbPatient |
the number of patient of the simulation |
disXi |
the distribution of the variable Xi : disXi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
disYi |
the distribution of the variable Yi : disYi is a 3 elements list : rangen stands for a random positive variable generator ; nbparam for number of parameter of this distribution and param for a list of parameters |
toplot |
a logical variable to plot the variable Zi |
Value
T the vector of durations between two declared side effects
Author(s)
Christophe Dutang and Julie Barthes
Examples
arg1Exp<-list(rangen=rexp,nbparam=1,param=list(1/2));
arg2Exp<-list(rangen=rexp,nbparam=1,param=list(1/20));
T<-simul2(100,arg1Exp,arg2Exp)