Computes the Dietary Species Richness (DSR) score from cleaned dietary recall data. The function counts the number of distinct species consumed per respondent or recall ID. Users can either use the package FCT database (online CSV) or supply their own mapping file.
Usage
compute_dsr(
recall_data,
id_col,
food_item_col,
use_fct_db = FALSE,
dsr_map_data = NULL,
dsr_map_food = NULL,
dsr_map_col = NULL,
add_prefix = NULL
)Arguments
- recall_data
A data frame containing at least the ID column and the food item column.
- id_col
Character. Name of the identifier column in
recall_data(e.g.,"survey_id").- food_item_col
Character. Column in
recall_datacontaining food item names.- use_fct_db
Logical, default = FALSE. If TRUE, uses the package's online FCT database (
speciescolumn).- dsr_map_data
Optional. A user-provided mapping data frame with food items and species names. Required if
use_fct_db = FALSE.- dsr_map_food
Character. Column name in
dsr_map_datathat matches food items.- dsr_map_col
Character. Column name in
dsr_map_datacontaining species names.- add_prefix
Optional character. Prefix to add to the output column name (e.g.,
"child"will producechild_dsr).
Value
A tibble with:
The ID column (as provided in
id_col)One column for the computed dietary species richness (
dsror prefixed name)
Details
If
use_fct_db = TRUE, the function pulls from the online FCT database used indietrecallkitR.Foods with
"No Species Assignment"orNAspecies are excluded from the count.Duplicate species per ID are counted once.
Returns warnings for unmapped items.
Examples
# Using online FCT DB
recall_sample <- data.frame(
survey_id = c(1, 1, 2, 2, 3),
desc_of_food = c(
"Rabbit meat, raw",
"Ghee (cow milk)",
"Cheese, cheddar, regular fat",
"Tuna, grilled",
"Rabbit meat, raw"
)
)
result <- compute_dsr(
recall_data = recall_sample,
id_col = "survey_id",
food_item_col = "desc_of_food",
use_fct_db = TRUE
)
print(result)
#> # A tibble: 3 × 2
#> survey_id dsr
#> <dbl> <int>
#> 1 1 2
#> 2 2 2
#> 3 3 1
# Using custom mapping
species_map <- data.frame(
item = c("Rabbit meat, raw", "Tuna, grilled", "Cheese, cheddar, regular fat", "Ghee (cow milk)"),
species = c("Rabbit", "Tuna", "Cow", "Cow")
)
result <- compute_dsr(
recall_data = recall_sample,
id_col = "survey_id",
food_item_col = "desc_of_food",
use_fct_db = FALSE,
dsr_map_data = species_map,
dsr_map_food = "item",
dsr_map_col = "species",
add_prefix = "child"
)
print(result)
#> # A tibble: 3 × 2
#> survey_id child_dsr
#> <dbl> <int>
#> 1 1 2
#> 2 2 2
#> 3 3 1