Skip to content

Commit

Permalink
Manage merge conflict in appveyor
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/BiologicalRecordsCentre/sparta

# Conflicts:
#	appveyor.yml
  • Loading branch information
AugustT committed Nov 23, 2021
2 parents 9f3932a + 9ed4673 commit 2973f6d
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 90 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: sparta
Type: Package
Title: Trend Analysis for Unstructured Data
Version: 0.2.14
Date: 2020-02-15
Version: 0.2.19
Date: 2020-05-26
Authors@R: c(person("Tom", "August", role = c("aut", "cre"), email = "[email protected]"),
person("Gary", "Powney", role = c("aut")),
person("Charlie", "Outhwaite", role = c("aut")),
Expand Down
8 changes: 6 additions & 2 deletions R/dataGaps.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ dataGaps<-function(years, minmod, maxmod, mindat, maxdat){
actualyears <- (years-1) + minmod
middleyears <- subset(actualyears,actualyears %in% seq(mindat,maxdat,1))
middleyears <- sort(unique(middleyears))
gap_middle <- max(diff(middleyears)-1)
if(length(middleyears)>1){
gap_middle <- max(diff(middleyears)-1)
} else {
gap_middle <- NA
}
return(list(gap_start=gap_start,gap_end=gap_end,gap_middle=gap_middle))
}
}
148 changes: 98 additions & 50 deletions R/occDetFunc.r

Large diffs are not rendered by default.

30 changes: 25 additions & 5 deletions R/occDetModel.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
#' @param site A character vector of site names, as long as the number of observations.
#' @param survey A vector as long as the number of observations.
#' This must be a Date if includeJDay = \code{TRUE}
#' @param replicate An optional vector to identify replicate samples (visits) per survey. Need not be globally unique (e.g can be 1, 2, .. n within surveys)
#' @param closure_period An optional vector of integers specifying the closure period.
#' If \code{FALSE} then closure_period will be extracted as the year from the survey.
#' @param criterion Determines whether the model should be run. If an integer then this defines the threshold number of records (50 in Outhwaite et al 2019).
#' Other options are `EqualWt` or `HighSpec`, which define the application of "rules of thumb" defined in Pocock et al 2019.
#' Defaults to 1, in which case the model is applied for so long there is a single record of the focal species.
#' @param provenance An optional text string allowing the user to identify the dataset.
#' @param rem_aggs_with_missing_regions An option which if TRUE will remove all aggregates which contain at least one region with no data.
#' @param allowSitesMultiRegions An option that permits sites to be included in more than one region. If `FALSE` then these sites are dropped.
#' @param species_list A character vector of taxa names for which models should be run. This is
#' optional and by default models will be run for all taxa
#' @param write_results logical, should results be saved to \code{output_dir}. This is
Expand Down Expand Up @@ -168,11 +177,16 @@
#' region_aggs = list(agg1 = c('region1', 'region2')))
#' }
#' @export
#' @references Roy, H.E., Adriaens, T., Isaac, N.J.B. et al. (2012) Invasive alien predator
#' causes rapid declines of native European ladybirds. Diversity & Distributions,
#' 18, 717-725.
#' @references Isaac, N.J.B., van Strien, A.J., August, T.A., de Zeeuw, M.P. and Roy, D.B. (2014).
#' Statistics for citizen science: extracting signals of change from noisy ecological data.
#' \emph{Methods in Ecology and Evolution}, 5: 1052-1060.
#' @references Outhwaite, C.L., Chandler, R.E., Powney, G.D., Collen, B., Gregory, R.D. & Isaac, N.J.B. (2018).
#' Prior specification in Bayesian occupancy modelling improves analysis of species occurrence data.
#' \emph{Ecological Indicators}, 93: 333-343.

occDetModel <- function(taxa, site, survey,
occDetModel <- function(taxa, site, survey,
replicate = NULL, closure_period = NULL, criterion = 1, provenance = NULL,
rem_aggs_with_missing_regions = TRUE, allowSitesMultiRegions = FALSE,
species_list = unique(taxa), write_results = TRUE,
output_dir = getwd(), nyr = 2, n_iterations = 5000,
burnin = 1500, thinning = 3, n_chains = 3,
Expand Down Expand Up @@ -202,6 +216,8 @@ occDetModel <- function(taxa, site, survey,
visitData <- formatOccData(taxa = taxa,
site = site,
survey = survey,
replicate = replicate,
closure_period = replicate,
includeJDay = includeJDay)

### loop through the species list running the Bayesian occupancy model function ###
Expand All @@ -228,7 +244,11 @@ occDetModel <- function(taxa, site, survey,
additional.parameters = additional.parameters,
additional.BUGS.elements = additional.BUGS.elements,
additional.init.values = additional.init.values,
return_data = return_data)
provenance = provenance,
criterion = criterion,
return_data = return_data,
rem_aggs_with_missing_regions = rem_aggs_with_missing_regions,
allowSitesMultiRegions = allowSitesMultiRegions)
}

class(output) <- 'occDetList'
Expand Down
33 changes: 23 additions & 10 deletions R/plot_DetectionOverTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@
#' @export


plot_DetectionOverTime <- function(model, spname = NULL, min.yr = NULL){
plot_DetectionOverTime <- function(model, spname = NULL, min.yr = NULL, CI=95){


# convert the CI into quantiles
# first check that CI is sensible
if((CI > 100) | (CI <= 0)) stop("Credible intervals must be between 0 and 100")
CI2q <- function(CI) {
q <- (1 - CI/100)/2
return(c(q, 1-q))
}
quant <- CI2q(CI)

sims_list <- model$BUGSoutput$sims.list

# the base: alpha.p is common to all models:
Expand All @@ -47,11 +57,14 @@ plot_DetectionOverTime <- function(model, spname = NULL, min.yr = NULL){
# the model was fitted with categorical list length
pDet2 <- pDet1 + sims_list$dtype2.p[,1]
pDet4 <- pDet1 + sims_list$dtype3.p[,1]
}
# there is also an option to ignore list length,
# in which case the probability of detection is assumed to be constant across surveys
# i.e. if the survey was systematic

} else {
# there is also an option to ignore list length,
# in which case the probability of detection is assumed to be constant across surveys
# i.e. if the survey was systematic
# in this case the there are no estimates for the other pDet values.
pDet2 <- pDet4 <- NA
}

pDet <- melt(list(pDet1, pDet2, pDet4))
names(pDet) <- c("it", "year", "lgt_pDet", "ListLength")
pDet$ListLength[pDet$ListLength==3] <- 4 # the "third" category is for a list of length 4
Expand All @@ -61,9 +74,9 @@ plot_DetectionOverTime <- function(model, spname = NULL, min.yr = NULL){
# now summarize these posterior distributions
pDet_summary <-ddply(
pDet, .(year, ListLength), summarise,
mean_pDet = mean(pDet),
lower95CI = quantile(pDet, 0.025),
upper95CI = quantile(pDet, 0.975))
mean_pDet = mean(pDet, na.rm=T),
lower95CI = quantile(pDet, quant[1], na.rm=T),
upper95CI = quantile(pDet, quant[2], na.rm=T))

# if the user has supplied a year then switch the x axis to start at that minimum
if(!is.null(min.yr)) pDet_summary$year <- pDet_summary$year + min.yr - 1
Expand All @@ -75,7 +88,7 @@ plot_DetectionOverTime <- function(model, spname = NULL, min.yr = NULL){
ylab("Detection probability") +
ggtitle(spname) +
theme_bw()
gp
gp

}

Expand Down
23 changes: 12 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ environment:
# Adapt as necessary starting from here

matrix:
- R_VERSION: devel
NOT_CRAN: true
R_CHECK_ARGS: "--no-manual"
USE_RTOOLS: true
WARNINGS_AS_ERRORS: OFF

- R_VERSION: devel
NOT_CRAN: true
R_CHECK_ARGS: "--no-manual"
USE_RTOOLS: true
WARNINGS_AS_ERRORS: OFF

# - R_VERSION: devel
# NOT_CRAN: true
# R_CHECK_ARGS: "--no-manual"
# USE_RTOOLS: true
# WARNINGS_AS_ERRORS: OFF

# - R_VERSION: devel
# NOT_CRAN: true
# R_CHECK_ARGS: "--no-manual"
# USE_RTOOLS: true
# WARNINGS_AS_ERRORS: OFF

- R_VERSION: stable
NOT_CRAN: false
USE_RTOOLS: true
Expand Down
16 changes: 12 additions & 4 deletions man/occDetFunc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions man/occDetModel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot_DetectionOverTime.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/testoccDetFunc.r
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ test_that("Test occDetFunc using regions and region aggregates", {
modeltype = c("ranwalk", "halfcauchy"),
regional_codes = regionsmulti,
region_aggs = list(agg1 = c('region1', 'region2'))),
'sites are not assigned to a region in regional_codes and will be removed')
'1 sites are not assigned to a region in regional_codes and will be removed')

# test for sites in occurence data but not regions
regionsmissing <- regionsDF[2:50,]
Expand All @@ -551,7 +551,7 @@ test_that("Test occDetFunc using regions and region aggregates", {
modeltype = c("ranwalk", "halfcauchy"),
regional_codes = regionsmissing,
region_aggs = list(agg1 = c('region1', 'region2'))),
'1 sites are in occurrence data but not in regional data and will be removed')
'1 sites are in occurrence data but not in regional_codes and will be removed')

# test for regional aggregate containing unknown region
expect_error(results <- occDetFunc(taxa_name = 'a',
Expand Down

0 comments on commit 2973f6d

Please sign in to comment.