specenv | R Documentation |
Computes the spectral envelope of categorical-valued or real-valued time series.
specenv(xdata, section = NULL, spans = NULL, kernel = NULL, taper = 0,
significance = 1e-04, plot = TRUE, ylim = NULL, real = FALSE, ...)
xdata |
For categorical-valued sequences, a matrix with rows that are indicators
of the categories represented by the columns, possibly a sequence converted using
|
section |
of the form |
spans |
specify smoothing used in |
kernel |
specify kernel to be used in |
taper |
specify amount of tapering to be used in |
significance |
significance threshold exhibited in plot - default is .0001; set to NA to cancel |
plot |
if TRUE (default) a graphic of the spectral envelope is produced |
ylim |
limits of the spectral envelope axis; if NULL (default), a suitable range is calculated. |
real |
FALSE (default) for categorical-valued sequences and TRUE for real-valued sequences. |
... |
other graphical parameters. |
Calculates the spectral envelope for categorical-valued series as discussed in
https://www.stat.pitt.edu/stoffer/dss_files/spenv.pdf
and summarized in
https://doi.org/10.1214/ss/1009212816.
Alternately, calculates the spectral envelope for real-valued series as discussed in
https://doi.org/10.1016/S0378-3758(96)00044-4.
These concepts are also presented (with examples) in Section 7.9 (Chapter 7) of Time Series Analysis and Its Applications: With R Examples: https://www.stat.pitt.edu/stoffer/tsa4/.
For categorical-valued series, the input xdata
must be a matrix of indicators which is perhaps a sequence preprocessed using dna2vector
.
For real-valued series, the input xdata
should be a matrix whose columns are various transformations of the univariate series.
The script does not detrend the data prior to estimating spectra. If this is an issue, then detrend the data prior to using this script.
By default, will produce a graph of the spectral envelope and an approximate significance threshold. A matrix containing: frequency, spectral envelope ordinates, and (1) the scalings of the categories in the order of the categories in the alphabet or (2) the coefficients of the transformations, is returned invisibly.
D.S. Stoffer
You can find demonstrations of astsa capabilities at FUN WITH ASTSA.
The most recent version of the package can be found at https://github.com/nickpoison/astsa/.
In addition, the News and ChangeLog files are at https://github.com/nickpoison/astsa/blob/master/NEWS.md.
The webpages for the texts and some help on using R for time series analysis can be found at https://nickpoison.github.io/.
dna2vector
## Not run:
# a DNA sequence
data = bnrf1ebv
xdata = dna2vector(data)
u = specenv(xdata, section=1:1000, spans=c(7,7))
head(u) # scalings are for A, C, G, and last one T=0 always
# a real-valued series (nyse returns)
x = astsa::nyse
xdata = cbind(x, abs(x), x^2)
u = specenv(xdata, real=TRUE, spans=c(3,3))
# plot optimal transform at freq = .001
beta = u[2, 3:5]
b = beta/beta[2] # makes abs(x) coef=1
gopt = function(x) { b[1]*x+b[2]*abs(x)+b[3]*x^2 }
curve(gopt, -.2, .2, col=4, lwd=2, panel.first=Grid())
g2 = function(x) { b[2]*abs(x) } # corresponding to |x|
curve(g2, -.2,.2, add=TRUE, col=6)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.