calc_density: Calculate Residential Density

View source: R/calc_density.R

calc_densityR Documentation

Calculate Residential Density

Description

This function creates a binary categorical variable representing residential density based on survey responses. 'Low' denotes low residential density (detached single-family housing), while 'High' denotes high residential density.

Usage

calc_density(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 'density', where 'density' is either "High" or "Low" based on the housing type in the neighborhood. Participants with non-answers will have an NA value for 'density'.

Examples

# Create a sample survey data frame
survey_df <- data.frame(
  person_id = c(1, 2, 3, 4, 5),
  question_concept_id = c(40192458, 40192458, 40192458, 40192458, 40192458),
  answer_concept_id = c(40192407, 40192472, 40192418, 40192433, 40192409)
)

# Compute residential density categories
density_scores <- calc_density(survey_df)
head(density_scores)


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