Calculate percentage change between two years using Bayesian output
Source:R/occurrenceChange.r
occurrenceChange.Rd
Using the data returned from occDetModel/occDetFunc this function models a trend between two years for each iteration of the models. Several options are available for the method used to calculate the trend. This distribution of the results is used to calculate the mean estimate and the 95
Usage
occurrenceChange(
bayesOut,
firstYear = NULL,
lastYear = NULL,
change = "growthrate",
region = NULL
)
Arguments
- bayesOut
occDet object as returned from occDetModel or occDetFunc.
- firstYear
numeric, the first year over which the change is to be estimated. Defaults to the final year in the dataset
- lastYear
numeric, the last year over which the change is to be estimated. Defaults to the first year in the dataset
- change
A character string that specifies the type of change to be calculated, the default is annual growth rate. See details for options.
- region
A character string specifying the region name if change is to be determined regional estimates of occupancy. Region names must match those in the model output.
Value
A list giving the mean, median, credible intervals and raw data from the estimations. It is recommended to use the median value.
Details
change
is used to specify which change measure to be calculated.
There are four options to choose from: difference, percentdif, growthrate and
lineargrowth.
difference
calculates the simple difference between the first and last year.
percentdif
calculates the percentage difference between the first and last year.
growthrate
calculates the annual growth rate across years.
lineargrowth
calculates the linear growth rate from a linear model.
Examples
if (FALSE) {
#' # Create data
n <- 15000 #size of dataset
nyr <- 20 # number of years in data
nSamples <- 100 # set number of dates
nSites <- 50 # set number of sites
# Create somes dates
first <- as.Date(strptime("1980/01/01", "%Y/%m/%d"))
last <- as.Date(strptime(paste(1980+(nyr-1),"/12/31", sep=''), "%Y/%m/%d"))
dt <- last-first
rDates <- first + (runif(nSamples)*dt)
# taxa are set as random letters
taxa <- sample(letters, size = n, TRUE)
# three sites are visited randomly
site <- sample(paste('A', 1:nSites, sep=''), size = n, TRUE)
# the date of visit is selected at random from those created earlier
survey <- sample(rDates, size = n, TRUE)
# run the model with these data for one species
results <- occDetModel(taxa = taxa,
site = site,
survey = survey,
species_list = c('a','m','g'),
write_results = FALSE,
n_iterations = 1000,
burnin = 10,
thinning = 2)
# estimate the change for one species
change <- occurrenceChange(firstYear = 1990,
lastYear = 1999,
bayesOut = results$a)
}