Is there a way to get confidence intervals for time-varying effects? #205
-
The documentation suggests to get confidence intervals using the tidy() function, but there doesn't seem to be a way to get confidence intervals for time-varying effects. Must they be calculated manually from standard error? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, sorry, those aren't in Here's an example of grabbing them yourself. The format of library(sdmTMB)
fit <- sdmTMB(
density ~ 0,
time_varying = ~ 1 + depth_scaled,
time_varying_type = "rw",
data = pcod_2011,
time = "year",
spatial = "off",
spatiotemporal = "off",
family = tweedie()
)
est <- as.list(fit$sd_report, "Estimate")
se <- as.list(fit$sd_report, "Std. Error")
est$b_rw_t
#> , , 1
#>
#> [,1] [,2]
#> [1,] 1.854868 -0.4317058
#> [2,] 1.830428 -0.4317059
#> [3,] 1.917300 -0.4317059
#> [4,] 1.602897 -0.4317059
est <- est$b_rw_t[,,1]
se <- se$b_rw_t[,,1]
est
#> [,1] [,2]
#> [1,] 1.854868 -0.4317058
#> [2,] 1.830428 -0.4317059
#> [3,] 1.917300 -0.4317059
#> [4,] 1.602897 -0.4317059
est + qnorm(0.975) * se
#> [,1] [,2]
#> [1,] 1.979196 -0.2454046
#> [2,] 1.954876 -0.2454048
#> [3,] 2.050123 -0.2454047
#> [4,] 1.760604 -0.2454047
est + qnorm(0.025) * se
#> [,1] [,2]
#> [1,] 1.730541 -0.6180071
#> [2,] 1.705980 -0.6180070
#> [3,] 1.784476 -0.6180071
#> [4,] 1.445190 -0.6180072 Created on 2023-04-28 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
Yes, sorry, those aren't in
tidy()
yet. Random intercepts are, but not time-varying random effects. I posted an issue here: #206Here's an example of grabbing them yourself. The format of
b_rw_t
may vary a bit depending on your model configuration. There's also the "ar1" and "rw0"time_varying_type
, which start with a mean of zero. In that case you'd likely include main effects and then the time-varying effect would represent deviations starting from the main effect.