calc_disorder: Calculate Neighborhood Disorder Score

View source: R/calc_disorder.R

calc_disorderR Documentation

Calculate Neighborhood Disorder Score

Description

This function computes a neighborhood disorder score ranging from 1 to 4 based on survey responses. The score is the mean of 13 specific item scores, where higher scores indicate a greater sense of disorder in the neighborhood, and lower scores indicate a sense of order. Some items are reverse-coded to ensure consistency in interpretation.

Usage

calc_disorder(survey_df)

Arguments

survey_df

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

Value

A data frame with two columns: 'person_id' and 'disorder', where 'disorder' is the calculated neighborhood disorder score for each participant. Participants who did not answer all 13 questions will have an NA score.

Examples

# Create a sample survey data frame
survey_df <- data.frame(
  person_id = rep(1:3, each = 13),
  question_concept_id = rep(c(40192420, 40192522, 40192412, 40192469, 40192456,
                              40192386, 40192500, 40192493, 40192457, 40192476,
                              40192404, 40192400, 40192384), times = 3),
  answer_concept_id = sample(c(40192514, 40192455, 40192408, 40192422),
                      39, replace = TRUE)
)

# Compute neighborhood disorder scores
disorder_scores <- calc_disorder(survey_df)
head(disorder_scores)


AOUSDOHtools documentation built on April 3, 2025, 8:11 p.m.