Skip to content

Commit

Permalink
Update codebook files
Browse files Browse the repository at this point in the history
  • Loading branch information
edambo committed Sep 17, 2024
1 parent e42be2d commit d1913dd
Show file tree
Hide file tree
Showing 8 changed files with 705 additions and 25 deletions.
Binary file modified codebooks/aps_investigations_codebook.docx
Binary file not shown.
2 changes: 1 addition & 1 deletion codebooks/data_06_self_report_codebook.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ library(codebookr)
library(dplyr, warn.conflicts = FALSE)
library(readr)
library(here)
source("../r/variable_descriptions.R")
source(here::here("r", "variable_descriptions.R"))
```

# Purpose of the program
Expand Down
Binary file modified codebooks/self_report_codebook.docx
Binary file not shown.
27 changes: 27 additions & 0 deletions codebooks/variable_labels/aps_investigations_var_lab.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name,description,label
x_primary_key,Unique record ID used internally by the database,
x_created_by,Person who created the record,
x_created_timestamp,Timestamp when the record was created,
x_modified_by,Person who modified the record,
x_modified_timestamp,Timestamp when the record was modified,
x_record_status,Status of the record as determined by research team,
x_error_message,Error message entered by research team,
medstar_id,Unique record number in MedStar System,
name_full,Full name of older individual,Full name
aps_report,AI_1. Has anyone from Adult Protective Services ever attempted to investigate whether or not you were living with elder abuse or neglect?,Previous APS investigation attempt
aps_report_2cat,AI_1. Has anyone from Adult Protective Services ever attempted to investigate whether or not you were living with elder abuse or neglect?,Previous APS investigation attempt
aps_report_2cat_f,AI_1. Has anyone from Adult Protective Services ever attempted to investigate whether or not you were living with elder abuse or neglect?,Previous APS investigation attempt
aps_times,AI_2. How many times has this happened in your life?,Number of APS investigation attempts
aps_times_3cat,AI_2. How many times has this happened in your life?,Number of APS investigation attempts
aps_times_3cat_f,AI_2. How many times has this happened in your life?,Number of APS investigation attempts
aps_first,AI_3. When was the first time APS attempted to do an investigation?,First APS investigation attempt
aps_first_6cat,AI_3. When was the first time APS attempted to do an investigation?,First APS investigation attempt
aps_first_6cat_f,AI_3. When was the first time APS attempted to do an investigation?,First APS investigation attempt
aps_recent,AI_4. When was the most recent time APS attempted to do an investigation?,Most recent APS investigation attempt
aps_recent_6cat,AI_4. When was the most recent time APS attempted to do an investigation?,Most recent APS investigation attempt
aps_recent_6cat_f,AI_4. When was the most recent time APS attempted to do an investigation?,Most recent APS investigation attempt
x_record_month,Month record was created,
x_record_year,Year record was created,
x_record_comment,Comments by interviewer,
xc_case_id,Calculated by the database from the last 5 characters of the MedstarID,
xc_lead_panel_summary_count,"Calculated count of positive abuse instances across SelfReport, ApsInvestigations, and ObservationalMeasures",
575 changes: 575 additions & 0 deletions codebooks/variable_labels/self_report_var_lab.csv

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions codebooks/variable_labels/variable_labels.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: "Create data sets of variable labels."
---

```{r}
# Load necessary packages and functions
library(dplyr, warn.conflicts = FALSE)
library(readr)
library(here)
library(expss, warn.conflicts = FALSE)
source(here::here("r", "variable_descriptions.R"))
```

# Purpose of the program

RDS files containing descriptions for each variable have been created. Variable labels similar to what is seen in SAS data sets will be created for each variable. These will be added manually.

# APS Investigations

## Load cleaned data

```{r}
# APS Investigations data set
aps_path <- here::here("data", "cleaned_rds_files", "aps_investigations_import.rds")
aps <- readr::read_rds(aps_path)
# APS Investigations variable descriptions
aps_var_desc_path <- here::here("codebooks", "variable_descriptions", "aps_investigations_var_desc.rds")
aps_var_desc <- readr::read_rds(aps_var_desc_path)
```

## Create CSV file for variable descriptions

A label column will be created manually in Microsoft Excel

```{r}
aps_var_desc_path <- here::here("codebooks", "variable_labels", "aps_investigations_var_lab.csv")
readr::write_csv(aps_var_desc, aps_var_desc_path)
```

## Load CSV file with added label column

```{r, include = FALSE}
aps_var_labs <- readr::read_csv(aps_var_desc_path)
```

## Add the labels to the data frame

```{r}
add_labs <- function(label_df, df){
labels_named_vec <- setNames(label_df[["label"]], label_df[["name"]]) %>% as.list()
result <- apply_labels(df, labels_named_vec)
}
```

```{r}
aps_lab <- add_labs(aps_var_labs, aps)
```


# Self Report

## Load cleaned data

```{r}
# Self report data set
sr_path <- here::here("data", "cleaned_rds_files", "self_report_import.rds")
sr <- readr::read_rds(sr_path)
# Self report variable descriptions
sr_var_desc_path <- here::here("codebooks", "variable_descriptions", "self_report_var_desc.rds")
sr_var_desc <- readr::read_rds(sr_var_desc_path)
```

## Create CSV file for variable descriptions

A label column will be created manually in Microsoft Excel

```{r}
sr_var_desc_path <- here::here("codebooks", "variable_labels", "self_report_var_lab.csv")
readr::write_csv(sr_var_desc, sr_var_desc_path)
```

## Load CSV file with added label column

```{r, include = FALSE}
aps_var_labs <- readr::read_csv(aps_var_desc_path)
```

## Add the labels to the data frame

```{r}
add_labs <- function(label_df, df){
labels_named_vec <- setNames(label_df[["label"]], label_df[["name"]]) %>% as.list()
result <- apply_labels(df, labels_named_vec)
}
```

```{r}
aps_lab <- add_labs(aps_var_labs, aps)
```
4 changes: 1 addition & 3 deletions exploratory/lead_data_analysis.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ participant |>
```

```{r}
# Keep only the columns of interest
# Select the columns of interest
parti <- participant |>
select(
medstar_id, x_created_timestamp, x_record_month, x_record_year,
Expand Down Expand Up @@ -349,8 +349,6 @@ pos_det <- purrr::reduce(list(part_id, any_pos_abuse), dplyr::right_join, by = "
# write_xlsx(pos_det, "LEAD_positive_determination_list.xlx")
```



## Merge participant, observational measures, sociodemographic and LEAD dateframes

```{r}
Expand Down
21 changes: 0 additions & 21 deletions r/extract_df_from_merged_detect.R

This file was deleted.

0 comments on commit d1913dd

Please sign in to comment.