Learn R Programming

AOUSDOHtools (version 1.0.4)

calc_hcd_sum: Calculate Sum of Perceived Health Care Discrimination Score

Description

This function creates a numeric score (range 7-35) that reflects the sum of perceived discrimination in health care based on responses to seven specific survey items. Higher scores indicate greater perceived discrimination in health care.

Usage

calc_hcd_sum(survey_df)

Value

A data frame with two columns: `person_id` and `hcd_sum`, where `hcd_sum` represents the sum of perceived discrimination in health care. Participants who did not respond to all 7 items will have an NA value for `hcd_sum`.

Arguments

survey_df

A data frame containing survey data with at least three columns: `person_id`, `question_concept_id`, and `answer_concept_id`.

Examples

Run this code
# Create a sample survey data frame
survey_df <- data.frame(
  person_id = rep(1:3, each = 7),
  question_concept_id = rep(c(40192383, 40192394, 40192423, 40192425,
                              40192497, 40192503, 40192505), times = 3),
  answer_concept_id = sample(c(40192465, 40192481, 40192429, 40192382, 40192515),
                             21, replace = TRUE)
)

# Compute sum of perceived health care discrimination scores
hcd_sum_scores <- calc_hcd_sum(survey_df)
head(hcd_sum_scores)

Run the code above in your browser using DataLab