+
set.seed(19292)
samps <- sdmTMBextra::extract_mcmc(fit_stan)
s <- simulate(fit_mle, mcmc_samples = samps, nsim = 50)
-bayesplot::pp_check(
+bayesplot::pp_check(
sim_dat$observed,
yrep = t(s),
- fun = bayesplot::ppc_dens_overlay
+ fun = bayesplot::ppc_dens_overlay
)
-See ?bayesplot::pp_check
. The solid line represents the
+
+See ?bayesplot::pp_check
. The solid line represents the
density of the observed data and the light blue lines represent the
density of 50 posterior predictive simulations. In this case, the
simulated data seem consistent with the observed data.
@@ -302,26 +454,30 @@ Plotting predictionspredict.sdmTMB().
-
+
pred <- predict(fit_mle, mcmc_samples = samps)
The output is a matrix where each row corresponds to a row of
predicted data and each column corresponds to a sample.
-
+
+dim(pred)
+#> [1] 500 1000
We can summarize these draws in various ways to visualize them:
-
+
+
+
+
Or predict on a grid for a given value of a1
:
-
+
nd <- expand.grid(
X = seq(0, 1, length.out = 70),
Y = seq(0, 1, length.out = 70),
@@ -335,32 +491,39 @@
+
+
+
We can extract posterior samples with
rstan::extract()
,
-
+
The result is a list where each element corresponds to a parameter or
set of parameters:
-
+
+#> [1] "b_j" "ln_tau_O" "ln_phi" "omega_s" "lp__"
+
+
As an example of calculating a derived parameter, here we will
calculate the marginal spatial random field standard deviation:
-
+
ln_kappa <- get_pars(fit_mle)$ln_kappa[1] # 2 elements since 2nd would be for spatiotemporal
ln_tau_O <- post$ln_tau_O
sigma_O <- 1 / sqrt(4 * pi * exp(2 * ln_tau_O + 2 * ln_kappa))
hist(sigma_O)
+
For example, let’s extract the spatial random field values
"omega_s"
. Other options are documented in
?predict.sdmTMB()
.
-
+
fit_pred <- predict(
fit_mle,
newdata = nd,
@@ -388,12 +551,15 @@
+
+
+
diff --git a/articles/web_only/bayesian_files/figure-html/unnamed-chunk-9-1.png b/articles/web_only/bayesian_files/figure-html/unnamed-chunk-9-1.png
index c100924e9..938c1483b 100644
Binary files a/articles/web_only/bayesian_files/figure-html/unnamed-chunk-9-1.png and b/articles/web_only/bayesian_files/figure-html/unnamed-chunk-9-1.png differ
diff --git a/articles/web_only/cross-validation.html b/articles/web_only/cross-validation.html
index 99ea269dd..ec08babbf 100644
--- a/articles/web_only/cross-validation.html
+++ b/articles/web_only/cross-validation.html
@@ -26,7 +26,7 @@
sdmTMB
- 0.6.0.9001
+ 0.6.0.9002
Our main effect tells us that the overall linear trend of density has
been a multiplicative factor of 0.94 per decade. Conversely, the overall
trend has been a decline of 6% per decade.
diff --git a/articles/web_only/spatial-trend-models_files/figure-html/unnamed-chunk-13-1.png b/articles/web_only/spatial-trend-models_files/figure-html/unnamed-chunk-13-1.png
index 8a007c4fb..757e2e5f7 100644
Binary files a/articles/web_only/spatial-trend-models_files/figure-html/unnamed-chunk-13-1.png and b/articles/web_only/spatial-trend-models_files/figure-html/unnamed-chunk-13-1.png differ
diff --git a/articles/web_only/threshold-models.html b/articles/web_only/threshold-models.html
index e5233e7b8..2a07104ad 100644
--- a/articles/web_only/threshold-models.html
+++ b/articles/web_only/threshold-models.html
@@ -26,7 +26,7 @@
sdmTMB
-
0.6.0.9001
+
0.6.0.9002