Skip to content

Commit

Permalink
update results
Browse files Browse the repository at this point in the history
  • Loading branch information
langbart committed May 24, 2024
1 parent 5854b0b commit ff70e7a
Show file tree
Hide file tree
Showing 35 changed files with 142 additions and 49 deletions.
12 changes: 6 additions & 6 deletions R/get-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,20 @@ get_merged_trips <- function(pars, ...) {
imei_regions <-
trips %>%
dplyr::filter(!is.na(.data$tracker_imei)) %>%
dplyr::select(.data$tracker_imei, .data$reporting_region) %>%
dplyr::select(.data$tracker_imei, .data$municipality) %>%
dplyr::group_by(.data$tracker_imei) %>%
dplyr::count(.data$reporting_region) %>%
dplyr::filter(!is.na(.data$reporting_region)) %>%
dplyr::count(.data$municipality) %>%
dplyr::filter(!is.na(.data$municipality)) %>%
dplyr::group_by(.data$tracker_imei) %>%
dplyr::arrange(dplyr::desc(.data$n), .by_group = TRUE) %>%
dplyr::summarise(reporting_region = dplyr::first(.data$reporting_region)) %>%
dplyr::summarise(reporting_region = dplyr::first(.data$municipality)) %>%
dplyr::rename(reporting_region_fill = .data$reporting_region) %>%
dplyr::ungroup()

dplyr::full_join(trips, imei_regions, by = "tracker_imei") %>%
dplyr::mutate(reporting_region = dplyr::case_when(
is.na(.data$reporting_region) ~ .data$reporting_region_fill,
TRUE ~ reporting_region
is.na(.data$municipality) ~ .data$reporting_region_fill,
TRUE ~ municipality
)) %>%
dplyr::select(-.data$reporting_region_fill)
}
5 changes: 3 additions & 2 deletions R/processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ get_model_data <- function() {
na.omit()

#factoextra::fviz_nbclust(df[, 8:13], kmeans, method = "wss")
#wss 3; silhouette 3
set.seed(555)
k2 <- kmeans(df[, 8:13], centers = 5, nstart = 500)
k2 <- kmeans(df[, 8:13], centers = 3, nstart = 500)

timor_GN_raw <-
dplyr::tibble(
Expand Down Expand Up @@ -138,7 +139,7 @@ get_model_data <- function() {

#factoextra::fviz_nbclust(df[, 7:12], kmeans, method = "wss")
set.seed(555)
k2 <- kmeans(df[, 7:12], centers = 5, nstart = 500)
k2 <- kmeans(df[, 7:12], centers = 3, nstart = 500)

timor_AG_raw <-
dplyr::tibble(
Expand Down
2 changes: 1 addition & 1 deletion R/xgb-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ plot_model_shaps <- function(data_shaps = NULL, model_type = NULL, alpha = 0.2,
hjust = 0,
vjust = -0.5,
align = "hv",
labels = c("NP1", "NP2", "NP3", "NP4", "NP5")
labels = c("NP1", "NP2", "NP3")
)

if (model_type == "gn") {
Expand Down
32 changes: 16 additions & 16 deletions data-raw/get-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ region_stats <-
# vitaminA = (.data$Vitamin_A_mu * (.data$catch * 1000)) / 1000
# )

trips <-
get_merged_trips(pars) %>%
dplyr::filter(!is.na(landing_id))
#trips <-
# get_merged_trips(pars) %>%
# dplyr::filter(!is.na(landing_id))

kobo_trips <-
trips %>%
Expand All @@ -88,31 +88,31 @@ kobo_trips <-
reporting_region %in% c("Dili", "Atauro")) %>%
tidyr::unnest(.data$landing_catch) %>%
tidyr::unnest(.data$length_frequency) %>%
dplyr::filter(!is.na(.data$weight)) %>%
dplyr::filter(!is.na(.data$catch)) %>%
dplyr::group_by(.data$landing_id, .data$landing_period) %>%
dplyr::summarise(
landing_id = dplyr::first(landing_id),
reporting_region = dplyr::first(reporting_region),
reporting_region = dplyr::first(municipality),
landing_date = dplyr::first(landing_date),
trip_duration = dplyr::first(trip_duration),
trip_duration = dplyr::first(trip_length),
n_fishers = dplyr::first(n_fishers),
habitat = dplyr::first(habitat),
gear_type = dplyr::first(gear_type),
gear_type = dplyr::first(gear),
mesh_size = dplyr::first(mesh_size),
vessel_type = dplyr::first(vessel_type),
landing_value = dplyr::first(landing_value),
vessel_type = dplyr::first(propulsion_gear),
landing_value = dplyr::first(landing_catch_price),
dplyr::across(
c(.data$weight:.data$Vitamin_A_mu),
c(.data$catch:.data$Vitamin_A_mu),
~ sum(.x) / 1000
)
) %>%
dplyr::ungroup() %>%
dplyr::mutate(habitat = ifelse(habitat == "Traditional FAD", "FAD", habitat))

catch_data <-
trips %>%
dplyr::filter(landing_id %in% kobo_trips$landing_id) %>%
dplyr::select(landing_id, landing_value, landing_catch)
#catch_data <-
# trips %>%
# dplyr::filter(landing_id %in% kobo_trips$landing_id) %>%
# dplyr::select(landing_id, landing_value, landing_catch)

usethis::use_data(RDI_tab, overwrite = TRUE)
usethis::use_data(catch_groups, overwrite = TRUE)
Expand All @@ -129,8 +129,8 @@ data_list <- get_model_data()
set.seed(555)
data_clusters <-
list(
timor_GN_perm = dplyr::slice_sample(data_list$data_raw$timor_GN_raw, prop = .5),
timor_AG_perm = dplyr::slice_sample(data_list$data_raw$timor_AG_raw, prop = .5)
timor_GN_perm = dplyr::slice_sample(data_list$data_raw$timor_GN_raw, prop = .75),
timor_AG_perm = dplyr::slice_sample(data_list$data_raw$timor_AG_raw, prop = .75)
)
perm_results <- purrr::imap(data_clusters, ~ run_permanova_clusters(.x, permutations = 999, parallel = 13))
usethis::use_data(perm_results, overwrite = T)
Expand Down
Binary file modified data/model_outputs.rda
Binary file not shown.
Binary file modified data/perm_results.rda
Binary file not shown.
Binary file modified data/shap_results.rda
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
8 changes: 4 additions & 4 deletions docs/afigures.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ <h1>
<section class="normal" id="section-">
<div id="afigures" class="section level1 hasAnchor" number="7">
<h1><span class="header-section-number">7</span> Other figures<a href="afigures.html#afigures" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<div class="figure"><span style="display:block;" id="fig:unnamed-chunk-12"></span>
<img src="Timor-nutrient-sensitive-fisheries-management_files/figure-html/unnamed-chunk-12-1.png" alt="To define" width="864" />
<div class="figure"><span style="display:block;" id="fig:unnamed-chunk-13"></span>
<img src="Timor-nutrient-sensitive-fisheries-management_files/figure-html/unnamed-chunk-13-1.png" alt="To define" width="864" />
<p class="caption">
Figure 7.1: To define
</p>
</div>
<div class="figure"><span style="display:block;" id="fig:unnamed-chunk-13"></span>
<img src="Timor-nutrient-sensitive-fisheries-management_files/figure-html/unnamed-chunk-13-1.png" alt="To define" width="768" />
<div class="figure"><span style="display:block;" id="fig:unnamed-chunk-14"></span>
<img src="Timor-nutrient-sensitive-fisheries-management_files/figure-html/unnamed-chunk-14-1.png" alt="To define" width="768" />
<p class="caption">
Figure 7.2: To define
</p>
Expand Down
4 changes: 2 additions & 2 deletions docs/highlight.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ <h1>
<div id="header">
<h1 class="title">Modelling scenarios for nutrient-sensitive fisheries management</h1>
<p class="author"><em>Lorenzo Longobardi</em></p>
<p class="date"><em>Last update: 2024-05-17</em></p>
<p class="date"><em>Last update: 2024-05-23</em></p>
</div>
<div id="content" class="section level1 hasAnchor" number="1">
<h1><span class="header-section-number">1</span> Content<a href="index.html#content" class="anchor-section" aria-label="Anchor link to header"></a></h1>
Expand Down
24 changes: 13 additions & 11 deletions docs/profiles.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/reference-keys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ fig:nutdispersion
fig:unnamed-chunk-2
fig:unnamed-chunk-3
fig:unnamed-chunk-4
fig:unnamed-chunk-5
fig:unnamed-chunk-6
fig:unnamed-chunk-7
fig:model-settings
fig:unnamed-chunk-9
fig:unnamed-chunk-12
fig:unnamed-chunk-10
fig:unnamed-chunk-13
fig:unnamed-chunk-14
content
data
catch-weight-and-nutrional-content
Expand Down
2 changes: 1 addition & 1 deletion docs/search_index.json

Large diffs are not rendered by default.

94 changes: 92 additions & 2 deletions docs_book/04-profiles.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For Atauro, considering all gear types (Panel a), the results demonstrate variab
The mainland dataset utilizing all gear types (Panel c) also reveals a distinct distribution of nutrients. Clusters 1 and 2 have higher levels of calcium, with cluster 2 showing a particularly high value that surpasses other clusters, while cluster 1 is particular rich in omega-3. Vitamin A shows a significant peak in cluster 2, indicating a unique subset of catch composition in terms of this nutrient. Finally, focusing on the mainland using only gill net gear (Panel d), the data suggests a more even distribution of omega-3 across the clusters, with clusters 4 and 2 showing marginally higher values. Calcium have a higher occurrence in clusters 2 and 4, while zinc is considerably more prevalent in cluster 5. Iron, although present in all clusters, is most concentrated in cluster 4.


```{r echo=FALSE, fig.cap="Distribution of nutrient adequacy across k-means clusters. The bar chart delineates the number of individuals meeting the Recommended Nutrient Intake (RNI) per 1kg of catch within identified k-means clusters. Each bar is categorized into six segments corresponding to the evaluated nutrients. The clusters are enumerated on the y-axis, each representing a group with a distinct nutritional profile as determined by the cluster analysis. The x-axis and the white labels in the bars quantify the count of individuals within each cluster that meet the RNI for the respective nutrients, underlining the variability in nutritional adequacy across clusters. Panels (A) through (D) compare these distributions across different fishing practices and locations, namely Atauro and the Mainland, using all gear types or exclusively gill nets.", fig.height=4.5, fig.width=10, message=FALSE, warning=FALSE}
```{r eval=FALSE, fig.cap="Distribution of nutrient adequacy across k-means clusters. The bar chart delineates the number of individuals meeting the Recommended Nutrient Intake (RNI) per 1kg of catch within identified k-means clusters. Each bar is categorized into six segments corresponding to the evaluated nutrients. The clusters are enumerated on the y-axis, fig.width=10, message=FALSE, warning=FALSE, each representing a group with a distinct nutritional profile as determined by the cluster analysis. The x-axis and the white labels in the bars quantify the count of individuals within each cluster that meet the RNI for the respective nutrients, underlining the variability in nutritional adequacy across clusters. Panels (A) through (D) compare these distributions across different fishing practices and locations, namely Atauro and the Mainland, using all gear types or exclusively gill nets.", fig.height=4.5, include=FALSE}
library(ggplot2)
data <- get_model_data()
data$data_raw$timor_GN_raw$clusters <- paste0("NP-", data$data_raw$timor_GN_raw$clusters)
Expand Down Expand Up @@ -126,6 +126,96 @@ final_plot <-
final_plot
```

```{r echo=FALSE, fig.cap="Distribution of nutrient adequacy across k-means clusters. The bar chart delineates the number of individuals meeting the Recommended Nutrient Intake (RNI) per 1kg of catch within identified k-means clusters. Each bar is categorized into six segments corresponding to the evaluated nutrients. The clusters are enumerated on the y-axis, message=FALSE, warning=FALSE, each representing a group with a distinct nutritional profile as determined by the cluster analysis. The x-axis and the white labels in the bars quantify the count of individuals within each cluster that meet the RNI for the respective nutrients, underlining the variability in nutritional adequacy across clusters. Panels (A) through (D) compare these distributions across different fishing practices and locations, namely Atauro and the Mainland, using all gear types or exclusively gill nets.", fig.height=4.5, fig.width=10}
library(ggplot2)
data <- get_model_data()
data$data_raw$timor_GN_raw$clusters <- paste0("NP-", data$data_raw$timor_GN_raw$clusters)
data$data_raw$timor_AG_raw$clusters <- paste0("NP-", data$data_raw$timor_AG_raw$clusters)
plot_profiles <- function(x) {
means_dat <-
x %>%
dplyr::rename_with(~ stringr::str_to_title(.x), .cols = c(.data$zinc:.data$vitaminA)) %>%
dplyr::rename(
"Vitamin-A" = .data$Vitamina,
"Omega-3" = .data$Omega3
) %>%
tidyr::pivot_longer(c(Zinc:"Vitamin-A")) %>%
dplyr::group_by(clusters, name) %>%
dplyr::summarise(
mean = mean(value, na.rm = TRUE),
sd = sd(value, na.rm = TRUE),
n = dplyr::n(),
se = sd / sqrt(n),
ci_lower = mean - qt(0.99, df = n - 1) * se,
ci_upper = mean + qt(0.99, df = n - 1) * se
)
all_dat <-
x %>%
dplyr::rename_with(~ stringr::str_to_title(.x), .cols = c(.data$zinc:.data$vitaminA)) %>%
dplyr::rename(
"Vitamin-A" = .data$Vitamina,
"Omega-3" = .data$Omega3
) %>%
tidyr::pivot_longer(c(Zinc:"Vitamin-A"))
ggplot() +
theme_bw() +
geom_jitter(data = all_dat, mapping = aes(x = value, y = name, color = clusters), alpha = 0.01, size = 1, position = position_dodge(width = 0.5)) +
geom_point(data = means_dat, mapping = aes(x = mean, y = name, color = clusters), size = 5, position = position_dodge(width = 0.5)) +
labs(
x = "",
y = "",
color = "Profiles"
) +
ggplot2::theme(
legend.position = "",
plot.margin = unit(c(0, 0, 0, 0), "cm"),
panel.grid = ggplot2::element_blank()
) +
coord_cartesian(xlim = c(0, 5)) +
scale_fill_manual(values = timor.nutrients::palettes$clusters_palette) +
scale_color_manual(values = timor.nutrients::palettes$clusters_palette)
}
plots <- purrr::map(data$data_raw, plot_profiles)
plots <-
list(
plots$timor_GN_raw + ggplot2::labs(subtitle = "Gill nets"),
plots$timor_AG_raw + ggplot2::labs(subtitle = "Other gears")
)
legend_plot <- cowplot::get_legend(plots[[1]] +
ggplot2::theme(
legend.position = "right",
legend.key.size = ggplot2::unit(0.55, "cm"),
legend.title = ggplot2::element_text(size = 12)
))
combined_plots <- cowplot::plot_grid(plotlist = plots, ncol = 2, labels = "AUTO")
x_label <- cowplot::draw_label("NDS per 1kg of catch", x = 0.5, y = 0.05)
y_label <- cowplot::draw_label("Nutrient", x = 0.04, y = 0.5, angle = 90)
final_plot <-
cowplot::plot_grid(
combined_plots,
legend_plot,
ncol = 2,
rel_widths = c(1, 0.15),
scale = 0.9
) +
x_label +
y_label
final_plot
```

The scatter plot from the k-means clustering (Figure 5.2) showed the distribution of nutritional profiles across different clusters in each data subset. The first two principal components explained a significant portion of the variance, indicating distinct groupings in nutritional profiles among the fishing trips.

```{r echo=FALSE, fig.height=5, fig.width=10, message=FALSE, warning=FALSE, fig.cap="Nutritional profile clustering of fishing trips by region and gear type. Each plot presents a k-means clustering analysis of fishing trip observations, grouped by their nutritional contributions to the Recommended Nutrient Intake (RNI) for six nutrients. The four panels, labeled (A) through (D), display data subsets for Atauro and the Mainland, utilizing all gear types and gill nets specifically. The scatter plots within each panel are charted in a two-dimensional space defined by the first two principal components, with the axes denoting the percentage of explained variance. Points are color-coded to denote distinct nutritional profile clusters derived from the k-means algorithm. Convex hulls define the periphery of each cluster, providing insight into the cluster density and separation. Convex hulls around the clusters aid in visualizing the distribution and delineation of nutritional profile groupings across different fishing methods and geographic areas."}
Expand Down Expand Up @@ -330,7 +420,7 @@ p2 <-
dplyr::filter(mesh_shap > 0) %>%
dplyr::mutate(habitat_fact = dplyr::case_when(habitat_fact == "Deep" ~ "Pelagic", TRUE ~ habitat_fact)) %>%
ggplot2::ggplot(ggplot2::aes(mesh_shap, mesh_fact, color = habitat_fact)) +
facet_grid(. ~ factor(profile, levels = c("NP-3", "NP-5", "NP-4", "NP-2", "NP-1")),
facet_grid(. ~ factor(profile, levels = c("NP-3", "NP-1", "NP-2")),
scales = "free"
) +
# ggplot2::geom_jitter(width = 2, alpha = alpha, size = 1.5, show.legend = FALSE) +
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 ff70e7a

Please sign in to comment.