From 51ca352ade977e4d0478f03f602ae799cf3ccb2d Mon Sep 17 00:00:00 2001 From: DylanCarbone Date: Fri, 17 May 2024 11:55:32 +0100 Subject: [PATCH] revert back to itemize tag; new example for htmlSummary --- Occ_viz_html.html | 456 +++++++++++++++++++++++++++++++++++++++++++++ R/WSS.r | 2 +- R/htmlSummary.R | 44 ++++- R/occDetFunc.r | 4 +- man/WSS.Rd | 2 +- man/htmlSummary.Rd | 42 +++++ man/occDetFunc.Rd | 4 +- 7 files changed, 547 insertions(+), 7 deletions(-) create mode 100644 Occ_viz_html.html diff --git a/Occ_viz_html.html b/Occ_viz_html.html new file mode 100644 index 0000000..ba6453f --- /dev/null +++ b/Occ_viz_html.html @@ -0,0 +1,456 @@ + + + + + + + + + + + + + + +Occupancy model summary + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +

This is a visualiation of an occupancy model produced using the +r-package sparta. For more information of +sparta visit https://github.com/biologicalrecordscentre/sparta

+
+

Table of contents

+
    +
  1. Basic Information
  2. +
  3. Species trend
  4. +
  5. Traceplots - +Annnual occupancy estimates
  6. +
  7. Traceplots - +Annnual detectability estimates
  8. +
  9. Traceplots - Other +parameters
  10. +
  11. Rhat values
  12. +
+
+

Basic Information

+
## Species: a
+
## Year range: 1980 - 1999
+
## Iterations: 1000
+
## Chains: 3
+
## Burn in: 10
+
## Thinning: 2
+
## Number of sites: 50
+
## Number of visits: 4704
+
## Number of sites with records of a:
+
## Number of observations of a: 571
+
+
+

Species trend

+

+
+
+

Traceplots - Annnual occupancy estimates

+

+
+
+

Traceplots - Annnual detectability estimates

+

+
+
+

Traceplots - Other parameters

+

+
+
+

Rhat values

+

+
+
+ + + + +
+ + + + + + + + + + + + + + + diff --git a/R/WSS.r b/R/WSS.r index e319503..aa3e66f 100644 --- a/R/WSS.r +++ b/R/WSS.r @@ -32,7 +32,7 @@ #' #' The data.frame has a number of attributes: #' -#' \describe{ +#' \itemize{ #' \item{\code{intercept_year}}{ - The year used for the intercept (i.e. the #' year whose value is set to 0). Setting the intercept to the median year helps #' to increase model stability} diff --git a/R/htmlSummary.R b/R/htmlSummary.R index 5a5d183..a4bbff9 100644 --- a/R/htmlSummary.R +++ b/R/htmlSummary.R @@ -10,8 +10,50 @@ #' @param ... Additional arguments passed to rmarkdown::render #' #' @return Path to html report -#' @export #' @import rmarkdown +#' +#' @examples +#' +#' \dontrun{ +#' # Create data +#' set.seed(125) +#' 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 +#' # using defaults +#' results <- occDetModel(taxa = taxa, +#' site = site, +#' survey = survey, +#' species_list = 'a', +#' write_results = TRUE, +#' n_iterations = 1000, +#' burnin = 10, +#' thinning = 2) +#' +#' generate summary +#' htmlSummary(results$a) +#' +#' } +#' +#' @export htmlSummary <- function(occDet, open = TRUE, diff --git a/R/occDetFunc.r b/R/occDetFunc.r index ead21c3..bb41dc8 100644 --- a/R/occDetFunc.r +++ b/R/occDetFunc.r @@ -79,7 +79,7 @@ #' a combination that is not supported. There is usually a good reason why that #' combination is not a good idea. Here are the model elements available: #' -#' \describe{ +#' \itemize{ #' \item{\code{"sparta"}}{ - This uses the same model as in Isaac et al (2014)} #' \item{\code{"indran"}}{ - Here the prior for the year effect of the state model is modelled as a random effect. This allows the model to adapt to interannual variability.} #' \item{\code{"ranwalk"}}{ - Here the prior for the year effect of the state model is modelled as a random walk. Each estimate for the year effect is dependent on that of the previous year.} @@ -96,7 +96,7 @@ #' #' @return A list including the model, JAGS model output, the path of the model file used and information on the number of iterations, first year, last year, etc. #' Key aspects of the model output include: -#' \describe{ +#' \itemize{ #' \item{\code{"out$model"}}{ - The model used as provided to JAGS. Also contained is a list of fully observed variables. These are those listed in the BUGS data.} #' \item{\code{"out$BUGSoutput$n.chains"}}{ - The number of Markov chains ran in the MCMC simulations.} #' \item{\code{"out$BUGSoutput$n.iter"}}{ - The total number of iterations per chain.} diff --git a/man/WSS.Rd b/man/WSS.Rd index 4038d99..f59a306 100644 --- a/man/WSS.Rd +++ b/man/WSS.Rd @@ -56,7 +56,7 @@ A dataframe of results are returned to R. Each row gives the results for a The data.frame has a number of attributes: - \describe{ + \itemize{ \item{\code{intercept_year}}{ - The year used for the intercept (i.e. the year whose value is set to 0). Setting the intercept to the median year helps to increase model stability} diff --git a/man/htmlSummary.Rd b/man/htmlSummary.Rd index c928b9e..a7299aa 100644 --- a/man/htmlSummary.Rd +++ b/man/htmlSummary.Rd @@ -24,3 +24,45 @@ Path to html report \description{ Create HTML Report for an \code{occDet} object. } +\examples{ + +\dontrun{ +# Create data +set.seed(125) +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 +# using defaults +results <- occDetModel(taxa = taxa, + site = site, + survey = survey, + species_list = 'a', + write_results = TRUE, + n_iterations = 1000, + burnin = 10, + thinning = 2) + +generate summary +htmlSummary(results$a) + +} + +} diff --git a/man/occDetFunc.Rd b/man/occDetFunc.Rd index 44432b2..2013c17 100644 --- a/man/occDetFunc.Rd +++ b/man/occDetFunc.Rd @@ -108,7 +108,7 @@ If `FALSE`, only aggregates where ALL regions in that aggregate contain no data, \value{ A list including the model, JAGS model output, the path of the model file used and information on the number of iterations, first year, last year, etc. Key aspects of the model output include: -\describe{ +\itemize{ \item{\code{"out$model"}}{ - The model used as provided to JAGS. Also contained is a list of fully observed variables. These are those listed in the BUGS data.} \item{\code{"out$BUGSoutput$n.chains"}}{ - The number of Markov chains ran in the MCMC simulations.} \item{\code{"out$BUGSoutput$n.iter"}}{ - The total number of iterations per chain.} @@ -171,7 +171,7 @@ Not all combinations are available in sparta. You will get an error if you try a a combination that is not supported. There is usually a good reason why that combination is not a good idea. Here are the model elements available: -\describe{ +\itemize{ \item{\code{"sparta"}}{ - This uses the same model as in Isaac et al (2014)} \item{\code{"indran"}}{ - Here the prior for the year effect of the state model is modelled as a random effect. This allows the model to adapt to interannual variability.} \item{\code{"ranwalk"}}{ - Here the prior for the year effect of the state model is modelled as a random walk. Each estimate for the year effect is dependent on that of the previous year.}