The cross-spectra of several channel pairs, stacked with a pair factor
Source: R/pairs.R
frm_cross_pairs.Rdcross_wishart() models ONE channel pair. A recording with more
channels has a pair for every two of them, and the questions asked of
it are about all of those pairs at once. frm_cross_pairs() runs
frm_cross_spectrum() on each pair and stacks the results, one block
per pair, with a pair factor that a model can use.
Arguments
- X
The recording: a numeric matrix or a data frame of numeric columns whose COLUMNS ARE CHANNELS and whose rows are samples, or a list of such matrices, one per epoch, each with the same channels. Channel names come from the column names, or are
ch1,ch2, and so on when there are none.- pairs
Which pairs to form.
NULL, the default, forms every pair of two different channels, in column order. Otherwise a two-column matrix or data frame, one row per pair, naming each channel by name or by column number.- ...
Passed to
frm_cross_spectrum():sfreq,segments,tapers,smooth,window,frangeand, for a list of epochs,group.
Value
The rows of frm_cross_spectrum() for every pair, with the
factors pair ("a-b" for channels a and b), ch1 and ch2
in front. ch1 is the signal frm_cross_spectrum() takes as x,
so the fitted phase is the lead of ch1 over ch2.
Many pairs in one model
Fitting each pair on its own and correcting the p-values afterwards treats the pairs as unrelated. One model over the stacked frame lets them share information instead:
coh ~ 1 + (1 | pair)gives each pair its own coherence, shrunk toward the pairs' common level by as much as the data say the pairs differ. A pair that stands out after shrinkage stands out against the others, which is the comparison a multiple-comparison correction tries to make after the fact.coh ~ s(freq, by = pair)withpairalso a fixed effect gives each pair its own coherence spectrum, andfrm_coherence()reads each one off with a band.coh ~ 0 + pair, withmu,pow2andphasealso bypair, is the separate fits in one call: the likelihood is then a sum of one term per pair, so each pair's estimate is the one its own fit gives.
The power of a channel appears in every pair that includes it, so the blocks share channels. Each block is still a correct likelihood for its own pair; what the stacked likelihood does not model is the dependence between two blocks that share a channel. Read the standard errors of a stacked fit with that in mind.