-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_management_hyp_1.R
More file actions
71 lines (66 loc) · 1.69 KB
/
data_management_hyp_1.R
File metadata and controls
71 lines (66 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
library(tidyverse)
############
# Load dfs #
############
source("data_wrangling.R")
# if (exists("df_1") == F){
# source("data_wrangling.R")
# }
# if (exists("df_essential_vars") == F){
# load(file = "G:\\data_wrangling.Rdata")
# source("helper.R")
# }
vars <- c(
"school_cohort_fct",
"fam_id",
"twin_id",
"sex_1",
"sex_1_fct",
"zygosity_binary_fct",
"eating_diagnosis_fct_26_1",
"eating_diagnosis_26_1",
# Ses & ethnicity serve as auxiliary vars,
# because they have many obs and are loosely associated with
# Bullying and BDD
"ses_1st_contact",
"ethnic_fct",
"age_parent_12",
"age_teach_12_1",
"age_child_12_1",
"age_parent_14",
"age_teach_14_1",
"age_child_14_1",
"age_child_web_16_1",
"age_phase1_parent_21",
"age_phase2_child_21_1",
"age_cov1_child_21_1",
"age_cov2_child_21_1",
"age_cov3_child_21_1",
"age_cov4_child_21_1",
"age_26_1",
colnames(df_1)[grepl(pattern = "mpvs_total", x = colnames(df_1))],
"dcq_total_26_1",
"dcq_total_26_1_cutoff11",
"dcq_total_26_1_cutoff11_numeric",
"dcq_total_26_1_cutoff17",
"dcq_total_26_1_cutoff17_numeric"
)
df_essential_vars <- df_1 %>%
dplyr::select(all_of(vars))
df_essential_vars <- scale_mpvs(
df = df_essential_vars,
scale_size = 32,
from_vars = colnames(df_essential_vars)[grepl(pattern = "mpvs_total", x = colnames(df_essential_vars))]
)
# Mean var across waves, without omitting NAs
mpvs_vars <- c(
"mpvs_total_12_1_scaled_32",
"mpvs_total_child_14_1_scaled_32",
"mpvs_total_16_1_scaled_32",
"mpvs_total_phase_2_21_1_scaled_32"
)
df_essential_vars <- cbind(
df_essential_vars,
data.frame(mpvs_mean_scaled_32 = rowMeans(df_essential_vars[, mpvs_vars], na.rm = T))
)
rm("mpvs_vars")