View source: R/calc_edd_chronicity.R
calc_edd_chronicity | R Documentation |
This function computes a chronicity score indicating the total number of perceived discrimination experiences in a year. The score ranges from 0 to 2340, where higher scores indicate more frequent perceived unfair treatment. The function also allows for filtering by a specific reason for discrimination.
calc_edd_chronicity(survey_df, reason)
survey_df |
A data frame containing survey data with at least three columns: 'person_id', 'question_concept_id', and 'answer_concept_id'. |
reason |
An optional argument specifying the reason for perceived discrimination, e.g., race or age. If provided, the function will limit the analysis to participants who reported this reason. |
A data frame with two columns: 'person_id' and 'edd_chronicity', where 'edd_chronicity' is the calculated chronicity score for each participant. Participants who did not answer all 9 questions or did not specify the given reason (if provided) will have an NA score.
# Create a sample survey data frame
survey_df <- data.frame(
person_id = rep(1:3, each = 9),
question_concept_id = rep(c(40192380, 40192395, 40192416, 40192451, 40192466,
40192489, 40192490, 40192496, 40192519), times = 3),
answer_concept_id = sample(c(40192465, 40192464, 40192453, 40192461, 40192391,
40192421), 27, replace = TRUE)
)
# Compute everyday discrimination chronicity scores
edd_chronicity_scores <- calc_edd_chronicity(survey_df)
head(edd_chronicity_scores)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.