View source: R/calc_food_insecurity.R
calc_food_insecurity | R Documentation |
This function creates a binary categorical variable (TRUE/FALSE) indicating whether a participant is at risk or currently experiencing food insecurity based on their responses to two specific survey items.
calc_food_insecurity(survey_df)
survey_df |
A data frame containing survey data with at least three columns: 'person_id', 'question_concept_id', and 'answer_concept_id'. |
A data frame with two columns: 'person_id' and 'food_insecurity', where 'food_insecurity' is TRUE if the participant reported experiencing food insecurity, and FALSE otherwise. Participants who did not respond to both questions will have an NA value for 'food_insecurity'.
# Create a sample survey data frame
survey_df <- data.frame(
person_id = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5),
question_concept_id = rep(c(40192426, 40192517), 5),
answer_concept_id = c(40192508, 40192488, 40192508, 903096, 903096, 903096,
40192488, 40192488, 40192508, 40192508)
)
# Compute food insecurity risk scores
food_insecurity_scores <- calc_food_insecurity(survey_df)
head(food_insecurity_scores)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.