Package 'noasr'

Title: NOAS convenience functions
Description: Functions created to work well with LCBC's Nephew of All Spreadsheet data.
Authors: Athanasia Mo Mowinckel [aut, cre]
Maintainer: Athanasia Mo Mowinckel <[email protected]>
License: MIT + file LICENSE
Version: 0.0.2
Built: 2024-11-11 05:01:19 UTC
Source: https://github.com/LCBC-UiO/noasr

Help Index


Add intervals

Description

Since we have longitudinal data, intervals for subjects is a good way to get a better idea of the time scale of the data. These functions add extra columns to your data.

Usage

add_interval(data, name = interval)

add_interval_baseline(data, name = interval_baseline)

Arguments

data

data extracted from the NOAS

name

unquoted name to give the new column

Details

  • add_interval - add interval since last visit - default col: interval

  • add_interval_baaseline - add interval since first visit- default col: baseline

Value

data frame with one extra column

Examples

# attach built-in noas example data to test
dt <- noas_example

add_interval(dt)
add_interval_baseline(dt)

library(dplyr)
dt %>%
  add_interval() %>%
  add_interval_baseline()

# Change the default column names
dt %>%
  add_interval(name = intv) %>%
  add_interval_baseline(name = bsl_intv)

Add timepoint to data

Description

Calculated sequential timepoint for participants along the 'visit_age' column.

Usage

add_timepoint(data, name = timepoint)

Arguments

data

data extracted from the NOAS

name

unquoted name to give the new column

Value

data frame with extra column with timepoint

Examples

# attach built-in noas example data to test
dt <- noas_example

add_timepoint(dt)

library(dplyr)
dt %>%
 add_timepoint()

# Change the name of the variable
dt %>%
 add_timepoint(name = tp)

Coerce NOAS date into R date

Description

Dates from the NOAS always come in a specific format (yyyy-mm-dd). This function is for convenience in turning NOAS dates into R-dates easily.

Usage

as_date(dates)

Arguments

dates

character of dates (yyyy-mm-dd)

Value

vector of R dates

Examples

dates <- c("2016-03-01", "2002-12-31")
dates <- as.Date(dates, format="%Y-%m-%d")
dates
as.numeric(dates)

Utility function for reducing double/triple scans to a single row

Description

returns a MOAS data.frame with one row per participant and timepoint (i.e. removes double/triple scan entries). For analyses not intending to use the power of double/triple scans, or for data which will be widened and scanner type/site is not of interest. Only subject timepoints that have several entries (i.e. several scan sites), will be reduced. All timepoints will be retained.

Usage

filter_site(
  data,
  site_var = site_name,
  keep = "long",
  tie = "interval",
  site_order = c("ousPrisma", "ousSkyra", "ousAvanto"),
  verbose = TRUE
)

Arguments

data

data extracted from the NOAS

site_var

column name with the site information

keep

A string specifying which data from double/triple scans to keep.

tie

string indicating given a tie in the "long" keep option, what to keep.

site_order

string vector of the scanner priority given a tie between scanners

verbose

logical, TRUE sets it to verbose

Details

Available options for 'keep' are:

  • "long"keep data from scanner with most data (default)

  • "ousAvanto"keep 'ousAvanto'

  • "ousSkyra"keep 'ousSkyra'

  • "ousPrisma"'ousPrisma'

Available options for 'tie' are:

  • "interval"keep data from scanner with longest data interval (default)

  • "ousAvanto"keep 'ousAvanto'

  • "ousSkyra"keep 'ousSkyra'

  • "ousPrisma"'ousPrisma'

Value

A NOAS type file with one line per subject and timepoint.

Examples

# attach built-in noas example data to test
dt <- noas_example
filter_site(dt)
filter_site(dt, 'ousSkyra')
filter_site(dt, 'ousAvanto')

Create a data.frame that is ready for use in Freesufers linear mixed models

Description

fs_lmm Creates a data.frame of subsetted row and formatted columns ready for use in Freesurfers (6.0) linear mixed models. Design matrices are created for the grouping.var factors, and numeric variables are z-transformed.

Usage

fs_lmm(
  data,
  formula,
  site_var,
  folder_var,
  numeric_transform = "delete",
  ...,
  file = NULL,
  concat_list = NULL
)

Arguments

data

data extracted from the NOAS

formula

right-hand formula for your model. (ex. ~ visit_age * sex)

site_var

column name with the site information

folder_var

unqoted column name with folder-information of MRI data from the 'mri_info' table.

numeric_transform

Action to take on numeric_transform data that are numeric

...

other arguments to utils{model.matrix}

file

Optional string specifying file name to be saved

concat_list

character vector of fsid's that you want the data matched to. Used if the data is already concatenated and you wish to add more variables to your models.

Details

Available options for 'numeric_transform' are:

  • "delete"delete observations with any numeric_transform numeric.vars

  • "mean_na"replace numeric_transform with mean for that participant

  • "mean_all"replace all values with the mean for that participant

  • "first"replace all values with the first observation for that participant

Value

a data frame ready for Freesurfer LMM use.

Examples

# attach built-in noas example data to test
dt <- noas_example

fs_lmm(dt, ~ visit_age * sex * cog,
       site_var = site_name,
       folder_var = mri_info_folder
     )

 # replace NA values in numeric with
 # mean values for the participant
 fs_lmm(dt, ~ visit_age * sex * cog,
       numeric_transform = "mean_na",
       site_var = site_name,
       folder_var = mri_info_folder
     )

 # replace all numeric values with
 # mean values for the participant
 fs_lmm(dt, ~ visit_age * sex * cog,
       numeric_transform = "mean_na",
       site_var = site_name,
       folder_var = mri_info_folder
     )

 # replace all numeric values with
 # first for the participant
 fs_lmm(dt, ~ visit_age * cog,
       site_var = site_name,
       folder_var = mri_info_folder
     )

 # Provide a vector of fsid to reduce the data to
 # pre-existing concatenated imaging data.
 fs_lmm(noas_example, ~ visit_age,
        site_var = site_name,
        folder_var = mri_info_folder,
        concat_list = c("1000000_1", "1000000_3", "1000000_5")
        )

Function to extract lcbc colors as hex codes

Description

Function to extract lcbc colors as hex codes

Usage

lcbc_cols(...)

Arguments

...

Character names of lcbc_colors


Return function to interpolate a lcbc color palette

Description

Return function to interpolate a lcbc color palette

Usage

lcbc_pal(palette = "main", reverse = FALSE, ...)

Arguments

palette

Character name of palette in lcbc_palettes

reverse

Boolean indicating whether the palette should be reversed

...

Additional arguments to pass to colorRampPalette()


Calculate the mean between two dates

Description

Calculate the mean between two dates

Usage

mean_date(date1, date2)

Arguments

date1

first date

date2

second date

Value

mean difference between two dates

Examples

dates <- as.Date(c("2020-01-20", "1998-01-20"))
mean_date(dates[1], dates[2])

Example NOAS data

Description

A dataset containing mock data mimicking core features like the NOAS data. For testing and examples in the package.

Usage

noas_example

Format

A data frame with 10 rows and 8 variables:

subject_id

subject identifier

project_id

project identifier

wave_code

assessment wave for the project

site_name

mri site identifier

mri_info_folder

mri folder on TSD

visit_age

subject age at visit

cog

cognitive score

sex

subject sex


Function to extract project colors as hex codes

Description

Function to extract project colors as hex codes

Usage

project_cols(...)

Arguments

...

Character names of project_colors


Return function to interpolate a project color palette

Description

Return function to interpolate a project color palette

Usage

project_pal(palette = "main", reverse = FALSE, ...)

Arguments

palette

Character name of palette in project_palettes, or a vector of colour names (NDev, MemP, NCP, MoBa, Loci, MemC, ACon, S2C)

reverse

Boolean indicating whether the palette should be reversed

...

Additional arguments to pass to colorRampPalette()


Colour scale constructor for lcbc colours

Description

Colour scale constructor for lcbc colours

Usage

scale_colour_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...)

scale_color_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...)

Arguments

palette

Character name of palette in lcbc_palettes

discrete

Boolean indicating whether colour aesthetic is discrete or not

reverse

Boolean indicating whether the palette should be reversed

...

Additional arguments passed to ggplot2{discrete_scale()} or ggplot2{scale_colour_gradientn()}, used respectively when discrete is TRUE or FALSE


Colour scale constructor for proj colours

Description

Colour scale constructor for proj colours

Usage

scale_colour_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...)

scale_color_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...)

Arguments

palette

Character name of palette in project_palettes

discrete

Boolean indicating whether colour aesthetic is discrete or not

reverse

Boolean indicating whether the palette should be reversed

...

Additional arguments passed to ggplot2{discrete_scale()} or ggplot2{scale_colour_gradientn()}, used respectively when discrete is TRUE or FALSE


Fill scale constructor for lcbc colours

Description

Fill scale constructor for lcbc colours

Usage

scale_fill_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...)

Arguments

palette

Character name of palette in lcbc_palettes

discrete

Boolean indicating whether colour aesthetic is discrete or not

reverse

Boolean indicating whether the palette should be reversed

...

Additional arguments passed to ggplot2{discrete_scale()} or ggplot2{scale_colour_gradientn()}, used respectively when discrete is TRUE or FALSE


Fill scale constructor for proj colours

Description

Fill scale constructor for proj colours

Usage

scale_fill_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...)

Arguments

palette

Character name of palette in project_palettes

discrete

Boolean indicating whether colour aesthetic is discrete or not

reverse

Boolean indicating whether the palette should be reversed

...

Additional arguments passed to ggplot2{discrete_scale()} or ggplot2{scale_colour_gradientn()}, used respectively when discrete is TRUE or FALSE


ggplot minimal theme for lcbc

Description

ggplot minimal theme for lcbc

Usage

theme_lcbc(base_size = base_size_text)

Arguments

base_size

text size


ggplot minimal theme for lcbc

Description

ggplot minimal theme for lcbc

Usage

theme_lcbc_dark(base_size = base_size_text)

Arguments

base_size

text size


ggplot dark theme for lcbc

Description

ggplot dark theme for lcbc

Usage

theme_lcbc_dark_grid(base_size = base_size_text)

Arguments

base_size

text size


ggplot minimal theme for lcbc

Description

ggplot minimal theme for lcbc

Usage

theme_lcbc_dark_void(base_size = base_size_text)

Arguments

base_size

text size


ggplot theme for lcbc

Description

ggplot theme for lcbc

Usage

theme_lcbc_grid(base_size = base_size_text)

Arguments

base_size

text size


ggplot minimal theme for lcbc

Description

ggplot minimal theme for lcbc

Usage

theme_lcbc_void(base_size = base_size_text)

Arguments

base_size

text size