Skip to content

Convenience functions for the LNCD. Includes db query, data processing, modeling, and visualizing

Notifications You must be signed in to change notification settings

LabNeuroCogDevel/LNCDR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LNCDR

Convenience functions for the LNCD

Test_LNCDR

DOI

Install

Succinctly, you can install with the command

remotes::install_github('LabNeuroCogDevel/LNCDR')

In more detail:

# install the package that handles installing if we haven't already
if (!'remotes' %in% installed.packages()) install.packages('remotes')

# if reinstalling, remove the old package from this workspace
detach("package:LNCDR", unload=TRUE)

# (re)install from most recent online source
remotes::install_github('LabNeuroCogDevel/LNCDR')

# load package
library(LNCDR)

Help

For help on all functions, in an R console, see ?LNCDR::tab

Functions

Stats

For better/more plotting facilities, see tidygam and tidymv (predict_gam and plot_smooths), gratia, and/or ggeffects. There's also a nice tutorial by Bart Larsen.

gam_growthrate_plot

 m <- gam(f1score ~ s(Ageatvisit) + s(visit) + s(id, bs="re"), data=d)
 ci <- gam_growthrate(m, 'Ageatvisit')
 gam_growthrate_plot(d, m, ci, 'Ageatvisit','f1score','id')

zscore zscorecols zscorewithinfactor

zscore dataframes

lmer_extract

get values (t, chisq, p) from a single variable in a model

Plotting

gganimate for data frames with an age column.

d <- data.frame(age=seq(10,30, length.out=8), x=runif(8), y=runif(8))
p  <- age_animate(d, rep_steps=16) +
      aes(x=x, y=y) +
      labs(title = 'Age: {frameage}')

gif <- p %>% lunaize %>% animate(fps=4, nframes=16, width = 480, height = 480)
anim_save("img/example_animate.gif", gif)

age_animate

waterfall_plot

Plot age at each visit for each participant (id and age column).

data.frame(id=rep(c(1:10),2),
           age=rep(c(11:20),each=2)+runif(20),
           sex=sample(rep(c('M','F'),5))) %>%
  waterfall_plot() +
  aes(color=sex) +
  see::theme_modern()

ggsave("img/waterfall_example.png",dpi=90, units='px', width=600, height=300)

waterfall plot

pubmed_search

For meta analysis, get a dataframe of pubmed search results (doi, title, authors, journal, year, abstract)

  btc_papers <- pubmed_search("Tervo-Clemmens[Author]", "tmp_xml/authsearch")

  #  journal  title   year  abstract                                doi   authors
  #  Biologi… Early … 2018  Retrospective neuroimaging studies hav… 10.1… Tervo-C…
  #  NeuroIm… Adoles… 2018  Given prior reports of adverse effects… 10.1… Tervo-C…
  #  Frontie… Neural… 2017  Risk for substance use disorder (SUD) … 10.3… Tervo-C…
  #  Annual … An int… 2015  "Brains systems undergo unique and spe… 10.1… Luna, B…
  #  Journal… Explor… 2013  Comorbid depression and anxiety disord… 10.4… Boyd, R…

lunaize

A better alternative is probably cowplot::theme_cowplot() or see::theme_modern()

Apply Dr. Luna's style to a ggplot. See ?lunaize for usage.

lunastyle

Data Wrangling

save1D

Dataframe to 1D file:

Given a data frame with a block column and a specified onset column, generate a 1D file for use in afni's 3dDeconvolve.

date_match

Match behavioral visit to scan visit.

Given two dataframes, both with a column of near matching dates, find the best match between the two.

parseROItempcor

read ROI_TempCorr *.rac1.adj_pearson.txt outputs into per subject rows.

roicormat_wide

extract unique pairs from a correlation matrix into a single row.

db_query

use .pg_pass to make quick queries to central database.

col_ungroup

extract variable grouped columns into rows. DEPRICATED. see tidyr::pivot_longer and https://mgimond.github.io/ES218/Week03b.html

a.mean b.mean c.mean a.std b.std c.std
     1      2      3    .6    .5   .4

TO

grp  mean  std
a    1     .6
b    2     .5
c    3     .4

interactive_label_match

match labels from one string vector with another

uppsp_scoring

scores uppsp 59-item

Imaging

to_nii

write a nifti file from a voxelwise dataframe

vox_cor

Given a seed region (mask) and target region (mask), return voxelwise correlations from a 4d nifti.

seed <- read_mask("striatum_mask.nii.gz")
target <- read_mask("gm_mask.nii.gz")
target <- target & ! seed
allcors <- vox_cor("subj_ts.nii.gz",seed,target)

spectrum functions

afni spect1

afni_save_spectrum(5, thres=2.68, posonly=T, lab="F")

spect2

You can also load a custom spectrum by right clicking Olay and saving the spectrum as a jpeg

getFromAfni custumnSpec

#### custumn color scale
cv <- afni.spectrum(0:5,img='custom_spec.jpg')
plot_colorspectrum(cv,'',side=1)

ijk functions

Convert ijk indexes between afni and oro MNI(LPI) data matrix.

afni_ijk

x <- oro.nifti::readNIfTI('betas.nii.gz')
dm <- dim(x)
mx <- arrayind(which.max(d),dm)
ijk.oro2afni(mx[1:3], dm )

Building the package and documentation

Build and test

make # see Makefile

Notes

Hilary Parker's package writeup was used as a template.

Rscript -e "devtools::document(); setwd('..'); devtools::install('LNCDR')"

Tests follow Hadley Wickham's testthat description.

Adding functions

  1. create a new or edit an existing *.R file within R/.
    • make sure #' @export is above a function definition you want exported. See roxygen primer. You can got to any function using 3 colons: LNCDR:::function_without_export
    • Other functions (esp. R/ld8.R) are a good starting place.
  2. run make
    • or, in an R console, run: devtools::document(); devtools::install('./')

About

Convenience functions for the LNCD. Includes db query, data processing, modeling, and visualizing

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages