Skip to content

Commit

Permalink
update neonDWP
Browse files Browse the repository at this point in the history
  • Loading branch information
doserjef committed Dec 15, 2023
1 parent 08e085a commit 34896ce
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 103 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: spAbundance
Type: Package
Title: Univariate and Multivariate Spatial Modeling of Species Abundance
Version: 0.1.0
Version: 0.1.1
Authors@R: c(person("Jeffrey", "Doser", role=c("aut", "cre"), email="[email protected]"), person("Andrew", "Finley", role = c("aut")))
Description: Fits single-species (univariate) and multi-species (multivariate) non-spatial and spatial abundance models in a Bayesian framework using Markov Chain Monte Carlo (MCMC). Spatial models are fit using Nearest Neighbor Gaussian Processes (NNGPs). Details on NNGP models are given in Datta, Banerjee, Finley, and Gelfand (2016) <doi:10.1080/01621459.2015.1044091> and Finley, Datta, and Banerjee (2020) <arXiv:2001.09111>. Fits single-species and multi-species spatial and non-spatial versions of generalized linear mixed models (Gaussian, Poisson, Negative Binomial), N-mixture models (Royle 2004 <doi:10.1111/j.0006-341X.2004.00142.x>) and hierarchical distance sampling models (Royle, Dawson, Bates (2004) <doi:10.1890/03-3127>). Multi-species spatial models are fit using a spatial factor modeling approach with NNGPs for computational efficiency.
License: GPL (>= 3)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# spAbundance 0.1.1

+ Updated the `neonDWP` data set after NEON announced an error in some of the bird point count data (more information [here](https://www.neonscience.org/impact/observatory-blog/bird-point-ids-within-grids-were-transposed-resulting-inaccurate-point).

# spAbundance 0.1.0

+ This is the first release of `spAbundance`
10 changes: 5 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ All model fitting functions allow for Poisson and negative binomial distribution

### Load package and data

To get started with `spAbundance` we load the package and an example data set. We use data on 16 birds from the [Disney Wilderness Preserve](https://www.neonscience.org/field-sites/dsny) in Central Florida, USA, which is available in the `spAbundance` package as the `neonDWP` object. Here we will only work with one bird species, the Eastern Meadowlark (EAME), and so we subset the `neonDWP` object to only include this species.
To get started with `spAbundance` we load the package and an example data set. We use data on 16 birds from the [Disney Wilderness Preserve](https://www.neonscience.org/field-sites/dsny) in Central Florida, USA, which is available in the `spAbundance` package as the `neonDWP` object. Here we will only work with one bird species, the Mourning Dove (MODO), and so we subset the `neonDWP` object to only include this species.

```{r}
library(spAbundance)
Expand All @@ -85,7 +85,7 @@ dat.MODO$y <- dat.MODO$y[sp.names == "MODO", , ]

### Fit a spatial hierarchical distance sampling model using `spDS()`

Below we fit a single-species spatially-explicit hierarchical distance sampling model to the MODO data using a Nearest Neighbor Gaussian Process. We use the default priors and initial values for the abundance (`beta`) and detection (`alpha`) coefficients, the spatial variance (`sigma.sq`), the spatial range parameter (`phi`), the spatial random effects (`w`), and the latent abundance values (`z`). We also include an offset in `dat.MODO` to provide estimates of density on a per hectare basis. We model abundance as a function of local forest cover and grassland cover, along with a spatial random intercept. We model detection probability as a function of linear and quadratic day of survey and a linear effect of wind.
Below we fit a single-species spatially-explicit hierarchical distance sampling model to the MODO data using a Nearest Neighbor Gaussian Process. We use the default priors and initial values for the abundance (`beta`) and detection (`alpha`) coefficients, the spatial variance (`sigma.sq`), the spatial decay parameter (`phi`), the spatial random effects (`w`), and the latent abundance values (`N`). We also include an offset in `dat.MODO` to provide estimates of density on a per hectare basis. We model abundance as a function of local forest cover and grassland cover, along with a spatial random intercept. We model detection probability as a function of linear and quadratic day of survey and a linear effect of wind.

```{r}
# Specify model formulas
Expand Down Expand Up @@ -123,15 +123,15 @@ summary(ppc.out)

### Model selection using WAIC

The `waicAbund` function computes the Widely Applicable Information Criterion (WAIC) for use in model selection and assessment (note that due to Monte Carlo error your results will differ slightly).
The `waicAbund` function computes the Widely Applicable Information Criterion (WAIC) for use in model selection and assessment.

```{r}
waicAbund(out)
```

### Prediction

Prediction is possible using the `predict` function, a set of covariates at the desired prediction locations, and the spatial coordinates of the locations. The object `neonPredData` contains percent forest cover and grassland cover across the Disney Wildnerness Preserve. Below we predict MODO densityacross the preserve, which is stored in the `out.pred` object.
Prediction is possible using the `predict` function, a set of covariates at the desired prediction locations, and the spatial coordinates of the locations. The object `neonPredData` contains percent forest cover and grassland cover across the Disney Wildnerness Preserve. Below we predict MODO density across the preserve, which is stored in the `out.pred` object.

```{r, eval = FALSE}
# First standardize elevation using mean and sd from fitted model
Expand All @@ -153,7 +153,7 @@ The `vignette("distanceSampling")`, `vignette("nMixtureModels")`, and `vignette(

Please cite `spAbundance` as:

Doser, J. W., Finley, A. O., Kéry, M., and Zipkin, E. F. (2023). spAbundance: An R package for univariate and multivariate spatially-explicit abundance models. arXiv Preprint.
Doser, J. W., Finley, A. O., Kéry, M., and Zipkin, E. F. (2023). spAbundance: An R package for single-species and multi-species spatially-explicit abundance models. arXiv Preprint.

## References

Expand Down
12 changes: 6 additions & 6 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ <h2 id="functionality">Functionality</h2>
<p>All model fitting functions allow for Poisson and negative binomial distributions for the abundance portion of the model. All GLM(M)s also allow for Gaussian and zero-inflated Gaussian models. Note the two functions for fitting spatailly-varying coefficient models are only available for Gaussian and zero-inflated Gaussian models.</p>
<h2 id="example-usage">Example usage</h2>
<h3 id="load-package-and-data">Load package and data</h3>
<p>To get started with <code>spAbundance</code> we load the package and an example data set. We use data on 16 birds from the <a href="https://www.neonscience.org/field-sites/dsny">Disney Wilderness Preserve</a> in Central Florida, USA, which is available in the <code>spAbundance</code> package as the <code>neonDWP</code> object. Here we will only work with one bird species, the Eastern Meadowlark (EAME), and so we subset the <code>neonDWP</code> object to only include this species.</p>
<p>To get started with <code>spAbundance</code> we load the package and an example data set. We use data on 16 birds from the <a href="https://www.neonscience.org/field-sites/dsny">Disney Wilderness Preserve</a> in Central Florida, USA, which is available in the <code>spAbundance</code> package as the <code>neonDWP</code> object. Here we will only work with one bird species, the Mourning Dove (MODO), and so we subset the <code>neonDWP</code> object to only include this species.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">library</span>(spAbundance)</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a><span class="co"># Set seed to get exact same results</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a><span class="kw">set.seed</span>(<span class="dv">100</span>)</span>
Expand All @@ -735,7 +735,7 @@ <h3 id="load-package-and-data">Load package and data</h3>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>dat.MODO &lt;-<span class="st"> </span>neonDWP</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>dat.MODO<span class="op">$</span>y &lt;-<span class="st"> </span>dat.MODO<span class="op">$</span>y[sp.names <span class="op">==</span><span class="st"> &quot;MODO&quot;</span>, , ]</span></code></pre></div>
<h3 id="fit-a-spatial-hierarchical-distance-sampling-model-using-spds">Fit a spatial hierarchical distance sampling model using <code>spDS()</code></h3>
<p>Below we fit a single-species spatially-explicit hierarchical distance sampling model to the MODO data using a Nearest Neighbor Gaussian Process. We use the default priors and initial values for the abundance (<code>beta</code>) and detection (<code>alpha</code>) coefficients, the spatial variance (<code>sigma.sq</code>), the spatial range parameter (<code>phi</code>), the spatial random effects (<code>w</code>), and the latent abundance values (<code>z</code>). We also include an offset in <code>dat.MODO</code> to provide estimates of density on a per hectare basis. We model abundance as a function of local forest cover and grassland cover, along with a spatial random intercept. We model detection probability as a function of linear and quadratic day of survey and a linear effect of wind.</p>
<p>Below we fit a single-species spatially-explicit hierarchical distance sampling model to the MODO data using a Nearest Neighbor Gaussian Process. We use the default priors and initial values for the abundance (<code>beta</code>) and detection (<code>alpha</code>) coefficients, the spatial variance (<code>sigma.sq</code>), the spatial decay parameter (<code>phi</code>), the spatial random effects (<code>w</code>), and the latent abundance values (<code>N</code>). We also include an offset in <code>dat.MODO</code> to provide estimates of density on a per hectare basis. We model abundance as a function of local forest cover and grassland cover, along with a spatial random intercept. We model detection probability as a function of linear and quadratic day of survey and a linear effect of wind.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="co"># Specify model formulas</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a>MODO.abund.formula &lt;-<span class="st"> </span><span class="er">~</span><span class="st"> </span><span class="kw">scale</span>(forest) <span class="op">+</span><span class="st"> </span><span class="kw">scale</span>(grass) </span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>MODO.det.formula &lt;-<span class="st"> </span><span class="er">~</span><span class="st"> </span><span class="kw">scale</span>(day) <span class="op">+</span><span class="st"> </span><span class="kw">I</span>(<span class="kw">scale</span>(day)<span class="op">^</span><span class="dv">2</span>) <span class="op">+</span><span class="st"> </span><span class="kw">scale</span>(wind)</span></code></pre></div>
Expand Down Expand Up @@ -763,7 +763,7 @@ <h3 id="fit-a-spatial-hierarchical-distance-sampling-model-using-spds">Fit a spa
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true"></a><span class="co">#&gt; Thinning Rate: 5</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true"></a><span class="co">#&gt; Number of Chains: 3</span></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true"></a><span class="co">#&gt; Total Posterior Samples: 6000</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true"></a><span class="co">#&gt; Run Time (min): 1.71</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true"></a><span class="co">#&gt; Run Time (min): 4.2247</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true"></a><span class="co">#&gt; </span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true"></a><span class="co">#&gt; Abundance (log scale): </span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true"></a><span class="co">#&gt; Mean SD 2.5% 50% 97.5% Rhat ESS</span></span>
Expand Down Expand Up @@ -799,14 +799,14 @@ <h3 id="posterior-predictive-check">Posterior predictive check</h3>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a><span class="co">#&gt; Bayesian p-value: 0.5208 </span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a><span class="co">#&gt; Fit statistic: freeman-tukey</span></span></code></pre></div>
<h3 id="model-selection-using-waic">Model selection using WAIC</h3>
<p>The <code>waicAbund</code> function computes the Widely Applicable Information Criterion (WAIC) for use in model selection and assessment (note that due to Monte Carlo error your results will differ slightly).</p>
<p>The <code>waicAbund</code> function computes the Widely Applicable Information Criterion (WAIC) for use in model selection and assessment.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="kw">waicAbund</span>(out)</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a><span class="co">#&gt; N.max not specified. Setting upper index of integration of N to 10 plus</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a><span class="co">#&gt; the largest estimated abundance value at each site in object$N.samples</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a><span class="co">#&gt; elpd pD WAIC </span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a><span class="co">#&gt; -168.03803 13.45534 362.98673</span></span></code></pre></div>
<h3 id="prediction">Prediction</h3>
<p>Prediction is possible using the <code>predict</code> function, a set of covariates at the desired prediction locations, and the spatial coordinates of the locations. The object <code>neonPredData</code> contains percent forest cover and grassland cover across the Disney Wildnerness Preserve. Below we predict MODO densityacross the preserve, which is stored in the <code>out.pred</code> object.</p>
<p>Prediction is possible using the <code>predict</code> function, a set of covariates at the desired prediction locations, and the spatial coordinates of the locations. The object <code>neonPredData</code> contains percent forest cover and grassland cover across the Disney Wildnerness Preserve. Below we predict MODO density across the preserve, which is stored in the <code>out.pred</code> object.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="co"># First standardize elevation using mean and sd from fitted model</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>forest.pred &lt;-<span class="st"> </span>(neonPredData<span class="op">$</span>forest <span class="op">-</span><span class="st"> </span><span class="kw">mean</span>(dat.MODO<span class="op">$</span>covs<span class="op">$</span>forest)) <span class="op">/</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a><span class="st"> </span><span class="kw">sd</span>(dat.MODO<span class="op">$</span>covs<span class="op">$</span>forest)</span>
Expand All @@ -820,7 +820,7 @@ <h2 id="learn-more">Learn more</h2>
<p>The <code>vignette(&quot;distanceSampling&quot;)</code>, <code>vignette(&quot;nMixtureModels&quot;)</code>, and <code>vignette(&quot;glmm&quot;)</code> provide detailed descriptions and tutorials of all hierarchical distance sampling models, N-mixture models, and generalized linear mixed models in <code>spAbundance</code>, respectively. Given the similarity in syntax to fitting occupancy models in the <code>spOccupancy</code> package, much of the documentation on the <a href="https://www.jeffdoser.com/files/spoccupancy-web/"><code>spOccupancy</code> website</a> will also be helpful for fitting models in <code>spAbundance</code>.</p>
<h2 id="citing-spabundance">Citing <code>spAbundance</code></h2>
<p>Please cite <code>spAbundance</code> as:</p>
<p>Doser, J. W., Finley, A. O., Kéry, M., and Zipkin, E. F. (2023). spAbundance: An R package for univariate and multivariate spatially-explicit abundance models. arXiv Preprint.</p>
<p>Doser, J. W., Finley, A. O., Kéry, M., and Zipkin, E. F. (2023). spAbundance: An R package for single-species and multi-species spatially-explicit abundance models. arXiv Preprint.</p>
<h2 id="references">References</h2>
<p>Doser, J. W., Finley, A. O., Kéry, M., and Zipkin, E. F. (2022). spOccupancy: An R package for single-species, multi-species, and integrated spatial occupancy models. Methods in Ecology and Evolution. <a href="https://doi.org/10.1111/2041-210X.13897">https://doi.org/10.1111/2041-210X.13897</a>.</p>

Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![](http://cranlogs.r-pkg.org/badges/grand-total/spAbundance?color=blue)](https://CRAN.R-project.org/package=spAbundance)
[![CRAN](https://www.r-pkg.org/badges/version/spAbundance)](https://CRAN.R-project.org/package=spAbundance)
[![Codecov test
coverage](https://codecov.io/gh/doserjef/spAbundance/branch/main/graph/badge.svg)](https://app.codecov.io/gh/doserjef/spAbundance?branch=main)
coverage](https://codecov.io/gh/doserjef/spAbundance/branch/main/graph/badge.svg)](https://codecov.io/gh/doserjef/spAbundance?branch=main)

`spAbundance` fits univariate (i.e., single-species) and multivariate
(i.e., multi-species) spatial N-mixture models, hierarchical distance
Expand Down Expand Up @@ -87,7 +87,7 @@ data set. We use data on 16 birds from the [Disney Wilderness
Preserve](https://www.neonscience.org/field-sites/dsny) in Central
Florida, USA, which is available in the `spAbundance` package as the
`neonDWP` object. Here we will only work with one bird species, the
Eastern Meadowlark (EAME), and so we subset the `neonDWP` object to only
Mourning Dove (MODO), and so we subset the `neonDWP` object to only
include this species.

``` r
Expand All @@ -106,8 +106,8 @@ Below we fit a single-species spatially-explicit hierarchical distance
sampling model to the MODO data using a Nearest Neighbor Gaussian
Process. We use the default priors and initial values for the abundance
(`beta`) and detection (`alpha`) coefficients, the spatial variance
(`sigma.sq`), the spatial range parameter (`phi`), the spatial random
effects (`w`), and the latent abundance values (`z`). We also include an
(`sigma.sq`), the spatial decay parameter (`phi`), the spatial random
effects (`w`), and the latent abundance values (`N`). We also include an
offset in `dat.MODO` to provide estimates of density on a per hectare
basis. We model abundance as a function of local forest cover and
grassland cover, along with a spatial random intercept. We model
Expand Down Expand Up @@ -158,7 +158,7 @@ summary(out)
#> Thinning Rate: 5
#> Number of Chains: 3
#> Total Posterior Samples: 6000
#> Run Time (min): 1.71
#> Run Time (min): 4.2247
#>
#> Abundance (log scale):
#> Mean SD 2.5% 50% 97.5% Rhat ESS
Expand Down Expand Up @@ -209,8 +209,7 @@ summary(ppc.out)
### Model selection using WAIC

The `waicAbund` function computes the Widely Applicable Information
Criterion (WAIC) for use in model selection and assessment (note that
due to Monte Carlo error your results will differ slightly).
Criterion (WAIC) for use in model selection and assessment.

``` r
waicAbund(out)
Expand All @@ -226,7 +225,7 @@ Prediction is possible using the `predict` function, a set of covariates
at the desired prediction locations, and the spatial coordinates of the
locations. The object `neonPredData` contains percent forest cover and
grassland cover across the Disney Wildnerness Preserve. Below we predict
MODO densityacross the preserve, which is stored in the `out.pred`
MODO density across the preserve, which is stored in the `out.pred`
object.

``` r
Expand Down Expand Up @@ -257,7 +256,7 @@ helpful for fitting models in `spAbundance`.
Please cite `spAbundance` as:

Doser, J. W., Finley, A. O., Kéry, M., and Zipkin, E. F. (2023).
spAbundance: An R package for univariate and multivariate
spAbundance: An R package for single-species and multi-species
spatially-explicit abundance models. arXiv Preprint.

## References
Expand Down
Binary file modified data/neonDWP.rda
Binary file not shown.
Loading

0 comments on commit 34896ce

Please sign in to comment.