Skip to content

Commit

Permalink
Merge pull request #1 from brad-cannell/main
Browse files Browse the repository at this point in the history
Catch up to main repository
  • Loading branch information
corvidfox authored Oct 2, 2024
2 parents c2e002d + d1913dd commit c120281
Show file tree
Hide file tree
Showing 19 changed files with 3,200 additions and 1,405 deletions.
Binary file modified codebooks/aps_investigations_codebook.docx
Binary file not shown.
72 changes: 47 additions & 25 deletions codebooks/data_01_aps_investigations_codebook.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ title: "Create APS Investigations Codebook"
library(codebookr)
library(dplyr, warn.conflicts = FALSE)
library(haven)
library(here)
library(readr)
source("../r/variable_descriptions.R")
```
Expand All @@ -18,8 +19,11 @@ Using the CodebookR package, we will create a data dictionary for follow-up inte

# Load cleaned data
```{r}
#| warning: false
aps_inv <- read_rds("../data/cleaned_rds_files/aps_investigations_import.rds")
aps_inv_path <- here::here("data", "cleaned_rds_files", "aps_investigations_import.rds")
```

```{r}
aps_inv <- readr::read_rds(aps_inv_path)
```

# Set column attributes
Expand Down Expand Up @@ -98,42 +102,53 @@ aps_inv <- aps_inv %>%
description = "Full name of older individual"
) %>%
cb_add_col_attributes(
aps_report_4cat,
aps_report,
description = "AI_1. Has anyone from Adult Protective Services ever attempted to investigate whether or not you were living with elder abuse or neglect?",
skip_pattern = "Skip to section 6 if any answer is given but Yes"
) %>%
cb_add_col_attributes(
aps_report_2cat,
description = "AI_1. Has anyone from Adult Protective Services ever attempted to investigate whether or not you were living with elder abuse or neglect?",
skip_pattern = "Skip to section 6 if any answer is given but Yes",
value_labels = c(
"Yes" = 1,
"No" = 2,
"Don’t know" = 7,
"Refused" = 9
"No" = 0,
"Yes" = 1
),
col_type = "Categorical"
) %>%
cb_add_col_attributes(
aps_report_4cat_f,
aps_report_2cat_f,
description = "AI_1. Has anyone from Adult Protective Services ever attempted to investigate whether or not you were living with elder abuse or neglect?",
skip_pattern = "Skip to section 6 if any answer is given but Yes"
) %>%
cb_add_col_attributes(
aps_times_5cat,
aps_times,
description = "AI_2. How many times has this happened in your life?",
skip_pattern = "If answer is 0 or Refused, go to Section 6. If answer is 1 go to AI_4."
) %>%
cb_add_col_attributes(
aps_times_3cat,
description = "AI_2. How many times has this happened in your life?",
skip_pattern = "If answer is 0 or Refused, go to Section 6. If answer is 1 go to AI_4.",
value_labels = c(
"0" = 0,
"1" = 1,
"2+" = 2,
"Don’t know" = 7,
"Refused" = 9
"2+" = 2
),
col_type = "Categorical"
) %>%
cb_add_col_attributes(
aps_times_5cat_f,
aps_times_3cat_f,
description = "AI_2. How many times has this happened in your life?",
skip_pattern = "If answer is 0 or Refused, go to Section 6. If answer is 1 go to AI_4."
) %>%
cb_add_col_attributes(
aps_first_8cat,
aps_first,
description = "AI_3. When was the first time APS attempted to do an investigation?",
skip_pattern = "If answer is Refused, go to Section 6. If answer is 1 to 7, go to AI_4."
) %>%
cb_add_col_attributes(
aps_first_6cat,
description = "AI_3. When was the first time APS attempted to do an investigation?",
skip_pattern = "If answer is Refused, go to Section 6. If answer is 1 to 7, go to AI_4.",
value_labels = c(
Expand All @@ -142,34 +157,34 @@ aps_inv <- aps_inv %>%
"1-5 years ago" = 3,
"In the past year but more than a month ago" = 4,
"In the past month" = 5,
"In the past week" = 6,
"Don’t know" = 7,
"Refused" = 9
"In the past week" = 6
),
col_type = "Categorical"
) %>%
cb_add_col_attributes(
aps_first_8cat_f,
aps_first_6cat_f,
description = "AI_3. When was the first time APS attempted to do an investigation?",
skip_pattern = "If answer is Refused, go to Section 6. If answer is 1 to 7, go to AI_4."
) %>%
cb_add_col_attributes(
aps_recent_8cat,
aps_recent,
description = "AI_4. When was the most recent time APS attempted to do an investigation?"
) %>%
cb_add_col_attributes(
aps_recent_6cat,
description = "AI_4. When was the most recent time APS attempted to do an investigation?",
value_labels = c(
"In the past week" = 1,
"In the past month" = 2,
"In the past year but more than a month ago" = 3,
"1-5 years ago" = 4,
"5-10 years ago" = 5,
"10 or more years ago" = 6,
"Don’t know" = 7,
"Refused" = 9
"10 or more years ago" = 6
),
col_type = "Categorical"
) %>%
cb_add_col_attributes(
aps_recent_8cat_f,
aps_recent_6cat_f,
description = "AI_4. When was the most recent time APS attempted to do an investigation?"
)
```
Expand All @@ -194,10 +209,14 @@ aps_inv_desc <- var_descriptions(aps_inv)


## Save as rds file

```{r}
write_rds(aps_inv_desc, "../codebooks/variable_descriptions/aps_investigations_var_desc.rds")
aps_inv_desc_path <- here::here("codebooks", "variable_descriptions", "aps_investigations_var_desc.rds")
```

```{r}
readr::write_rds(aps_inv_desc, aps_inv_desc_path)
```

# Pass data frame to the codebook function
```{r}
Expand All @@ -210,7 +229,10 @@ aps_codebook <- codebook(
)
```

```{r}
aps_codebook_path <- here::here("codebooks", "aps_investigations_codebook.docx")
```

```{r}
print(aps_codebook, "../codebooks/aps_investigations_codebook.docx")
print(aps_codebook, aps_codebook_path)
```
22 changes: 18 additions & 4 deletions codebooks/data_03_clutter_scale_codebook.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ library(codebookr)
library(dplyr, warn.conflicts = FALSE)
library(haven)
library(readr)
library(here)
source("../r/variable_descriptions.R")
```

Expand All @@ -16,9 +17,13 @@ source("../r/variable_descriptions.R")
Using the CodebookR package, we will create a data dictionary for follow-up interview data for the DETECT project pertaining to home inspection and the clutter image rating scale

# Load cleaned data

```{r}
clutter_scale_path <- here::here("data", "cleaned_rds_files", "clutter_scale_import.rds")
```

```{r}
#| warning: false
clutter_scale <- read_rds("../data/cleaned_rds_files/clutter_scale_import.rds")
clutter_scale <- readr::read_rds(clutter_scale_path)
```

# Set column attributes
Expand Down Expand Up @@ -213,10 +218,14 @@ cls_desc <- var_descriptions(clutter_scale)
```

## Save as rds file

```{r}
write_rds(cls_desc, "../codebooks/variable_descriptions/clutter_scale_var_desc.rds")
cls_desc_path <- here::here("codebooks", "variable_descriptions", "clutter_scale_var_desc.rds")
```

```{r}
readr::write_rds(cls_desc, cls_desc_path)
```

# Exclude summary stats for certain variables in word doc

Expand All @@ -242,5 +251,10 @@ clutter_scale_codebook <- codebook(
```

```{r}
print(clutter_scale_codebook, "../codebooks/clutter_scale_codebook.docx")
clutter_scale_codebook_path <- here::here("codebooks", "clutter_scale_codebook.docx")
```

```{r}
print(clutter_scale_codebook, clutter_scale_codebook_path)
```

Loading

0 comments on commit c120281

Please sign in to comment.