Convenience functions for the LNCD
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)
For help on all functions, in an R console, see ?LNCDR::
tab
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.
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 dataframes
get values (t, chisq, p) from a single variable in a model
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)
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)
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…
A better alternative is probably cowplot::theme_cowplot()
or see::theme_modern()
Apply Dr. Luna's style to a ggplot. See ?lunaize
for usage.
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
.
Match behavioral visit to scan visit.
Given two dataframes, both with a column of near matching dates, find the best match between the two.
read ROI_TempCorr
*.rac1.adj_pearson.txt
outputs into per subject rows.
extract unique pairs from a correlation matrix into a single row.
use .pg_pass
to make quick queries to central database.
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
match labels from one string vector with another
scores uppsp 59-item
write a nifti file from a voxelwise dataframe
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)
afni_save_spectrum(5, thres=2.68, posonly=T, lab="F")
You can also load a custom spectrum by right clicking Olay and saving the spectrum as a jpeg
#### custumn color scale
cv <- afni.spectrum(0:5,img='custom_spec.jpg')
plot_colorspectrum(cv,'',side=1)
Convert ijk indexes between afni and oro MNI(LPI) data matrix.
x <- oro.nifti::readNIfTI('betas.nii.gz')
dm <- dim(x)
mx <- arrayind(which.max(d),dm)
ijk.oro2afni(mx[1:3], dm )
make # see Makefile
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.
- create a new or edit an existing
*.R
file withinR/
.- 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.
- make sure
- run
make
- or, in an R console, run:
devtools::document(); devtools::install('./')
- or, in an R console, run: