-
Notifications
You must be signed in to change notification settings - Fork 0
/
_02-07_motor.qmd
executable file
·223 lines (196 loc) · 5.17 KB
/
_02-07_motor.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
## Motor {#sec-motor}
{{< include _02-07_motor_text.qmd >}}
```{r}
#| label: setup-motor
#| include: false
# domain
domains <- c("Motor")
# phenotype
pheno <- "motor"
```
```{r}
#| label: export-motor
#| include: false
# Read the CSV file into a data frame
motor <- vroom::vroom("neurocog.csv")
# Filter the data frame based on certain conditions
# Keep only the rows where 'domain' equals 'domains' and 'z_mean_domain' is not NA
motor <- motor |>
dplyr::filter(domain %in% domains)
# Select specific columns from the data frame
motor <- motor |>
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 'motor' data frame to a CSV file
# The file name is derived from the 'pheno' variable
readr::write_excel_csv(motor, paste0(pheno, ".csv"), na = "", col_names = TRUE, append = FALSE)
```
```{r}
#| label: data-motor
#| include: false
# read and filter data
data <- motor
scales <- c(
"Dominant Hand Time",
"Dominant Hand",
"Dominant vs. Nondominant",
"Fingertip Tapping Dominant Hand Repetitions",
"Fingertip Tapping Dominant Hand Sequences",
"Fingertip Tapping Dominant Hand",
"Fingertip Tapping Nondominant Hand Repetitions",
"Fingertip Tapping Nondominant Hand Sequences",
"Fingertip Tapping Nondominant Hand",
"Fingertip Tapping Repetitions",
"Fingertip Tapping Sequences",
"FT Dominant Hand vs. Nondominant Hand",
"Imitating Hand Positions",
"Imitating Hand Positions-Dominant",
"Imitating Hand Positions-Nondominant",
"Left-Hand Time",
"Non-Dominant Hand Time",
"Nondominant Hand",
"Nondominant Hand Time",
"Repetitions vs. Sequences",
"Right-Hand Time",
"Visuomotor Precision Errors",
"Visuomotor Precision Pencil Lifts",
"Visuomotor Precision Completion Time",
"Visuomotor Precision"
)
# 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_motor <- bwu::filter_data(data, domain = domains, scale = scales)
```
```{r}
#| label: text-motor
#| cache: true
#| include: false
# Generate the text for the motor domain
bwu::cat_neuropsych_results(data = data_motor, file = "_02-07_motor_text.qmd")
```
```{r}
#| label: qtbl-motor
#| dev: tikz
#| fig-process: pdf2png
#| include: false
# Set the default engine for tikz to "xetex"
options(tikzDefaultEngine = "xetex")
# table arguments
table_name <- "table_motor"
vertical_padding <- 0
multiline <- TRUE
# footnotes
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‰]")
# Groupings
grp_motor <- list(
t_score = c("Grooved Pegboard"),
scaled_score = c("NEPSY-2")
)
# make `gt` table
bwu::tbl_gt(
data = data_motor,
pheno = pheno,
table_name = table_name,
fn_t_score = fn_t_score,
fn_scaled_score = fn_scaled_score,
grp_t_score = grp_motor[["t_score"]],
grp_scaled_score = grp_motor[["scaled_score"]],
dynamic_grp = grp_motor,
vertical_padding = vertical_padding,
multiline = multiline
)
```
```{r}
#| label: fig-motor
#| include: false
#| eval: true
#| fig-cap: "Sensorimotor tasks refer to the capacity to control hand movements quickly, smoothly, and with adequate precision, which are required to engage in activities such as writing and drawing."
# dotplot args
x <- data_motor$z_mean_narrow
y <- data_motor$narrow
colors <- NULL
return_plot <- Sys.getenv("RETURN_PLOT")
filename <- "fig_motor.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_motor,
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, [
Sensorimotor tasks refer to the capacity to control hand movements
quickly, smoothly, and with adequate precision, which are required
to engage in activities such as writing and drawing.
]),
placement: none,
kind: "image",
supplement: [Figure],
gap: 0.5em,
),
)
}
```
```{=typst}
#let title = "Motor"
#let file_qtbl = "table_motor.png"
#let file_fig = "fig_motor.svg"
#domain(
title: [#title Scores],
file_qtbl,
file_fig
)
```