pbs-assess / sdmTMB

:earth_americas: An R package for spatial and spatiotemporal GLMMs with TMB
https://pbs-assess.github.io/sdmTMB/
186 stars 26 forks source link

tidy with exponentiate = TRUE returns CIs based on already exponentiated estimate #353

Closed maxlindmark closed 3 months ago

maxlindmark commented 3 months ago

Hi!

I wonder if there's an issue with tidy.sdmTMB() and the exponentiate argument. See below for an example on how the CIs look wrong:

library(sdmTMB)

mesh <- make_mesh(pcod, c("X", "Y"), cutoff = 20)

fit <- sdmTMB(
  density ~ s(depth, by = as.factor(year)), 
  time = "year",
  spatial = "off",
  spatiotemporal = "rw",
  data = pcod, mesh = mesh,
  family = tweedie(link = "log")
)
#> Detected irregular time spacing with an AR(1) or random walk process.
#> Consider filling in the missing time slices with `extra_time`.
#> `extra_time = c(2006, 2008, 2010, 2012, 2014, 2016)`

tidy(fit, conf.int = TRUE)
#> # A tibble: 1 × 5
#>   term        estimate std.error conf.low conf.high
#>   <chr>          <dbl>     <dbl>    <dbl>     <dbl>
#> 1 (Intercept)     2.31     0.276     1.77      2.85

tidy(fit, conf.int = TRUE, exponentiate = TRUE)
#> # A tibble: 1 × 5
#>   term        estimate std.error conf.low conf.high
#>   <chr>          <dbl>     <dbl>    <dbl>     <dbl>
#> 1 (Intercept)     10.1     0.276   14052.    41433.

Created on 2024-06-19 with reprex v2.1.0

I wonder if this is due to this code, because out$estimate is already exponentiated here (if I run the code for out$conf.low and out$conf.high manually prior to exponentiating out$estimate the exponentiated estimate fits within the CI)

seananderson commented 3 months ago

Thanks! Fixed. I also set conf.int = TRUE as the new default and removed the std.error if exponentiate = TRUE since it no longer reflects the printed parameter space.