Skip to content

Commit

Permalink
speedup ssm_fitting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Jonsen committed Jan 11, 2024
1 parent 68b696b commit 54d1ba3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
8 changes: 0 additions & 8 deletions vignettes/Mapping.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ fit <- fit_ssm(se2,
map(fit, what = "predicted")
```

```{r map 1a, eval=FALSE, echo=FALSE, fig.height=4, fig.width=7, warning=FALSE, message=FALSE}
se2 <- subset(sese, id %in% unique(id)[1:2])
fit <- fit_ssm(se2,
model = "mp",
time.step = 24,
control = ssm_control(verbose = 0))
```
![](images/mapping/map_1a.jpg){width=95%}

Here, SSM-predicted locations are coloured by the estimated move persistence index ($\gamma_t$). To aid visualisation of high and low move persistence regions along each track, the $\gamma_t$ estimates are normalised separately for each track to span the interval 0,1. This can be turned off with `normalise = FALSE`, or applied to the group of tracks with `group = TRUE`.
Expand Down
11 changes: 8 additions & 3 deletions vignettes/SSM_fitting.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ The default emf values are given by `emf()`:
emf()
```
These can be adjusted by modifying the data.frame and passing this to `fit_ssm` via `emf.
```{r emf mod, message=FALSE, fig.width=7, fig.height=6}
emf2 <- mutate(emf(), emf.x = c(0.1, 1, 2, 4, 20, 8, 15, 15))
```{r emf mod, eval=FALSE, message=FALSE}
emf2 <- dplyr::mutate(emf(), emf.x = c(0.1, 1, 2, 4, 20, 8, 15, 15))
fit1 <- fit_ssm(subset(sese2, id == unique(id)[1]),
model = "rw",
Expand All @@ -74,6 +74,7 @@ hist(grab(fit1, "f")$x - grab(fit2, "f")$x, breaks = 20,
hist(grab(fit1, "f")$y - grab(fit2, "f")$y, breaks = 20,
main = "fit1$y - fit2$y", xlim = c(-20,20), xlab = "Distance (km)")
```
![](images/ssm_fitting/histos.jpeg){width="98%"}

In this contrived example, re-specified `emf.x` values result in differences in the predicted locations of up to about 20 km in the x-direction and a more subtle 4 km in the y-direction, even though the `emf.y` values were not edited. The latter is due to a model-estimated correlation between the x and y errors.

Expand All @@ -83,7 +84,7 @@ Now that CLS Argos provides locations estimated by their Kalman filter algorithm
The `map` argument allows some model parameters to by turned off by fixing them at 0 on the log-scale. This can be useful in cases where model simplification can aid in convergence or simply provide a better fit to the data. For example, the `crw` has a parameter `psi` that re-scales the semi-major axis of Argos KF error ellipses to account for apparent bias in the error ellipses (Jonsen et al. 2020). Occasionally, there may be insufficient information to reliably estimate this parameter, or one might wish to compare model fits with and without error ellipse bias correction.

Here we fit the `crw` model with (`fit1`) and without (`fit2`) the bias-correction parameter `psi`, by supplying a named list to the `map` argument. Where `factor(NA)` is a `TMB` convention that ensures `psi` is fixed during optimization.
```{r demonstrate map use, message=FALSE, warning=FALSE}
```{r demonstrate map use, eval=FALSE, message=FALSE, warning=FALSE}
fit1 <- fit_ssm(ellie,
model = "crw",
time.step = 24,
Expand All @@ -97,6 +98,10 @@ fit2 <- fit_ssm(ellie,
c(fit1$ssm[[1]]$AICc, fit2$ssm[[1]]$AICc)
```
```{r demonstrate map use2, message=FALSE, echo=FALSE}
load("data/ssm_fitting/fits_aic.rda")
c(fit1$ssm[[1]]$AICc, fit2$ssm[[1]]$AICc)
```

Comparison of AIC~c~ from the model fits implies the model including the `psi` parameter `fit1` provides a slightly better fit.

Expand Down
Binary file added vignettes/data/ssm_fitting/fits_aic.rda
Binary file not shown.
Binary file added vignettes/images/ssm_fitting/histos.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 54d1ba3

Please sign in to comment.