calc_cohesion: Calculate Neighborhood Cohesion Score

View source: R/calc_cohesion.R

calc_cohesionR Documentation

Calculate Neighborhood Cohesion Score

Description

This function computes a neighborhood cohesion score ranging from 1 to 5 based on survey responses. The score is the mean of four specific item scores, where higher scores indicate greater neighborhood cohesion.

Usage

calc_cohesion(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 'cohesion', where 'cohesion' is the calculated cohesion score for each participant. Participants who did not answer all four questions will have an NA score.

Examples

# Create a sample survey data frame
survey_df <- data.frame(
  person_id = c(1, 1, 2, 2, 3, 3, 4, 4),
  question_concept_id = c(40192463, 40192411, 40192463, 40192411,
                          40192499, 40192417, 40192499, 40192417),
  answer_concept_id = c(40192514, 40192455, 40192524, 40192408,
                        40192514, 40192524, 40192408, 40192422)
)

# Compute neighborhood cohesion scores
cohesion_scores <- calc_cohesion(survey_df)
head(cohesion_scores)


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