Skip to content

Commit

Permalink
include jsdgam example in pkgdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed Nov 1, 2024
1 parent e930afc commit fd8b1cf
Show file tree
Hide file tree
Showing 89 changed files with 685 additions and 936 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
^tests/testthat/Rplots\.pdf$
^tests/local$
^memcheck\.R$
*.gcda
^src\.gcda$
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Meta
/Meta/
desktop.ini
^cran-comments\.md$
*.gcda
^src\.gcda$
51 changes: 37 additions & 14 deletions R/jsdgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#'for other functions in the package. See \code{\link{mvgam-class}} for details.
#'Use `methods(class = "mvgam")` for an overview on available methods
#'@examples
#'\dontrun{
#'\donttest{
#' # Simulate latent count data for 500 spatial locations and 10 species
#' set.seed(0)
#' N_points <- 500
Expand Down Expand Up @@ -175,10 +175,10 @@
#'
#' # Poisson observations
#' family = poisson())
#' priors
#' head(priors)
#'
#' # Fit a JSDM that estimates a hierarchical temperature responses
#' # and that uses three latent spatial factors
#' # and that uses four latent spatial factors
#' mod <- jsdgam(formula = count ~
#' # Environmental model includes species-level intercepts
#' # and random slopes for a linear effect of temperature
Expand All @@ -188,7 +188,7 @@
#' # Each factor estimates a different nonlinear spatial process, using
#' # 'by = trend' as in other mvgam State-Space models
#' factor_formula = ~ te(lat, lon, k = 5, by = trend) - 1,
#' n_lv = 3,
#' n_lv = 4,
#'
#' # Change default priors for fixed effect betas to standard normal
#' priors = prior(std_normal(), class = b),
Expand All @@ -199,7 +199,9 @@
#' subgr = species,
#'
#' # Poisson observations
#' family = poisson())
#' family = poisson(),
#' chains = 2,
#' silent = 2)
#'
#' # Plot species-level intercept estimates
#' plot_predictions(mod, condition = 'species',
Expand All @@ -209,18 +211,18 @@
#' plot_predictions(mod, condition = c('temperature', 'species', 'species'),
#' type = 'link')
#'
#' # Plotting species' average geographical predictions against the observed
#' # data gives some idea of whether more flexibility in the spatial process
#' # may be needed
#' plot_predictions(mod, condition = c('lat', 'species', 'species'),
#' points = 0.5)
#' plot_predictions(mod, condition = c('lon', 'species', 'species'),
#' points = 0.5)
#' # Plot posterior median estimates of the latent spatial factors
#' plot(mod, type = 'smooths', trend_effects = TRUE)
#'
#' # Or using gratia, if you have it installed
#' if(requireNamespace('gratia', quietly = TRUE)){
#' gratia::draw(mod, trend_effects = TRUE)
#' }
#'
#' # Calculate (median) residual spatial correlations
#' med_loadings <- matrix(apply(as.matrix(mod$model_output, 'lv_coefs'),
#' 2, median),
#' nrow = N_species, ncol = 3)
#' nrow = N_species, ncol = 4)
#' cormat <- cov2cor(tcrossprod(med_loadings))
#' rownames(cormat) <- colnames(cormat) <- levels(dat$species)
#'
Expand All @@ -232,8 +234,29 @@
#'
#' # Posterior predictive checks and ELPD-LOO can ascertain model fit
#' pp_check(mod, type = "ecdf_overlay_grouped",
#' group = "species", ndraws = 50)
#' group = "species", ndraws = 100)
#' loo(mod)
#'
#' # Forecast log(counts) for entire region (site value doesn't matter as long
#' # as each spatial location has a different and unique site identifier);
#' # note this calculation takes a few minutes because of the need to calculate
#' # draws from the stochastic latent factors
#' newdata <- st_process %>%
#' dplyr::mutate(species = factor(species,
#' levels = paste0('species_',
#' 1:N_species))) %>%
#' dplyr::group_by(lat, lon) %>%
#' dplyr::mutate(site = dplyr::cur_group_id()) %>%
#' dplyr::ungroup()
#' preds <- predict(mod, newdata = newdata)
#'
#' # Plot the median log(count) predictions on a grid
#' newdata$log_count <- preds[,1]
#' ggplot(newdata, aes(x = lat, y = lon, col = log_count)) +
#' geom_point(size = 1.5) +
#' facet_wrap(~ species, scales = 'free') +
#' viridis::scale_color_viridis() +
#' theme_classic()
#'}
#'@export
jsdgam = function(formula,
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/GP.html

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

4 changes: 2 additions & 2 deletions docs/reference/RW.html

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

4 changes: 2 additions & 2 deletions docs/reference/ZMVN.html

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

Binary file modified docs/reference/figures/README-unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-13-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-17-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-18-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-19-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-20-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-21-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-22-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-23-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/figures/README-unnamed-chunk-24-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/reference/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/forecast.mvgam-9.png
Loading

0 comments on commit fd8b1cf

Please sign in to comment.