-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_02-08_social.qmd
392 lines (353 loc) · 11 KB
/
_02-08_social.qmd
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
## Social Cognition {#sec-social}
{{< include _02-08_social_text.qmd >}}
```{r}
#| label: setup-social
#| include: false
# domain
domains <- c("Social Cognition")
# phenotype
pheno <- "social"
```
```{r}
#| label: export-social
#| include: false
# Read the CSV file into a data frame
social1 <- vroom::vroom("neurocog.csv")
social2 <- vroom::vroom("neurobehav.csv")
social <- dplyr::bind_rows(social1, social2)
# Filter the data frame based on certain conditions
social <- social |>
dplyr::filter(domain %in% domains)
# Select specific columns from the data frame
social <- social |>
dplyr::select(
test,
test_name,
scale,
raw_score,
score,
ci_95,
percentile,
range,
domain,
subdomain,
narrow,
pass,
verbal,
timed,
description,
result,
z,
z_mean_domain,
z_sd_domain,
z_mean_subdomain,
z_sd_subdomain,
z_mean_narrow,
z_sd_narrow,
z_mean_pass,
z_sd_pass,
z_mean_verbal,
z_sd_verbal,
z_mean_timed,
z_sd_timed
)
# Write the 'social' data frame to a CSV file
# The file name is derived from the 'pheno' variable
readr::write_excel_csv(social, paste0(pheno, ".csv"), na = "", col_names = TRUE, append = FALSE)
```
```{r}
#| label: data-social
#| include: false
# read and filter data
data <- social
scales <- c(
"Affect Recognition",
"Theory of Mind",
"Theory of Mind Verbal",
"Affect Recognition",
"Affect Recognition Happy Errors",
"Affect Recognition Sad Errors",
"Affect Recognition Neutral Errors",
"Affect Recognition Fear Errors",
"Affect Recognition Angry Errors",
"Affect Recognition Disgust Errors",
"Social Perception",
"Affect Naming",
"Prosody-Face Matching",
"Prosody-Pair Matching",
"Faces I",
"Faces II",
"Names I",
"Names II",
"Restricted/Repetitive Behaviors",
"Social Interaction",
"Social Communication",
"Emotional Responses",
"Cognitive Style",
"Maladaptive Speech",
"Autism Index",
# CARS-2
"Relating to People",
"Imitation",
"Emotional Response",
"Body Use",
"Object Use",
"Adaptation to Change",
"Visual Response",
"Listening Response",
"Taste, Smell, and Touch Response and Use",
"Fear or Nervousness",
"Verbal Communication",
"Nonverbal Communication",
"Activity Level",
"Level of Consistency of Intellectual Response",
"General Impressions",
"CARS-2 Total Score",
# CARS-2 High Functioning Version
"Social-Emotional Understanding",
"Emotional Expression and Regulation of Emotions",
"Relating to People",
"Body Use",
"Object Use in Play",
"Adaptation to Change/Restricted Interests",
"Visual Response",
"Listening Response",
"Taste, Smell, and Touch Response and Use",
"Fear or Anxiety",
"Verbal Communication",
"Nonverbal Communication",
"Thinking/Cognitive Integration Skills",
"Level of Consistency of Intellectual Response",
"General Impressions",
"CARS 2-HF Total Score"
)
# Filter the data using the filter_data function from the bwu library
# The domain is specified by the 'domains' variable
# The scale is specified by the 'scales' variable
data_social <- bwu::filter_data(data, domain = domains, scale = scales)
```
```{r}
#| label: text-social
#| cache: true
#| include: false
# Generate the text for the social domain
bwu::cat_neuropsych_results(data = data_social, file = "_02-08_social_text.qmd")
```
```{r}
#| label: qtbl-social
#| dev: tikz
#| fig-process: pdf2png
#| include: false
# Set the default engine for tikz to "xetex"
options(tikzDefaultEngine = "xetex")
# table arguments
table_name <- "table_social"
vertical_padding <- 0
multiline <- TRUE
# footnotes
fn_standard_score <- gt::md("Index score: Mean = 100 [50th‰], SD ± 15 [16th‰, 84th‰]")
fn_scaled_score <- gt::md("Scaled score: Mean = 10 [50th‰], SD ± 3 [16th‰, 84th‰]")
fn_t_score <- gt::md("T-score: Mean = 50 [50th‰], SD ± 10 [16th‰, 84th‰]")
fn_z_score <- gt::md("z-score: Mean = 0 [50th‰], SD ± 1 [16th‰, 84th‰]")
fn_raw_score <- gt::md("Raw score: Range = 0-4")
# Groupings
grp_social <- list(
# scaled_score = c("NEPSY-2", "ACS Social Cognition"),
# t_score = c("CARS-2", "GARS-3", "CARS-2 HF", "CARS-2 High Functioning Version", "CARS 2-HF"),
raw_score = c("CARS-2", "CARS-2 HF", "CARS 2-HF")
)
data_social <- data_social |> dplyr::select(c(test_name, scale, raw_score, score, percentile, range))
# tbl_gt2 <-
# function(data,
# pheno = NULL,
# table_name = NULL,
# source_note = NULL,
# names = NULL,
# title = NULL,
# tab_stubhead = NULL,
# caption = NULL,
# process_md = FALSE,
# fn_scaled_score = NULL,
# fn_standard_score = NULL,
# fn_t_score = NULL,
# fn_z_score = NULL,
# fn_raw_score = NULL,
# grp_scaled_score = NULL,
# grp_standard_score = NULL,
# grp_t_score = NULL,
# grp_z_score = NULL,
# grp_raw_score = NULL,
# dynamic_grp,
# vertical_padding = NULL,
# multiline = TRUE,
# ...,
# # Add a new argument to control displayed columns
# table_vars = c("range")) {
# # Create data counts
# data_counts <- data |>
# dplyr::select(test_name, scale, all_of(table_vars)) |>
# dplyr::mutate(across(any_of(c("score", "percentile", "raw_score")), ~ tidyr::replace_na(., replace = 0)))
# # Create table
# table <- data_counts |>
# dplyr::mutate(
# score = if_else(score == 0, NA_integer_, score),
# percentile = if_else(percentile == 0, NA_integer_, percentile),
# test_name = as.character(paste0(test_name)),
# scale = as.character(scale)
# ) |>
# # gt table formatting
# gt::gt(
# rowname_col = "scale",
# groupname_col = "test_name",
# process_md = process_md,
# caption = caption,
# rownames_to_stub = FALSE,
# id = paste0("table_", pheno)
# ) |>
# cols_label(
# test_name = md("**Test**"),
# scale = md("**Scale**"),
# raw_score = md("**Raw Score**"),
# score = md("**Score**"),
# percentile = md("**‰ Rank**"),
# range = md("**Range**")
# ) |>
# tab_header(title = title) |>
# tab_stubhead(label = tab_stubhead) |>
# sub_missing(missing_text = "--") |>
# tab_stub_indent(rows = scale, indent = 2) |>
# cols_align(
# align = "center",
# # Use any_of to dynamically select columns
# columns = any_of(c("raw_score", "score", "percentile", "range"))
# )
# # Extract unique row groups from the data to check against the groups we want to apply footnotes to
# existing_row_groups <- unique(data$test_name)
# # Filter out non-existent groups
# grp_scaled_score <- intersect(grp_scaled_score, existing_row_groups)
# grp_standard_score <- intersect(grp_standard_score, existing_row_groups)
# grp_t_score <- intersect(grp_t_score, existing_row_groups)
# grp_z_score <- intersect(grp_z_score, existing_row_groups)
# grp_raw_score <- intersect(grp_raw_score, existing_row_groups)
# # Concatenate footnotes
# fn_combined <- list(
# scaled_score = fn_scaled_score,
# standard_score = fn_standard_score,
# t_score = fn_t_score,
# z_score = fn_z_score,
# raw_score = fn_raw_score
# )
# # Add footnotes
# for (score_type in names(fn_combined)) {
# fn <- fn_combined[[score_type]]
# groups <- get(paste0("grp_", score_type))
# if (!is.null(fn) && any(groups %in% dynamic_grp[[score_type]])) {
# table <- table |>
# tab_footnote(
# footnote = glue::glue_collapse(fn, sep = " "),
# locations = cells_row_groups(groups = groups)
# )
# }
# }
# # Adding source note
# table <- table |>
# tab_style(style = cell_text(size = "small"), locations = cells_source_notes()) |>
# tab_source_note(source_note = source_note) |>
# gtExtras::gt_theme_538() |>
# tab_options(
# row_group.font.weight = "bold",
# footnotes.multiline = multiline,
# footnotes.font.size = "small"
# ) |>
# opt_vertical_padding(scale = vertical_padding)
# gt::gtsave(table, glue::glue("table_{pheno}.pdf"))
# gt::gtsave(table, glue::glue("table_{pheno}.png"))
# return(table)
# }
# make `gt` table
bwu::tbl_gt(
data = data_social,
pheno = pheno,
table_name = table_name,
# table_vars = c("raw_score", "range"),
# fn_scaled_score = fn_scaled_score,
# fn_t_score = fn_t_score,
fn_raw_score = fn_raw_score,
# grp_scaled_score = grp_social[["scaled_score"]],
# grp_t_score = grp_social[["t_score"]],
grp_raw_score = grp_social[["raw_score"]],
dynamic_grp = grp_social,
vertical_padding = vertical_padding,
multiline = multiline
)
```
```{r}
#| label: fig-social
#| include: false
#| eval: true
#| fig-cap: "Social cognition measures are used to gauge aspects of social-emotional processing and social aptitude (sometimes referred to as _emotional intelligence_), which are important facets of how individuals process social information about other children, adults, groups, and social contexts."
# Filter the data frame to include only the specified scales
exclude <- c(
"CARS-2 Total Score",
"Theory of Mind Verbal",
"Affect Recognition",
"CARS 2-HF Total Score"
)
data_social <- data_social |>
dplyr::filter(!(scale %in% exclude))
# Dotplot args
x <- data_social$raw_score
y <- data_social$scale
colors <- NULL
return_plot <- Sys.getenv("RETURN_PLOT")
filename <- "fig_social.svg"
# Suppress warnings from being converted to errors
options(warn = 1) # Set warn to 1 to make warnings not halt execution
# Plotting function call
bwu::dotplot(
data = data_social,
x = x,
y = y,
colors = colors,
return_plot = return_plot,
filename = filename,
na.rm = TRUE
)
# Reset warning options to default if needed
options(warn = 0) # Reset to default behavior
```
```{=typst}
#let domain(title: none, file_qtbl, file_fig) = {
let font = (font: "Roboto Slab", size: 0.5em)
set text(..font)
pad(top: 0.5em)[]
grid(
columns: (50%, 50%),
gutter: 8pt,
figure([#image(file_qtbl)],
caption: figure.caption(position: top, [#title]),
kind: "qtbl",
supplement: [Table],
),
figure([#image(file_fig, width: auto)],
caption: figure.caption(position: bottom, [
Social cognition and autism spectrum disorder (ASD) measures are used to gauge aspects of social-emotional processing and social aptitude (sometimes referred to as _emotional intelligence_), which are important facets of how individuals process social information about other children, adults, groups, and social contexts.
]),
placement: none,
kind: "image",
supplement: [Figure],
gap: 0.5em,
),
)
}
```
```{=typst}
#let title = "Social Cognition"
#let file_qtbl = "table_social.png"
#let file_fig = "fig_social.svg"
#domain(
title: [#title Scores],
file_qtbl,
file_fig
)
```