Learn R Programming

bayescount (version 0.8.2)

bayescount: ANALYSE COUNT DATA USING JAGS

Description

Apply a Bayesian (zero-inflated) (gamma / Weibull / lognormal / independant / simple) Poisson model to count data to return possible values for mean count, variance, shape paramater, scale parameter (overdispersion or 'k') and zero-infaltion where appropriate to the model selected. A text .csv file named *name*.*model*.csv with the results is optionally written to the working directory (before checking if the file already exists), and an object *name*.*model*.results is copied to the Global environment within R. Where more than 1 model is used, a results file and object is created for each model. Convergence is assessed for each dataset by calculating the Gelman-Rubin statistic for each parameter. Optionally, the (log) likelihood for the model fit is also calculated. This function is a wrapper for bayescount.single(), allowing extra automation. Requires Just Another Gibbs Sampler (JAGS). *THIS SOFTWARE IS INTENDED FOR EDUCATIONAL PURPOSES ONLY AND SHOULD NOT BE RELIED UPON FOR REAL WORLD APPLICATIONS* The GUI interface for R in Windows may not continually refresh the output window, making it difficult to track the progress of the simulation (if silent.jags is FALSE). To avoid this, you can run the function from the terminal version of R (located in the Program Files/R/bin/ folder).

Usage

bayescount(name = NA, data = NA, setnames = NA, 
   div = 1, model = c("ZILP"), burnin = 5000, 
   updates = c(10000,100000,500000), jags = findjags(), 
   rownames = FALSE, remove.zeros = TRUE, remove.missing = TRUE, 
   test = TRUE, alt.prior = FALSE, write.file = TRUE,
   adjust.mean = FALSE, crash.retry = 1,
   silent.jags = FALSE, likelihood = FALSE)

Arguments

Value

No value is returned by this function. Instead, a text .csv file named *name*.*model*.csv with the results is optionally written to the working directory (before checking if the file already exists), and an object *name*.*model*.results is copied to the Global environment within R. Where more than 1 model is used, a results file and object is created for each model. The results files contain the dataset names, an indication of the error/crash/convergence status of each dataset, the number of sampled updates used, and a lower/upper 95

See Also

bayescount.single likelihood

Examples

Run this code
# run the function with all values as default, and 'name', 'data' and 'setnames' to be input by the user when prompted:
bayescount()

# analyse data using zero-inflated gamma Poisson and zero-inflated lognormal Poisson models in 5 text .csv files named 'mydata/data.*numer*.csv' with column labels, using sampling updates increasing in 10000 increments, and calculating the likelihoods:
for (i in 1:5){
	bayescount(name=paste("Data ", i, sep=""), data=paste("mydata/data.", i, ".csv", sep=""), model=c("ZIGP", "ZILP"), setnames=TRUE, updates = (1:10)*10000, test = FALSE, likelihood = TRUE)
}

Run the code above in your browser using DataLab