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
`ggeffects::ggpredict()` can be used to make conditional effects plots of sdmTMB models, including models with smoothers (but not currently including delta models [due to a recent change in ggeffects](https://github.com/pbs-assess/sdmTMB/issues/435)).
157
+
158
+
Here's an example:
159
+
160
+
```{r}
161
+
pcod$fyear <- as.factor(pcod$year)
162
+
mesh <- make_mesh(pcod, c("X", "Y"), cutoff = 20)
163
+
fit <- sdmTMB(present ~ s(depth) + fyear,
164
+
data = pcod,
165
+
mesh = mesh,
166
+
spatial = "on",
167
+
family = binomial()
168
+
)
169
+
```
170
+
171
+
```{r}
172
+
g <- ggpredict(fit, "depth [0:400 by=2]")
173
+
plot(g)
174
+
```
175
+
176
+
```{r}
177
+
g <- ggpredict(fit, terms = c("depth [0:350 by=5]", "fyear"))
178
+
plot(g)
179
+
plot(g, facet = TRUE)
180
+
```
181
+
182
+
We can extract the data to make our own plot:
183
+
184
+
```{r}
185
+
df <- as.data.frame(g)
186
+
glimpse(df)
187
+
```
188
+
189
+
```{r}
190
+
ggplot(df, aes(
191
+
x, predicted,
192
+
ymin = conf.low,
193
+
ymax = conf.high,
194
+
colour = group, fill = group
195
+
)) +
196
+
geom_ribbon(alpha = 0.4, colour = NA) +
197
+
geom_line() +
198
+
facet_wrap(vars(group)) +
199
+
labs(x = "Depth (m)", y = "Predicted", colour = "Year", fill = "Year")
0 commit comments