Calculate periodogram for a timecourse using LombScargle, fast Fourier
transform, or selected version of chisquare. The spectr
function is a
wrapper for the various methods. lspgram
is in turn a wrapper for
lomb::lsp()
, and fftpgram
a wrapper for stats::spec.pgram()
. Among the
versions of chisquare, it is highly recommended to use greedy, which has
lower bias than standard and lower variance than conservative.
cspgram( x, deltat, periodRange = c(18, 32), method = c("greedy", "conservative", "standard"), na.action = stats::na.fail, dopar = FALSE ) fftpgram( x, deltat, periodRange = c(18, 32), pad = 50, na.action = stats::na.fail, ... ) lspgram(x, deltat, time, periodRange = c(18, 32), ofac = 50) spectr( x, deltat, time, periodRange = c(18, 32), method = c("greedy_chisq", "conservative_chisq", "standard_chisq", "lombscargle", "fft"), ofac = 50, pad = 50, na.action = stats::na.fail, dopar = FALSE, ... )
x  Numeric vector of measurements. 

deltat  Numeric value of the interval between timepoints. 
periodRange  Numeric vector of the minimum and maximum values of the
period to consider, in the same units as 
method  Character indicating which method to use. Can be an unambiguous substring of the full name. 
na.action  Function specifying how to handle 
dopar  Logical indicating whether to run calculations in parallel if
a parallel backend is already set up, e.g., using

pad  Numeric value of the proportion of the length of 
...  Other arguments passed to 
time  Numeric vector of timepoints. Can be specified instead of

ofac  Integer value of the oversampling factor. Must be >= 1. Only used for LombScargle. 
A data.table
with various columns depending on the method. For any
version of chisquare, columns will be period
, chisq
, df
, and
log_pval
. The log pvalue is more reliable than the pvalue, since R has
finite precision, so pvalues less than about 5e324 would be set to 0. For
LombScargle and FFT, columns will be period
and power
.
library('data.table') set.seed(1789) deltat = 0.1 tau = 25 tt = seq(0, 24 * 3, deltat) x = 3 * sin(tt / tau * 2 * pi) + rnorm(length(tt)) specCsp = spectr(x, deltat, method = 'greedy') peakCsp = specCsp[which.min(log_pval)] specLsp = spectr(x, deltat, method = 'lomb') peakLsp = specLsp[which.max(power)] specFft = spectr(x, deltat, method = 'fft') peakFft = specFft[which.max(power)]