WISC-5

Load libraries

knitr::opts_chunk$set(
  root.dir = normalizePath("./"),
  echo = TRUE,
  message = TRUE,
  warning = FALSE,
  error = TRUE
)
library(dplyr)
library(hablar)
library(here)
library(knitr)
library(magrittr)
library(purrr)
library(readr)
library(rJava)
library(rmarkdown)
library(rmdformats)
library(shiny)
library(snakecase)
library(tabulapdf)
library(tibble)
library(tidyr)
library(tidyverse)
library(bwu)

Patient

patient <- params$patient

Test

test <- params$test
test_name <- params$test_name

File upload/attach PDF

# file <- file.path(file.choose())
# saveRDS(file, "wisc5.rds")
# input_file_path <- readRDS("wisc5.rds")
file <- file.path(params$file)

Pages

pages <- params$pages

Extract tables with tabulapdf

UseThis - updated July 2024

# This works well so far
plucked_tables_wisc5 <- tabulapdf::extract_tables(
  file = file,
  pages = pages,
  output = "matrix",
  method = "stream",
  guess = TRUE
)

# Save the entire list to an R data file
save(plucked_tables_wisc5, file = "plucked_tables_wisc5.RData")

# Load the entire list from an R data file
load("plucked_tables_wisc5.RData")

Function process_wisc_tables

library(dplyr)
library(purrr)

process_wisc_tables <- function(wisc5_data) {
  table_list <- purrr::map(wisc5_data, as_tibble) %>%
    set_names(paste0("table", 1:length(wisc5_data))) # Rename tables

  list2env(table_list, .GlobalEnv) # Assign to global environment
}

# Example Usage:
process_wisc_tables(plucked_tables_wisc5)

# Loop over the list and write each matrix to a CSV file
for (i in seq_along(plucked_tables_wisc5)) {
  write.csv(plucked_tables_wisc5[[i]], file = paste0(test, "_", i, ".csv"), row.names = FALSE)
}

# # Save the entire list to an R data file
# save(plucked_tables_wisc5, file = "plucked_tables_wisc5.RData")
# 
# # Load the entire list from an R data file
# load("plucked_tables_wisc5.RData")

Table 1

Change scale names

names(table1) <- params$colnames1

# names(table1) <- c("domain", "scale", "abbrev", "raw_score", "score", "percentile", "age_equiv", "sem")

table1 <- table1[3:18, 2:8]

table1[1, 1] <- c("Similarities")
table1[2, 1] <- c("Vocabulary")
table1[3, 1] <- c("Information")
table1[4, 1] <- c("Comprehension")
table1[5, 1] <- c("Block Design")
table1[6, 1] <- c("Visual Puzzles")
table1[7, 1] <- c("Matrix Reasoning")
table1[8, 1] <- c("Figure Weights")
table1[9, 1] <- c("Picture Concepts")
table1[10, 1] <- c("Arithmetic")
table1[11, 1] <- c("Digit Span")
table1[12, 1] <- c("Picture Span")
table1[13, 1] <- c("Letter-Number Sequencing")
table1[14, 1] <- c("Coding")
table1[15, 1] <- c("Symbol Search")
table1[16, 1] <- c("Cancellation")

table1 <- table1 |> dplyr::select(all_of(params$keep1))

Extract rows with data

library(dplyr)

# Function to replace "-" with NA and filter out rows with no real data
filter_real_data <- function(table, key_columns) {
  table <- table %>%
    mutate(across(all_of(key_columns), ~ if_else(. == "-", NA_character_, as.character(.)))) %>%
    mutate(across(all_of(key_columns), as.numeric)) %>%
    filter(rowSums(is.na(select(., all_of(key_columns)))) < length(key_columns))

  return(table)
}

# Assuming key_columns are those columns which must have data
key_columns <- c("raw_score", "score", "percentile")

# Extract and filter table1
table1_all_rows <- as_tibble(table1) # Ensure table1 is a tibble
table1 <- filter_real_data(table1_all_rows, key_columns)

# Print the filtered table
print(table1)

Mutate columns

table1 <- bwu::gpluck_make_columns(
  table1,
  test = params$test,
  test_name = params$test_name,
  ci_95 = "",
  range = "",
  domain = "",
  subdomain = "",
  narrow = "",
  pass = "Sequential",
  verbal = "Verbal",
  timed = "Untimed",
  test_type = "npsych_test",
  score_type = "scaled_score",
  description = "",
  result = ""
)

# Test score ranges
table1 <- bwu::gpluck_make_score_ranges(
  table = table1,
  test_type = "npsych_test"
)

Domains/Subdomains

# Domain
table1 <-
  table1 |>
  dplyr::mutate(
    domain = dplyr::case_when(
      scale == "Similarities" ~ "Verbal/Language",
      scale == "Vocabulary" ~ "Verbal/Language",
      scale == "Information" ~ "Verbal/Language",
      scale == "Comprehension" ~ "Verbal/Language",
      scale == "Block Design" ~ "Visual Perception/Construction",
      scale == "Visual Puzzles" ~ "Visual Perception/Construction",
      scale == "Matrix Reasoning" ~ "Visual Perception/Construction",
      scale == "Figure Weights" ~ "Visual Perception/Construction",
      scale == "Picture Concepts" ~ "Visual Perception/Construction",
      scale == "Arithmetic" ~ "Attention/Executive",
      scale == "Digit Span" ~ "Attention/Executive",
      scale == "Picture Span" ~ "Attention/Executive",
      scale == "Letter-Number Sequencing" ~ "Attention/Executive",
      scale == "Coding" ~ "Attention/Executive",
      scale == "Symbol Search" ~ "Attention/Executive",
      scale == "Cancellation" ~ "Attention/Executive",
      TRUE ~ as.character(domain)
    )
  )

# Subdomain
table1 <-
  table1 |>
  dplyr::mutate(
    subdomain = dplyr::case_when(
      scale == "Similarities" ~ "Reasoning",
      scale == "Vocabulary" ~ "Knowledge",
      scale == "Information" ~ "Knowledge",
      scale == "Comprehension" ~ "Reasoning",
      scale == "Block Design" ~ "Construction",
      scale == "Visual Puzzles" ~ "Visualization",
      scale == "Matrix Reasoning" ~ "Reasoning",
      scale == "Figure Weights" ~ "Reasoning",
      scale == "Picture Concepts" ~ "Reasoning",
      scale == "Arithmetic" ~ "Working Memory",
      scale == "Digit Span" ~ "Working Memory",
      scale == "Picture Span" ~ "Working Memory",
      scale == "Letter-Number Sequencing" ~ "Working Memory",
      scale == "Coding" ~ "Processing Speed",
      scale == "Symbol Search" ~ "Processing Speed",
      scale == "Cancellation" ~ "Attention",
      TRUE ~ as.character(subdomain)
    )
  )

# Narrow
table1 <-
  table1 |>
  dplyr::mutate(
    narrow = dplyr::case_when(
      scale == "Similarities" ~ "Word Reasoning",
      scale == "Vocabulary" ~ "Word Knowledge",
      scale == "Information" ~ "General World Knowledge",
      scale == "Comprehension" ~ "Acquired Knowledge",
      scale == "Block Design" ~ "Block Construction",
      scale == "Visual Puzzles" ~ "Visualization",
      scale == "Matrix Reasoning" ~ "Nonverbal Reasoning",
      scale == "Figure Weights" ~ "Quantitiative Reasoning",
      scale == "Picture Concepts" ~ "Nonverbal Reasoning",
      scale == "Arithmetic" ~ "Verbal Working Memory",
      scale == "Digit Span" ~ "Verbal Working Memory",
      scale == "Picture Span" ~ "Nonverbal Working Memory",
      scale == "Letter-Number Sequencing" ~ "Verbal Working Memory",
      scale == "Coding" ~ "Cognitive Efficiency",
      scale == "Symbol Search" ~ "Perceptual Speed",
      scale == "Cancellation" ~ "Attentional Fluency",
      TRUE ~ as.character(narrow)
    )
  )

# PASS Model
table1 <-
  table1 |>
  dplyr::mutate(
    pass = dplyr::case_when(
      scale == "Block Design" ~ "Simultaneous",
      scale == "Visual Puzzles" ~ "Simultaneous",
      scale == "Matrix Reasoning" ~ "Simultaneous",
      scale == "Figure Weights" ~ "Simultaneous",
      scale == "Picture Concepts" ~ "Simultaneous",
      scale == "Arithmetic" ~ "Attention",
      scale == "Digit Span" ~ "Attention",
      scale == "Picture Span" ~ "Attention",
      scale == "Letter-Number Sequencing" ~ "Attention",
      scale == "Cancellation" ~ "Attention",
      scale == "Coding" ~ "Planning",
      scale == "Symbol Search" ~ "Planning",
      TRUE ~ as.character(pass)
    )
  )

## Verbal vs Nonverbal
table1 <-
  table1 |>
  dplyr::mutate(
    verbal = dplyr::case_when(
      scale == "Block Design" ~ "Nonverbal",
      scale == "Visual Puzzles" ~ "Nonverbal",
      scale == "Matrix Reasoning" ~ "Nonverbal",
      scale == "Figure Weights" ~ "Nonverbal",
      scale == "Picture Concepts" ~ "Nonverbal",
      scale == "Arithmetic" ~ "Verbal",
      scale == "Digit Span" ~ "Verbal",
      scale == "Picture Span" ~ "Nonverbal",
      scale == "Letter-Number Sequencing" ~ "Verbal",
      scale == "Cancellation" ~ "Nonverbal",
      scale == "Coding" ~ "Nonverbal",
      scale == "Symbol Search" ~ "Nonverbal",
      TRUE ~ as.character(verbal)
    )
  )

## Timed vs Untimed
table1 <-
  table1 |>
  dplyr::mutate(
    timed = dplyr::case_when(
      scale == "Block Design" ~ "Timed",
      scale == "Visual Puzzles" ~ "Timed",
      scale == "Matrix Reasoning" ~ "Untimed",
      scale == "Figure Weights" ~ "Timed",
      scale == "Picture Concepts" ~ "Untimed",
      scale == "Arithmetic" ~ "Timed",
      scale == "Digit Span" ~ "Untimed",
      scale == "Picture Span" ~ "Untimed",
      scale == "Letter-Number Sequencing" ~ "Untimed",
      scale == "Cancellation" ~ "Timed",
      scale == "Coding" ~ "Timed",
      scale == "Symbol Search" ~ "Timed",
      TRUE ~ as.character(timed)
    )
  )

Scale descriptions

table1 <-
  table1 |>
  dplyr::mutate(
    description = dplyr::case_when(
      scale ==
        "Similarities" ~ "Verbal inductive reasoning",
      scale ==
        "Vocabulary" ~ "Word/lexical knowledge",
      scale ==
        "Information" ~ "Acquired knowledge/ability to acquire, retain, and retrieve general factual knowledge",
      scale ==
        "Comprehension" ~ "Practical knowledge and judgment of general principles and social situations",
      scale ==
        "Block Design" ~ "Understanding visual-spatial relationships to construct geometric designs from a model",
      scale ==
        "Visual Puzzles" ~ "Generate visual images in the mind's eye",
      scale == "Matrix Reasoning" ~ "Inductive reasoning and nonverbal problem-solving",
      scale == "Figure Weights" ~ "General sequential (deductive) reasoning and quantitative reasoning",
      scale == "Picture Concepts" ~ "Reasoning and semantic matching",
      scale == "Arithmetic" ~ "Solving math word problems in working memory",
      scale == "Digit Span" ~ "Registering, maintaining, and manipulating auditory information",
      scale == "Picture Span" ~ "Maintenance and resequencing of progressively lengthier sets of pictures in spatial working memory",
      scale == "Letter-Number Sequencing" ~ "Maintenance and resequencing of progressively lengthier number and letter strings in working memory",
      scale == "Coding" ~ "Efficiency of psychomotor speed, visual scanning ability, and visual-motor coordination",
      scale == "Symbol Search" ~ "Visual-perceptual decision-making speed",
      scale == "Cancellation" ~ "Selective visual attention, visual discrimination, and visual-perceptual processing",
      TRUE ~ as.character(description)
    )
  )

Glue results

table1 <-
  table1 %>%
  dplyr::mutate(
    result = glue::glue(
      "{description} was {range}.\n"
    )
  )

## Relocate variables
table1 <- table1 |> dplyr::relocate(c(raw_score, score, ci_95, percentile, range), .after = scale)

Table 2

Change scale names

names(table2) <- params$colnames2
# names(table2) <- c("scale", "raw_score", "score", "percentile", "ci_95")

table2 <- table2[4:9, ]

table2[1, 1] <- c("Verbal Comprehension (VCI)")
table2[2, 1] <- c("Visual Spatial (VSI)")
table2[3, 1] <- c("Fluid Reasoning (FRI)")
table2[4, 1] <- c("Working Memory (WMI)")
table2[5, 1] <- c("Processing Speed (PSI)")
table2[6, 1] <- c("Full Scale IQ (FSIQ)")

table2 <- table2 |> dplyr::select(all_of(params$keep2))

Extract rows with data

library(dplyr)

# Function to replace "-" with NA and filter out rows with no real data
filter_real_data <- function(table, key_columns) {
  table <- table %>%
    mutate(across(all_of(key_columns), ~ if_else(. == "-", NA_character_, as.character(.)))) %>%
    mutate(across(all_of(key_columns), as.numeric)) %>%
    filter(rowSums(is.na(select(., all_of(key_columns)))) < length(key_columns))

  return(table)
}

# Assuming key_columns are those columns which must have data
key_columns <- c("raw_score", "score", "percentile")

# Extract and filter table2
table2_all_rows <- as_tibble(table2)
table2 <- filter_real_data(table2_all_rows, key_columns)

# Print the filtered table
print(table2)

Mutate columns

table2 <- bwu::gpluck_make_columns(
  table2,
  test = params$test,
  test_name = params$test_name,
  ci_95 = "",
  range = "",
  domain = "General Cognitive Ability",
  subdomain = "",
  narrow = "",
  pass = "Sequential",
  verbal = "Verbal",
  timed = "Untimed",
  test_type = "npsych_test",
  score_type = "standard_score",
  description = "",
  result = ""
)

# Test score ranges
table2 <- bwu::gpluck_make_score_ranges(
  table = table2,
  test_type = "npsych_test"
)

Domains/Subdomains

# Subdomain
table2 <-
  table2 |>
  dplyr::mutate(
    subdomain = dplyr::case_when(
      scale == "Verbal Comprehension (VCI)" ~ "Crystallized Knowledge",
      scale == "Visual Spatial (VSI)" ~ "Visuospatial Processing",
      scale == "Fluid Reasoning (FRI)" ~ "Fluid Reasoning",
      scale == "Working Memory (WMI)" ~ "Working Memory",
      scale == "Processing Speed (PSI)" ~ "Processing Speed",
      scale == "Full Scale IQ (FSIQ)" ~ "General Intelligence",
      TRUE ~ as.character(subdomain)
    )
  )

# Narrow
table2 <-
  table2 |>
  dplyr::mutate(
    narrow = dplyr::case_when(
      scale == "Verbal Comprehension (VCI)" ~ "Crystallized Knowledge",
      scale == "Visual Spatial (VSI)" ~ "Visuospatial Processing",
      scale == "Fluid Reasoning (FRI)" ~ "Fluid Reasoning",
      scale == "Working Memory (WMI)" ~ "Working Memory",
      scale == "Processing Speed (PSI)" ~ "Processing Speed",
      scale == "Full Scale IQ (FSIQ)" ~ "General Intelligence",
      TRUE ~ as.character(narrow)
    )
  )

## Verbal vs Nonverbal

table2 <-
  table2 |>
  dplyr::mutate(
    verbal = dplyr::case_when(
      scale == "Verbal Comprehension (VCI)" ~ "Verbal",
      scale == "Visual Spatial (VSI)" ~ "Nonverbal",
      scale == "Fluid Reasoning (FRI)" ~ "Nonverbal", # unless arithmetic too
      scale == "Working Memory (WMI)" ~ "",
      scale == "Processing Speed (PSI)" ~ "Nonverbal",
      scale == "Full Scale IQ (FSIQ)" ~ "",
      TRUE ~ as.character(verbal)
    )
  )

## Timed vs Untimed
table2 <-
  table2 |>
  dplyr::mutate(
    timed = dplyr::case_when(
      scale == "Verbal Comprehension (VCI)" ~ "Untimed",
      scale == "Visual Spatial (VSI)" ~ "Timed",
      scale == "Fluid Reasoning (FRI)" ~ "",
      scale == "Working Memory (WMI)" ~ "Untimed",
      scale == "Processing Speed (PSI)" ~ "Timed",
      scale == "Full Scale IQ (FSIQ)" ~ "",
      TRUE ~ as.character(timed)
    )
  )

Descriptions

table2 <-
  table2 |>
  dplyr::mutate(
    description = dplyr::case_when(
      scale == "Verbal Comprehension (VCI)" ~ "Verbal Comprehension (i.e., the ability to verbalize meaningful concepts, think about verbal information, and express oneself using words)",
      scale == "Visual Spatial (VSI)" ~ "Visual Spaital is not an independent factor",
      scale == "Fluid Reasoning (FRI)" ~ "Fluid Reasoning (i.e., the ability to use reasoning to identify and apply solutions to problems)",
      scale == "Working Memory (WMI)" ~ "Working Memory (*G*wm)",
      scale == "Processing Speed (PSI)" ~ "Processing Speed (*G*s)",
      scale == "Full Scale IQ (FSIQ)" ~ "General Intelligence (*g*)",
      scale == "General Ability (GAI)" ~ "A subset of intellectual functioning with reduced influences of working memory and processing speed",
      TRUE ~ as.character(description)
    )
  )

Glue result

table2 <-
  table2 |>
  dplyr::mutate(
    result = dplyr::case_when(
      scale == "Verbal Comprehension (VCI)" ~ glue::glue(
        "{description} was classified as {range} and ranked at the {percentile}th percentile.\n"
      ),
      scale == "Visual Spatial (VSI" ~ glue::glue(
          "{description} was classified as {range} and ranked at the {percentile}th percentile.\n"
        ),
      scale == "Fluid Reasoning (FRI)" ~ glue::glue(
          "{description} was classified as {range} and ranked at the {percentile}th percentile.\n"
        ),
      scale == "Working Memory (WMI)" ~ glue::glue(
          "{description} fell in the {range} range.\n"
        ),
      scale == "Processing Speed (PSI)" ~ glue::glue(
          "{description} was {range}.\n"
        ),
      scale == "Full Scale IQ (FSIQ)" ~ glue::glue(
        "{description} was {range} overall.\n"
      ),
      scale == "General Ability (GAI)" ~ glue::glue(
        "{description} was {range} and ranked at the {percentile}th percentile, indicating performance as good as or better than {percentile}% of same-age peers from the general population.\n"
      ),
      TRUE ~ as.character(result)
    )
  )

## Relocate variables
table2 <- table2 |> dplyr::relocate(c(raw_score, score, ci_95, percentile, range), .after = scale)

Table 3

Change scale names

names(table3) <- params$colnames2
# names(table3) <- c("scale", "abbrev", "raw_score", "score", "percentile", "ci_95", "category", "sem")

table3 <- table3[c(6, 8:13), ]

table3[1, 1] <- c("Verbal (Expanded Crystallized) (VECI)")
table3[2, 1] <- c("Expanded Fluid (EFI)")
table3[3, 1] <- c("Quantitative Reasoning (QRI)")
table3[4, 1] <- c("Auditory Working Memory (AWMI)")
table3[5, 1] <- c("Nonverbal (NVI)")
table3[6, 1] <- c("General Ability (GAI)")
table3[7, 1] <- c("Cognitive Proficiency (CPI)")
# table3[1, 1] <- c("Naming Speed (NSI)")
# table3[2, 1] <- c("Symbol Translation (STI)")
# table3[3, 1] <- c("Storage & Retrieval (SRI)")

table3 <- table3 |> dplyr::select(all_of(params$keep2))

Extract rows with data

library(dplyr)

# Function to replace "-" with NA and filter out rows with no real data
filter_real_data <- function(table, key_columns) {
  table <- table %>%
    mutate(across(all_of(key_columns), ~ if_else(. == "-", NA_character_, as.character(.)))) %>%
    mutate(across(all_of(key_columns), as.numeric)) %>%
    filter(rowSums(is.na(select(., all_of(key_columns)))) < length(key_columns))

  return(table)
}

# Assuming key_columns are those columns which must have data
key_columns <- c("raw_score", "score", "percentile")

# Extract and filter table3
table3_all_rows <- as_tibble(table3)
table3 <- filter_real_data(table3_all_rows, key_columns)

# Print the filtered table
print(table3)

Mutate columns

table3 <- bwu::gpluck_make_columns(
  table3,
  test = params$test,
  test_name = params$test_name,
  ci_95 = "",
  range = "",
  domain = "General Cognitive Ability",
  subdomain = "",
  narrow = "",
  pass = "Sequential",
  verbal = "Verbal",
  timed = "Untimed",
  test_type = "npsych_test",
  score_type = "scaled_score",
  description = "",
  result = ""
)

# Test score ranges
table3 <- bwu::gpluck_make_score_ranges(
  table = table3,
  test_type = "npsych_test"
)

Domains/Subdomains

table3 <-
  table3 |>
  mutate(
    domain = case_when(
      ## Ancillary
      scale == "Verbal (Expanded Crystallized) (VECI)" ~ "General Cognitive Ability",
      scale == "Expanded Fluid (EFI)" ~ "General Cognitive Ability",
      scale == "Quantitative Reasoning (QRI)" ~ "General Cognitive Ability",
      scale == "Auditory Working Memory (AWMI)" ~ "Attention/Executive",
      scale == "Nonverbal (NVI)" ~ "General Cognitive Ability",
      scale == "General Ability (GAI)" ~ "General Cognitive Ability",
      scale == "Cognitive Proficiency (CPI)" ~ "General Cognitive Ability",
      ## Complementary
      scale == "Naming Speed (NSI)" ~ "Verbal/Language",
      scale == "Symbol Translation (STI)" ~ "Memory",
      scale == "Storage & Retrieval (SRI)" ~ "Memory",
      TRUE ~ as.character(domain)
    )
  )

# Subdomain
table3 <-
  table3 |>
  mutate(
    subdomain = case_when(
      scale == "Auditory Working Memory (AWMI)" ~ "Working Memory",
      scale == "Cognitive Proficiency (CPI)" ~ "Executive Functioning",
      scale == "Expanded Fluid (EFI)" ~ "Fluid Intelligence",
      scale == "General Ability (GAI)" ~ "General Intelligence",
      scale == "Nonverbal (NVI)" ~ "Fluid Intelligence",
      scale == "Quantitative Reasoning (QRI)" ~ "Fluid Intelligence",
      scale == "Verbal (Expanded Crystallized) (VECI)" ~ "Crystallized Intelligence",
      scale == "Naming Speed (NSI)" ~ "Retrieval Fluency",
      scale == "Symbol Translation (STI)" ~ "Learning Efficiency",
      scale == "Storage & Retrieval (SRI)" ~ "Long-Term Storage and Retrieval",
      TRUE ~ as.character(subdomain)
    )
  )

# Narrow
table3 <-
  table3 |>
  mutate(
    narrow = case_when(
      scale == "Auditory Working Memory (AWMI)" ~ "Verbal Working Memory",
      scale == "Cognitive Proficiency (CPI)" ~ "Cognitive Efficiency",
      scale == "Expanded Fluid (EFI)" ~ "Fluid Intelligence",
      scale == "General Ability (GAI)" ~ "General Intelligence",
      scale == "Nonverbal (NVI)" ~ "Fluid Intelligence",
      scale == "Quantitative Reasoning (QRI)" ~ "Quantitative Reasoning",
      scale == "Verbal (Expanded Crystallized) (VECI)" ~ "Crystallized Intelligence",
      scale == "Naming Speed (NSI)" ~ "Naming Facility",
      scale == "Storage & Retrieval (SRI)" ~ "Retrieval Fluency",
      scale == "Symbol Translation (STI)" ~ "Learning Efficiency",
      TRUE ~ as.character(narrow)
    )
  )

# PASS Model
table3 <-
  table3 |>
  mutate(
    pass = case_when(
      scale == "General Ability (GAI)" ~ "",
      scale == "Cognitive Proficiency (CPI)" ~ "",
      scale == "Nonverbal (NVI)" ~ "Simultaneous",
      scale == "Auditory Working Memory (AWMI)" ~ "Sequential",
      scale == "Expanded Fluid (EFI)" ~ "Simultaneous",
      scale == "Quantitative Reasoning (QRI)" ~ "Simultaneous",
      scale == "Verbal (Expanded Crystallized) (VECI)" ~ "Sequential",
      scale == "Naming Speed (NSI)" ~ "Attention",
      scale == "Storage & Retrieval (SRI)" ~ "Simultaneous",
      scale == "Symbol Translation (STI)" ~ "Simultaneous",
      TRUE ~ as.character(pass)
    )
  )

## Verbal vs Nonverbal
table3 <-
  table3 |>
  mutate(
    verbal = case_when(
      scale == "Auditory Working Memory (AWMI)" ~ "Verbal",
      scale == "Cognitive Proficiency (CPI)" ~ "",
      scale == "Expanded Fluid (EFI)" ~ "Nonverbal",
      scale == "General Ability (GAI)" ~ "",
      scale == "Nonverbal (NVI)" ~ "Nonverbal",
      scale == "Quantitative Reasoning (QRI)" ~ "",
      scale == "Verbal (Expanded Crystallized) (VECI)" ~ "Verbal",
      scale == "Naming Speed (NSI)" ~ "Verbal",
      scale == "Storage & Retrieval (SRI)" ~ "Verbal",
      scale == "Symbol Translation (STI)" ~ "Nonverbal",
      TRUE ~ as.character(verbal)
    )
  )

## Timed vs Untimed
table3 <-
  table3 |>
  mutate(
    timed = case_when(
      scale == "Auditory Working Memory (AWMI)" ~ "Untimed",
      scale == "Cognitive Proficiency (CPI)" ~ "Timed",
      scale == "Expanded Fluid (EFI)" ~ "Untimed",
      scale == "General Ability (GAI)" ~ "Untimed",
      scale == "Nonverbal (NVI)" ~ "Timed",
      scale == "Quantitative Reasoning (QRI)" ~ "Timed",
      scale == "Verbal (Expanded Crystallized) (VECI)" ~ "Untimed",
      scale == "Naming Speed (NSI)" ~ "Timed",
      scale == "Storage & Retrieval (SRI)" ~ "Timed",
      scale == "Symbol Translation (STI)" ~ "Untimed",
      TRUE ~ as.character(timed)
    )
  )

Scale descriptions

table3 <-
  table3 |>
  mutate(
    description = case_when(
      ## Ancillary
      scale == "Verbal (Expanded Crystallized) (VECI)" ~ "verbal concept formation, verbal reasoning, verbal comprehension and expression, acquired knowledge, and practical knowledge and judgment (expanded)",
      scale == "Expanded Fluid (EFI)" ~ "ability to use reasoning to identify and apply solutions to problems (expanded)",
      scale == "Quantitative Reasoning (QRI)" ~ "quantitative reasoning skills",
      scale == "Auditory Working Memory (AWMI)" ~ "auditory working memory processes supported by the phonological loop; ability to register, maintain, and manipulate verbally-presented information",
      scale == "Nonverbal (NVI)" ~ "general intellectual functioning that minimizes expressive language demands",
      scale == "General Ability (GAI)" ~ "a subset of intellectual functioning with reduced influences of working memory and processing speed",
      scale == "Cognitive Proficiency (CPI)" ~ "index of cognitive processing proficiency that reduces crystallzied knowledge, verbal reaoning, and fluid reasoning demands",
      ## Complementary
      scale == "Naming Speed (NSI)" ~ "automaticity of naming",
      scale == "Symbol Translation (STI)" ~ "visual-verbal associative memory",
      scale == "Storage & Retrieval (SRI)" ~ "ability to accurately and efficiently store and retrieve auditory and visual information fromlong-term memory",
      TRUE ~ as.character(description)
    )
  )

Glue results

table3 <-
  table3 %>%
  dplyr::mutate(
    result = glue::glue(
      "{description} was {range}.\n"
    )
  )

## Relocate variables
table3 <- table3 |> dplyr::relocate(c(raw_score, score, ci_95, percentile, range), .after = scale)

Combine tables

wisc5 <- collapse::rowbind(table2, table3, table1, fill = TRUE)
# wisc5 <- rbind(table2, table3, table1)
# wisc5 <- rbind(table2, table3, table1, table4, table5)

Write out final csv

readr::write_csv(wisc5, here::here("data", "csv", "wisc5.csv"))


jtrampush/npsych.data documentation built on Feb. 25, 2025, 12:30 a.m.