8000 alternatief voor toename soorten in de tijd als proportie tov pantrap… by hansvancalster · Pull Request #6 · inbo/mbag-monipolli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

alternatief voor toename soorten in de tijd als proportie tov pantrap… #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 177 additions & 1 deletion source/data_analysis_spring/data_analysis_spring_2023.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,16 @@
## Beide groepen

```{r}
site_totals <- apoidea |>
bind_rows(syrphidae) |>
filter(
time_since_previous == 0 | time_till_next == 0
) %>%
group_by(location_code) |>
distinct(species_nm) |>
count(location_code, name = "n_species_site")


combi <- apoidea |>
bind_rows(syrphidae) |>
filter(
Expand Down Expand Up @@ -1149,9 +1159,172 @@
group_by(sampling_site_method) |>
mutate(n_species_final = max(cumulative_n_species)) |>
ungroup() |>
mutate(prop = cumulative_n_species / n_species_final)
mutate(prop = cumulative_n_species / n_species_final) |>
left_join(site_totals) |>
select(
location_code,
sampling_site_method,
method_combi,
cumulative_days,
cumulative_n_species,
n_species_final,
prop,
n_species_site
)
```


### Nieuwe analyse

Alternatief model: cumulatief aantal soorten als responsvariabele en het totaal aantal soorten op een locatie als offset-term.
Naast een random effect voor pantrap, ook eens een extra random effect voor locatie toegevoegd (de pantraps zijn genest in locatie).
Dat blijkt, ondanks dat er maar drie levels zijn voor locatie, een betere AIC waarde op te leveren.

```{r}
model8 <- glmmTMB(cumulative_n_species ~
cumulative_days * method_combi +
(1 | sampling_site_method) + (1 | location_code),
family = poisson(),
offset = log(n_species_site),
data = combi)

model9 <- glmmTMB(cumulative_n_species ~
cumulative_days * method_combi +
(1 | sampling_site_method),
family = poisson(),
offset = log(n_species_site),
data = combi)

AIC(model8, model9)

```

Model validatie:

```{r}
performance::check_predictions(model8)
performance::check_overdispersion(model8)
performance::check_collinearity(model8)
performance::check_homogeneity(model8)
performance::check_residuals(model8)
```

Model parameterschattingen:

```{r}
model8
```

Berekening contrasten per methode:

```{r}
emmeans::emmeans(
model8,
trt.vs.ctrl1 ~ cumulative_days | method_combi,
type = "response",
at = list(
cumulative_days = c(
0.25,
1.25,
2.25,
3.25,
4.25,
5.25,
6.25,
7.25,
8.25,
9.25),
n_species_site = round(mean(site_totals$n_species_site), -1)
)
) |>
confint()
```


Berekening contrasten per dag:

```{r}
emmeans::emmeans(
model8,
revpairwise ~ method_combi | cumulative_days,
type = "response",
at = list(
cumulative_days = c(
0.25,
1.25,
2.25,
3.25,
4.25,
5.25,
6.25,
7.25,
8.25,
9.25),
n_species_site = round(mean(site_totals$n_species_site), -1)
)
) |>
confint()
```


Voorstelling predicties in figuur \@ref(fig:cns-predictions)

(ref:cns-predictions) Voorspelling van het aantal soorten in functie van het aantal dagen dat een pantrap op dezelfde locatie blijft staan en in functie van het type pantrap. De voorspelling gaat uit van een soortenpoel van `r round(mean(site_totals$n_species_site), -1)` taxa.

```{r cns-predictions, fig.cap="(ref:cns-predictions)"}
nd <- combi |>
distinct(cumulative_days, method_combi) |>
complete(cumulative_days, method_combi) |>
mutate(
n_species_site = round(mean(site_totals$n_species_site), -1)
)

Check warning on line 1281 in source/data_analysis_spring/data_analysis_spring_2023.Rmd

View workflow job for this annotation

GitHub Actions / check project with checklist

file=source/data_analysis_spring/data_analysis_spring_2023.Rmd,line=1281,col=1,[trailing_whitespace_linter] Remove trailing whitespace.

pp <- predict(
model8,
newdata = nd,
type = "link",
re.form = NA,
se.fit = TRUE
)

pp <- nd %>%
mutate(
estimate = pp$fit,
se = pp$se.fit,
conf.low = estimate - 2 * se,
conf.high = estimate + 2 * se
) %>%
mutate(
across(c(estimate, conf.low, conf.high), \(x) exp(x))
)

pp |>
ggplot() +
geom_line(
aes(x = cumulative_days, y = estimate, colour = method_combi)
) +
geom_ribbon(
aes(
x = cumulative_days,
ymin = conf.low,
ymax = conf.high,
fill = method_combi),
alpha = 0.2
) +
scale_x_continuous(
breaks = c(0, 2, 4, 6, 8)
) +
labs(y = "Predicted number of species",
x = "Cumulative days",
colour = "Method",
fill = "Method")
```


### Vorige analyse


```{r}
model7 <- glmmTMB(prop ~ cumulative_days * method_combi +
(1 | sampling_site_method),
Expand All @@ -1160,6 +1333,8 @@
data = combi)
```



```{r}
# check model assumptions
performance::check_model(model7)
Expand All @@ -1181,6 +1356,7 @@
9.25)))
```


```{r time-series-wild-bees-hoverflies, fig.cap = "Proportie soorten gevonden over tijd voor wilde bijen en zweefvliegen."}
# plot proportion of species found over time
pp <- marginaleffects::predictions(
Expand Down
0