-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_02-01_iq.qmd
More file actions
executable file
·356 lines (314 loc) · 9.4 KB
/
_02-01_iq.qmd
File metadata and controls
executable file
·356 lines (314 loc) · 9.4 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
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
## General Cognitive Ability {#sec-iq}
{{< include _02-01_iq_text.qmd >}}
```{r}
#| label: setup-iq
#| include: false
# Filter by domain
domains <- c("General Cognitive Ability")
# Target phenotype
pheno <- "iq"
# Read the CSV file into a data frame
iq <- readr::read_csv("data/neurocog.csv")
```
```{r}
#| label: export-iq
#| include: false
#| eval: true
iq <- iq |>
dplyr::filter(domain %in% domains)
# Select specific columns from the data frame
iq <- iq |>
dplyr::select(
test,
test_name,
scale,
raw_score,
score,
ci_95,
percentile,
range,
domain,
subdomain,
narrow,
pass,
verbal,
timed,
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 resulting data frame to a new CSV file
readr::write_excel_csv(
iq,
here::here("data", paste0(pheno, ".csv")),
na = "",
col_names = TRUE,
append = FALSE
)
```
```{r}
#| label: data-iq
#| include: false
#| eval: true
# Define the scales of interest
scales <- c(
"Auditory Working Memory (AWMI)",
"Cognitive Proficiency (CPI)",
"Crystallized Knowledge",
"Fluid Reasoning (FRI)",
"Fluid Reasoning",
"Full Scale (FSIQ)",
"Full Scale IQ (FSIQ)",
"General Ability (GAI)",
"General Ability",
"General Intelligence",
"Global Neurocognitive Index (G)",
"NAB Attention Index",
"NAB Executive Functions Index",
"NAB Language Index",
"NAB Memory Index",
"NAB Spatial Index",
"NAB Total Index",
"Nonverbal (NVI)",
"Perceptual Reasoning (PRI)",
"Perceptual Reasoning",
"Processing Speed (PSI)",
"Processing Speed",
"RBANS Total Index",
"Test of Premorbid Functioning",
"TOPF Standard Score",
"Total NAB Index (T-NAB)",
"Verbal Comprehension (VCI)",
"Verbal Comprehension",
"Visual Perception/Construction",
"Visual Spatial (VSI)",
"Vocabulary Acquisition (VAI)",
"Word Reading",
"Working Memory (WMI)",
"Working Memory",
"Attention Index (ATT)",
"Language Index (LAN)",
"Spatial Index (SPT)",
"Memory Index (MEM)",
"Executive Functions Index (EXE)"
)
# Filter the data using the filter_data function from the bwu library
data_iq <- bwu::filter_data(data = iq, domain = domains, scale = scales)
```
```{r}
#| label: text-iq
#| cache: true
#| include: false
# export text
bwu::cat_neuropsych_results(data = data_iq, file = "_02-01_iq_text.qmd")
```
```{r}
#| label: qtbl-iq
#| dev: tikz
#| fig-process: pdf2png
#| include: false
#| eval: true
# Set the default engine for tikz to "xetex"
options(tikzDefaultEngine = "xetex")
# Define the scales to include
subset <- c(
"Auditory Working Memory (AWMI)",
"Cognitive Proficiency (CPI)",
"Crystallized Knowledge",
"Fluid Reasoning (FRI)",
"Fluid Reasoning",
"Full Scale (FSIQ)",
"Full Scale IQ (FSIQ)",
"General Ability (GAI)",
"General Ability",
"General Intelligence",
"Global Neurocognitive Index (G)",
"NAB Attention Index",
"NAB Executive Functions Index",
"NAB Language Index",
"NAB Memory Index",
"NAB Spatial Index",
"NAB Total Index",
"Nonverbal (NVI)",
"Perceptual Reasoning (PRI)",
"Perceptual Reasoning",
"Processing Speed (PSI)",
"Processing Speed",
"RBANS Total Index",
"Test of Premorbid Functioning",
"TOPF Standard Score",
"Total NAB Index (T-NAB)",
"Verbal Comprehension (VCI)",
"Verbal Comprehension",
"Visual Perception/Construction",
"Visual Spatial (VSI)",
"Vocabulary Acquisition (VAI)",
"Word Reading",
"Working Memory (WMI)",
"Working Memory",
"Attention Index (ATT)",
"Language Index (LAN)",
"Spatial Index (SPT)",
"Memory Index (MEM)",
"Executive Functions Index (EXE)"
)
# Filter the data to subset only the specified scales
data_iq <- dplyr::filter(data_iq, scale %in% subset)
# Define the table name, vertical padding, and multiline setting
pheno <- "iq"
table_name <- "table_iq"
vertical_padding <- 0
multiline <- TRUE
# footnotes
fn_standard_score <- gt::md(
"Standard score: Mean = 100 [50th‰], SD ± 15 [16th‰, 84th‰]"
)
source_note <- gt::md(
"Standard score: Mean = 100 [50th‰], SD ± 15 [16th‰, 84th‰]"
)
# Define the groups for the table
grp_iq <- list(
standard_score = c(
"Composite Scores",
"Test of Premorbid Functioning",
"WAIS-5",
"WAIS-IV",
"WAIS-4",
"WASI-2",
"WISC-5",
"WISC-V",
"WRAT-5",
"KTEA-3",
"NAB",
"NAB-S",
"RBANS",
"WPPSI-IV"
)
)
# Create the table using the NeurotypR::tbl_gt2 function from the bwu library
NeurotypR::tbl_gt(
data = data_iq,
pheno = pheno,
table_name = table_name,
vertical_padding = vertical_padding,
source_note = source_note,
# fn_standard_score = fn_standard_score,
# grp_standard_score = grp_iq[["standard_score"]],
dynamic_grp = grp_iq,
multiline = multiline
)
```
```{r}
#| label: fig-iq-subdomain
#| include: false
#| eval: true
#| fig-cap: "_Premorbid Ability_ is an estimate of an individual's intellectual functioning prior to known or suspected onset of brain disease or dysfunction. _General Ability_ is the overall skill to reason, solve problems, and gain useful knowledge. _Crystallized Knowledge_ involves understanding the world through language and reasoning. _Fluid Reasoning_ is the logical analysis and solution of new problems, identifying underlying patterns, and applying logic."
# Define the x and y variables for the dotplot (as column names)
x <- data_iq$z_mean_subdomain
y <- data_iq$subdomain
# plot args
colors <- NULL
return_plot <- TRUE
filename <- "fig_iq_subdomain.svg"
# Define the scales to keep
# keep <- c("General Ability", "Crystallized Knowledge", "Fluid Reasoning")
# data_iq <- dplyr::filter(data_iq, scale %in% keep)
# source("R/dotplot2_efficient.R")
# Create the dotplot using the dotplot function from the bwu library
NeurotypR::dotplot2(
data = data_iq,
x = x,
y = y,
colors = colors,
return_plot = return_plot,
filename = filename,
na.rm = TRUE
)
```
```{r}
#| label: fig-iq-narrow
#| include: false
#| fig-cap: "_Premorbid Ability_ is an estimate of an individual's intellectual functioning prior to known or suspected onset of brain disease or dysfunction. _General Ability_ is the overall skill to reason, solve problems, and gain useful knowledge. _Crystallized Knowledge_ involves understanding the world through language and reasoning. _Fluid Reasoning_ is the logical analysis and solution of new problems, identifying underlying patterns, and applying logic."
# Define the x and y variables for the dotplot (as column names)
x <- data_iq$z_mean_narrow
y <- data_iq$narrow
# plot args
colors <- NULL
return_plot <- TRUE
# Define the filename for the plot
filename <- "fig_iq_narrow.svg"
# Define the scales to keep
# keep <- c("General Ability", "Crystallized Knowledge", "Fluid Reasoning")
# data_iq <- dplyr::filter(data_iq, scale %in% keep)
# Create the dotplot using the dotplot function from the NeurotypR package
NeurotypR::dotplot2(
data = data_iq,
x = x,
y = y,
colors = colors,
return_plot = return_plot,
filename = filename,
na.rm = TRUE
)
```
```{=typst}
// Define a function to create a domain with a title, a table, and a figure
#let domain(title: none, file_qtbl, file_fig) = {
let font = (font: "Roboto Slab", size: 0.7em)
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,
[#emph[_Premorbid Ability_] is an estimate of an individual's intellectual functioning prior to known or suspected onset of brain disease or dysfunction. Neurocognition is independent of intelligence and evaluates cognitive functioning across five domains\: Attention (focus, concentration, and information processing), Language (verbal communication, naming, comprehension, and fluency), Memory (immediate and delayed verbal and visual recall), Spatial (visuospatial perception, construction, and orientation), and Executive Functions (planning, problem-solving, and mental flexibility). #footnote[All scores in these figures have been standardized as z-scores. In this system: A z-score of 0.0 represents average performance; Each unit represents one standard deviation from the average; Scores between -1.0 and +1.0 fall within the normal range; Scores below -1.0 indicate below-average performance and warrant attention; and Scores at or below -2.0 indicate significantly impaired performance and are clinically concerning.]
],
),
placement: none,
kind: "image",
supplement: [*Figure*],
gap: 0.5em,
),
)
}
```
```{=typst}
// Define the title of the domain
#let title = "General Cognitive Ability"
// Define the file name of the table
#let file_qtbl = "table_iq.png"
// Define the file name of the figure
#let file_fig = "fig_iq_subdomain.svg"
// The title is appended with ' Index Scores'
#domain(title: [#title Scores], file_qtbl, file_fig)
```
<!-- ```{=typst}
// Define the title of the domain
#let title = "General Cognitive Ability"
// Define the file name of the table
#let file_qtbl = "table_iq.png"
// Define the file name of the figure
#let file_fig = "fig_iq_narrow.svg"
// The title is appended with ' Index Scores'
#domain(title: [#title Scores], file_qtbl, file_fig)
``` -->