View source: R/calc_cohesion.R
calc_cohesion | R Documentation |
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.
calc_cohesion(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 'cohesion', where 'cohesion' is the calculated cohesion score for each participant. Participants who did not answer all four questions will have an NA score.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.