You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/articles/multispecies.Rmd
+88-7Lines changed: 88 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -170,14 +170,95 @@ fit <- sdmTMB(
170
170
family = gaussian(),
171
171
spatial = "off",
172
172
time = "species_year",
173
-
spatiotemporal = "iid",
174
-
spatial_varying = ~ 0 + factor(species),
175
-
control = sdmTMBcontrol(map = map_list)
173
+
spatiotemporal = "iid"
174
+
# spatial_varying = ~ 0 + factor(species),
175
+
# control = sdmTMBcontrol(map = map_list)
176
176
)
177
177
fit
178
178
```
179
179
180
-
### Model 4: hack species into the time element for spatial models
180
+
### Model 4: species-specific spatiotemporal fields using the `spatial_varying` argument
181
+
182
+
We can fit the same model by using the `spatial_varying` argument. This would give us the added flexibility of letting each species' spatiotemporal field have its own variance if we wanted or if expanding our model to have another category of independent random fields. E.g., we might also have age or length bins.
183
+
184
+
First, we'll have the spatial fields share their variance and the spatiotemporal fields share their variance:
185
+
186
+
```{r}
187
+
# quick hack to force all levels of species and species:factor interactions in formula:
Now we have separate SDs for the spatial and spatiotemporal fields across species.
253
+
254
+
But in this case, marginal AIC does not indicate an improvement from this added flexibility:
255
+
256
+
```{r}
257
+
AIC(fit_svc, fit_svc_separate)
258
+
```
259
+
260
+
261
+
### Model 5: hack species into the time element for spatial models
181
262
182
263
If we only wanted to fit a spatial model but had several species (or other groups), one approach is to pretend our species (or other group) is the time element.
183
264
@@ -198,7 +279,7 @@ fit_fake_time
198
279
This is just a convenience though. We could instead do the same thing using the `spatial_varying` argument making sure to 'map' the field variances to be shared to match the above:
199
280
200
281
```{r}
201
-
fit_svc <- sdmTMB(
282
+
fit_svc3 <- sdmTMB(
202
283
observed ~ 0 + factor(species),
203
284
data = sim_dat,
204
285
mesh = mesh,
@@ -207,14 +288,14 @@ fit_svc <- sdmTMB(
207
288
spatial_varying = ~ 0 + factor(species),
208
289
control = sdmTMBcontrol(map = list(ln_tau_Z = factor(c(1, 1))))
0 commit comments