Models the reduction in faecal egg counts data with a (un)paired (zero-inflated) Poisson-gamma model formulation using the Stan modelling language. It is computationally several-fold faster compare to conventional MCMC techniques. For the installation instruction of Stan, please read: Stan Installation.
fecr_stan(preFEC, postFEC,rawCounts = FALSE, preCF = 50,
postCF = preCF, paired = TRUE, zeroInflation=TRUE,
muPrior, kappaPrior, deltaPrior, phiPrior,
nsamples = 4000, nburnin = 2000, thinning = 1, nchain = 1,
ncore = 1, adaptdelta = 0.95, verbose = FALSE)
vector of pre-treatment faecal egg counts
vector of post-treatment faecal egg counts
logical. If true, preFEC
and postFEC
correspond to raw counts
(as counted on equipment). Otherwise they correspond to calculated epgs (raw counts times correction factor).
Defaults to FALSE
.
correction factor(s) before treatment
correction factor(s) after treatment
logical. If true, uses the model for the paired design. Otherwise uses the model for the unpaired design
logical. If true, uses the model with zero-inflation. Otherwise uses the model without zero-inflation
a list with hyper-prior information for the baseline mean parameter \(\mu\). The default prior is list(priorDist = "gamma",hyperpars=c(1,0.001))
, i.e. a gamma distribution with shape 1 and rate 0.001, its 90% probability mass lies between 51 and 2996
a list with hyper-prior information for the dispersion parameter \(\kappa\). The default prior is list(priorDist = "gamma",hyperpars=c(1,0.7))
, i.e. a gamma distribution with shape 1 and rate 0.7, its 90% probability mass lies between 0.1 and 4.3 with a median of 1
a list with hyper-prior information for the reduction \(\delta\). The default prior is list(priorDist = "beta",hyperpars=c(1,1))
a list with hyper-prior information for the zero-inflation parameter \(\phi\),The default prior is list(priorDist = "beta",hyperpars=c(1,1))
a positive integer specifying how many iterations for each chain (including burn-in samples)
number of burn-in samples
thinning parameter, a positive integer specifying the period for saving samples
a positive integer specifying the number of chains
number of cores to use when executing the chains in parallel
the target acceptance rate, a value between 0 and 1
logical. If true, prints progress and debugging information
Prints out the posterior summary of fecr
as the reduction, meanEPG.untreated
as the mean faecal egg counts before treatment, and meanEPG.treated
as the mean faecal egg counts after treatment. The posterior summary contains the mean, standard deviation (sd), 2.5%, 25%, 50%, 75% and 97.5% percentiles, the 95% highest posterior density interval (HPDLow95 and HPDHigh95) and the posterior mode. NOTE: we recommend to use the 95% HPD interval and the mode for further statistical analysis.
The returned value is a list that consists of:
An object of S4 class stanfit
representing the fitted results. For more information, please see the stanfit-class
in rstan
reference manual.
A data frame that is the same as the printed posterior summary.
The first time each model with non-default priors is applied, it can take up to 20 seconds for stan to compile the model. Currently the function only support prior distributions with two parameters. For a complete list of supported priors and their parameterization, please consult the list of distributions in Stan.
Sometimes the function outputs informational message from Stan regarding the Metropolis proposal rejections, this is due to the sampler hitting the boundary of the parameter space. For some variables, the boundary point is not supported in the distribution. This is not a concern if there are only a few such warnings.
The default number of iterations is 2000, with 1000 burn-in iterations. Normally this is sufficient in Stan. If MCMC chains do not converge, one should tune the MCMC parameters until convergence is reached to ensure correct results.
simData2s
for simulating faecal egg counts data with two samples
# NOT RUN {
## load the sample data as a vector
data(epgs)
## apply zero-infation model to the data vector
model<-fecr_stan(epgs[,1],epgs[,2],rawCounts=FALSE,preCF=10,paired=TRUE,zeroInflation=TRUE)
samples<-stan2mcmc(model$stan.samples)
## a demonstration
demo("fecm_stan", package = "eggCounts")
# }
Run the code above in your browser using DataLab