## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4)

## -----------------------------------------------------------------------------
library(metricT)

## ----eval = FALSE-------------------------------------------------------------
#  feats <- mt_features_from_eeg_csv(files, sfreq = 128)

## -----------------------------------------------------------------------------
mt_bands()

## -----------------------------------------------------------------------------
sim <- mt_simulate(n = c(A = 20, B = 20), seed = 1)
names(sim$features)
dim(sim$features$alpha$wpli)   # subjects x channel pairs
table(sim$group)

## -----------------------------------------------------------------------------
f <- tempfile(fileext = ".csv")
mt_write_features_csv(sim$features, sim$group, f)
dat <- mt_read_features_csv(f)
names(read.csv(f, check.names = FALSE))[1:4]
unlink(f)

## -----------------------------------------------------------------------------
res <- metric_t(dat$features, dat$group, n_perm = 2000, seed = 42)
res

## -----------------------------------------------------------------------------
head(as.data.frame(res)[, c("band", "DC_wPLI", "DC_MSC", "T", "reversal", "p_raw", "p_min", "T_attain", "p_attain", "p_WY")])

## -----------------------------------------------------------------------------
plot(res)

## -----------------------------------------------------------------------------
small <- mt_simulate(n = c(A = 6, B = 7), n_ch = 5, n_epochs = 12, seed = 7)
ex <- metric_t(small$features, small$group, exact = TRUE, wy_family = "all")
ex

## -----------------------------------------------------------------------------
sp <- mt_label_space(small$features)
sp
mt_locate(sp, small$group == "A")       # the observed grouping
session <- rep(c("s1", "s2", "s3"), c(4, 4, 5))
mt_locate(sp, session == "s1")          # a recording session treated as a group

## -----------------------------------------------------------------------------
set.seed(11)
years <- round(runif(13, 0, 40))
tr <- metric_t_trend(small$features, years, strata = session)
tr

## ----eval = FALSE-------------------------------------------------------------
#  run_metricT_app()   # requires the 'shiny' package

## ----eval = FALSE-------------------------------------------------------------
#  citation("metricT")

