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 |
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.
add_interval(data, name = interval) add_interval_baseline(data, name = interval_baseline)
add_interval(data, name = interval) add_interval_baseline(data, name = interval_baseline)
data |
data extracted from the NOAS |
name |
unquoted name to give the new column |
add_interval - add interval since last visit - default col: interval
add_interval_baaseline - add interval since first visit- default col: baseline
data frame with one extra column
# 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)
# 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)
Calculated sequential timepoint for participants along the 'visit_age' column.
add_timepoint(data, name = timepoint)
add_timepoint(data, name = timepoint)
data |
data extracted from the NOAS |
name |
unquoted name to give the new column |
data frame with extra column with timepoint
# 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)
# 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)
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.
as_date(dates)
as_date(dates)
dates |
character of dates (yyyy-mm-dd) |
vector of R dates
dates <- c("2016-03-01", "2002-12-31") dates <- as.Date(dates, format="%Y-%m-%d") dates as.numeric(dates)
dates <- c("2016-03-01", "2002-12-31") dates <- as.Date(dates, format="%Y-%m-%d") dates as.numeric(dates)
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.
filter_site( data, site_var = site_name, keep = "long", tie = "interval", site_order = c("ousPrisma", "ousSkyra", "ousAvanto"), verbose = TRUE )
filter_site( data, site_var = site_name, keep = "long", tie = "interval", site_order = c("ousPrisma", "ousSkyra", "ousAvanto"), verbose = TRUE )
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 |
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'
A NOAS type file with one line per subject and timepoint.
# attach built-in noas example data to test dt <- noas_example filter_site(dt) filter_site(dt, 'ousSkyra') filter_site(dt, 'ousAvanto')
# attach built-in noas example data to test dt <- noas_example filter_site(dt) filter_site(dt, 'ousSkyra') filter_site(dt, 'ousAvanto')
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.
fs_lmm( data, formula, site_var, folder_var, numeric_transform = "delete", ..., file = NULL, concat_list = NULL )
fs_lmm( data, formula, site_var, folder_var, numeric_transform = "delete", ..., file = NULL, concat_list = NULL )
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 |
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. |
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
a data frame ready for Freesurfer LMM use.
# 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") )
# 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
lcbc_cols(...)
lcbc_cols(...)
... |
Character names of lcbc_colors |
in a ggplot, adding the logo should be added early in the plot building
lcbc_logo(type = "main", alpha = 0.4, ...)
lcbc_logo(type = "main", alpha = 0.4, ...)
type |
type of logo to get |
alpha |
opacity of logo |
... |
arguments to ggplot2 |
library(ggplot2) ggplot(mtcars, aes(x = wt, y = disp, colour = cyl)) + geom_point() + lcbc_logo()
library(ggplot2) ggplot(mtcars, aes(x = wt, y = disp, colour = cyl)) + geom_point() + lcbc_logo()
Return function to interpolate a lcbc color palette
lcbc_pal(palette = "main", reverse = FALSE, ...)
lcbc_pal(palette = "main", reverse = FALSE, ...)
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
mean_date(date1, date2)
mean_date(date1, date2)
date1 |
first date |
date2 |
second date |
mean difference between two dates
dates <- as.Date(c("2020-01-20", "1998-01-20")) mean_date(dates[1], dates[2])
dates <- as.Date(c("2020-01-20", "1998-01-20")) mean_date(dates[1], dates[2])
A dataset containing mock data mimicking core features like the NOAS data. For testing and examples in the package.
noas_example
noas_example
A data frame with 10 rows and 8 variables:
subject identifier
project identifier
assessment wave for the project
mri site identifier
mri folder on TSD
subject age at visit
cognitive score
subject sex
Function to extract project colors as hex codes
project_cols(...)
project_cols(...)
... |
Character names of project_colors |
Return function to interpolate a project color palette
project_pal(palette = "main", reverse = FALSE, ...)
project_pal(palette = "main", reverse = FALSE, ...)
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
scale_colour_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_color_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...)
scale_colour_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_color_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...)
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 |
Colour scale constructor for proj colours
scale_colour_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_color_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...)
scale_colour_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_color_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...)
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 |
Fill scale constructor for lcbc colours
scale_fill_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...)
scale_fill_lcbc(palette = "main", discrete = TRUE, reverse = FALSE, ...)
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 |
Fill scale constructor for proj colours
scale_fill_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...)
scale_fill_proj(palette = "main", discrete = TRUE, reverse = FALSE, ...)
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 |
ggplot minimal theme for lcbc
theme_lcbc(base_size = base_size_text)
theme_lcbc(base_size = base_size_text)
base_size |
text size |
ggplot minimal theme for lcbc
theme_lcbc_dark(base_size = base_size_text)
theme_lcbc_dark(base_size = base_size_text)
base_size |
text size |
ggplot dark theme for lcbc
theme_lcbc_dark_grid(base_size = base_size_text)
theme_lcbc_dark_grid(base_size = base_size_text)
base_size |
text size |
ggplot minimal theme for lcbc
theme_lcbc_dark_void(base_size = base_size_text)
theme_lcbc_dark_void(base_size = base_size_text)
base_size |
text size |
ggplot theme for lcbc
theme_lcbc_grid(base_size = base_size_text)
theme_lcbc_grid(base_size = base_size_text)
base_size |
text size |
ggplot minimal theme for lcbc
theme_lcbc_void(base_size = base_size_text)
theme_lcbc_void(base_size = base_size_text)
base_size |
text size |