Skip to content

Commit

Permalink
Merge branch 'master' into pull_requests
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanCarbone committed Apr 9, 2024
2 parents 297dce4 + f2b1479 commit 2dd3fbe
Show file tree
Hide file tree
Showing 24 changed files with 2,922 additions and 853 deletions.
Binary file removed .RData
Binary file not shown.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ frescalo.exe
^docs$
misc/
^appveyor\.yml$
^\.github$
^doc$
^Meta$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
51 changes: 51 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [master, pull_requests]
pull_request:
branches: [master, pull_requests]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-build-vignettes", "--no-manual")'
args: 'c("--no-vignettes", "--no-manual")'
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# History files
# History files and data files
.Rhistory
.Rdata

# Example code in package build process
*-Ex.R
Expand All @@ -11,3 +12,5 @@ frescalo.exe
sparta.Rproj

misc/
/doc/
/Meta/
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

67 changes: 42 additions & 25 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
Package: sparta
Type: Package
Package: sparta
Title: Trend Analysis for Unstructured Data
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")),
person("Colin", "Harrower", role = c("aut")),
person("Mark", "Hill", role = c("aut")),
person("Jack", "Hatfield", role = c("aut")),
person("Francesca", "Mancini", role = c("aut")),
person("Nick", "Isaac", role = c("aut")))
Maintainer: Tom August <[email protected]>
Description: Methods used to analyse trends in unstructured
occurrence datasets such as those collected by volunteer recording
schemes.
Authors@R: c(
person("Dylan", "Carbone", email = "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0009-0003-5290-786X")),
person("Tom", "August", email = "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1116-3385")),
person("Gary", "Powney", role = "aut",
comment = c(ORCID = "0000-0003-3313-7786")),
person("Charlie", "Outhwaite", role = "aut",
comment = c(ORCID = "0000-0001-9997-6780")),
person("Jack", "Hatfield", role = "aut",
comment = c(ORCID = "0000-0002-6361-0629")),
person("Nick", "Isaac", role = "aut",
comment = c(ORCID = "0000-0002-4869-8052")),
person("Francesca", "Mancini", role = "aut",
comment = c(ORCID = "0000-0003-4085-4978")),
person("Mark", "Hill", role = "aut",
comment = c(ORCID = "0000-0002-3323-4458")),
person("Colin", "Harrower", role = "aut",
comment = c(ORCID = "0000-0001-5070-5293"))
)
Maintainer: Dylan Carbone <[email protected]>
Description: Methods used to analyse trends in unstructured occurrence
datasets such as those collected by volunteer recording schemes.
License: MIT + file LICENSE
URL: https://github.com/BiologicalRecordsCentre/sparta
BugReports: https://github.com/BiologicalRecordsCentre/sparta/issues
Depends:
R (>= 3.1.0),
lme4 (>= 1.0)
lme4 (>= 1.0),
R (>= 3.5.0)
Imports:
plyr,
boot,
dplyr (>= 0.4.1),
sp,
reshape2,
ggplot2,
gdata,
ggplot2,
LearnBayes,
plyr,
reshape2,
rmarkdown,
boot
sp,
xfun (>= 0.4.3)
Suggests:
testthat (>= 0.8.0),
roxygen2,
knitr,
R2jags
VignetteBuilder: knitr
R2jags,
roxygen2,
testthat (>= 0.8.0),
VignetteBuilder:
knitr
Encoding: UTF-8
LazyData: TRUE
RoxygenNote: 7.2.3
Encoding: UTF-8
SystemRequirements: JAGS
(https://sourceforge.net/projects/mcmc-jags/files/JAGS/)
4 changes: 2 additions & 2 deletions R/plot_DetectionOverTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#' @param model a fitted sparta model of class \code{OccDet}.
#' @param spname optional name of the species (used for plotting)
#' @param bins number of points to estimate across the year. Defaults to 12
#' @param density_function whether the model used a density function to fit Julian date. This form was implemented from version 0.1.48 onwards. For models ran using earlier versions of the package this should be set to FALSE
#' @param min.yr Minimum year for the detection (e.g., 1990).
#' @param CI Confidence interval
#'
#' @details
#' Takes a object of \code{OccDet}
Expand Down
87 changes: 44 additions & 43 deletions R/plot_DetectionPhenology.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#' Diagnostics for the detectability with respect to Julian Date
#'
#' Diagnostics for the detectability with respect to Julian Date
#'
#' Creates a plot of detectability over the season and calculates some simple statistics
#'
#' @param model a fitted sparta model of class \code{OccDet}.
#' @param spname optional name of the species (used for plotting)
#' @param bins number of points to estimate across the year. Defaults to 12
#' @param density_function whether the model used a density function to fit Julian date. This form was implemented from version 0.1.48 onwards. For models ran using earlier versions of the package this should be set to FALSE
#'
#' @details
#'
#' @details
#' Takes a object of \code{OccDet} fitted with the \code{jul_date} option
#'
#'
#' Calculates the phenology of detection and produces a plot of detectability over time for the reference data type.
#'
#' @return This function returns plot showing the detection probability on the y axis and Julian day on the x.
#' The data within the output list shows the Julian day for each point estimated (equal to the number of bins)
#' and the mean detection probability with 95% credible intervals.
#'
#' @references van Strien, A.J., Termaat, T., Groenendijk, D., Mensing, V. & Kéry, M. (2010)
#' Site-occupancy models may offer new opportunities for dragonfly monitoring based on daily species lists.
#'
#' @references van Strien, A.J., Termaat, T., Groenendijk, D., Mensing, V. & Kéry, M. (2010)
#' Site-occupancy models may offer new opportunities for dragonfly monitoring based on daily species lists.
#' \emph{Basic and Applied Ecology}, 11, 495–503.
#'
#' @importFrom reshape2 melt
#' @importFrom reshape2 melt
#' @importFrom plyr ddply
#' @importFrom ggplot2 ggplot
#' @importFrom boot inv.logit
Expand All @@ -34,64 +34,65 @@
###########################################


plot_DetectionPhenology <- function(model, spname=NULL, bins=12, density_function = TRUE){

plot_DetectionPhenology <- function(model, spname = NULL, bins = 12, density_function = TRUE) {
data <- model$BUGSoutput$sims.list
if(!"beta1" %in% names(data))

if (!"beta1" %in% names(data)) {
stop("no phenological effect was modelled!")
}

# the base: alpha.p is common to all models:
# the base: alpha.p is common to all models:
# it's the logit probability of detection on a single species list
# use the average value across years
pDet1 <- rowMeans(data$alpha.p)
# pDet1 is an array of dims equal to (niter, nyr)

# Julian dates are 1:
jul_dates <- seq(from=1, to=365, length.out=bins)
if(density_function == TRUE){
if(!"beta3" %in% names(data))
jul_dates <- seq(from = 1, to = 365, length.out = bins)

if (density_function == TRUE) {
if (!"beta3" %in% names(data)) {
stop("beta3 not found. Please check that the density function method was used")
}
# we ran the Julian Date option
# So let's calculate the detection probabilities
pDet <- melt(sapply(jul_dates, function(jd){
pDet1 + data$beta3[,1] * (1/((2*pi)^0.5 * data$beta2[,1]) * exp(-((jd - data$beta1[,1])^2 / (2* data$beta2[,1]^2))))

pDet <- melt(sapply(jul_dates, function(jd) {
pDet1 + data$beta3[, 1] * (1 / ((2 * pi)^0.5 * data$beta2[, 1]) * exp(-((jd - data$beta1[, 1])^2 / (2 * data$beta2[, 1]^2))))
}))
}else{
} else {
cjd <- jul_dates - 182
# we ran the Julian Date option
# So let's scale the detection probabilities to end June (day 180)
pDet <- melt(sapply(cjd, function(jd){
pDet1 + jd * data$beta1[,1] + jd^2 * data$beta2[,1]
}))
pDet <- melt(sapply(cjd, function(jd) {
pDet1 + jd * data$beta1[, 1] + jd^2 * data$beta2[, 1]
}))
}
names(pDet) <- c("it", "bin","lgt_pDet")

names(pDet) <- c("it", "bin", "lgt_pDet")
pDet$pDet <- inv.logit(pDet$lgt_pDet)

# now summarize these posterior distributions
pDet_summary <-ddply(
pDet, .(bin), summarise,
pDet_summary <- ddply(
pDet, .(bin), summarise,
mean_pDet = mean(pDet),
lower95CI = quantile(pDet, 0.025),
upper95CI = quantile(pDet, 0.975))

# now convert the jds back to their equivalent Julian Dates
if(density_function == FALSE){pDet_summary$cJulDate <- cjd[pDet_summary$bin]}
pDet_summary$JulianDay <- jul_dates[pDet_summary$bin]
upper95CI = quantile(pDet, 0.975)
)

# now convert the jds back to their equivalent Julian Dates
if (density_function == FALSE) {
pDet_summary$cJulDate <- cjd[pDet_summary$bin]
}
pDet_summary$JulianDay <- jul_dates[pDet_summary$bin]

# now plot the detection over time
gp <- ggplot(data=pDet_summary, x=JulianDay, y=mean_pDet) +
geom_line(aes(x=JulianDay, y=mean_pDet)) +
geom_ribbon(aes(x=JulianDay, ymin=lower95CI, ymax=upper95CI), alpha=0.2) +
gp <- ggplot(data = pDet_summary, x = JulianDay, y = mean_pDet) +
geom_line(aes(x = JulianDay, y = mean_pDet)) +
geom_ribbon(aes(x = JulianDay, ymin = lower95CI, ymax = upper95CI), alpha = 0.2) +
ylab("Detection probability") +
ggtitle(spname) +
theme_bw()
gp

# calculate some simple stats

return(gp)
}

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
![Sparta banner](https://raw.githubusercontent.com/AugustT/sparta/master/logo.png)

<!-- badges: start -->
[![Travis Build Status](https://travis-ci.org/BiologicalRecordsCentre/sparta.svg)](https://travis-ci.org/BiologicalRecordsCentre/sparta)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/augustt/sparta?branch=master&svg=true)](https://ci.appveyor.com/project/augustt/sparta)
[![codecov.io](https://codecov.io/github/BiologicalRecordsCentre/sparta/coverage.svg?branch=master)](https://codecov.io/github/BiologicalRecordsCentre/sparta?branch=master)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R-CMD-check](https://github.com/DylanCarbone/sparta/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/DylanCarbone/sparta/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

This R package includes methods used to analyse trends in unstructured occurrence datasets and a range of useful functions for mapping such data in the UK. The package is under continious development, but you can find stable releases in the release section. Note that frescalo currently uses an .exe compiled only for windows.
Expand Down
Loading

0 comments on commit 2dd3fbe

Please sign in to comment.