Skip to content

Commit

Permalink
general maintenance update
Browse files Browse the repository at this point in the history
  • Loading branch information
abarbour committed Aug 14, 2023
1 parent c65fce5 commit b5944e5
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 9 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/R-CMD-check.yaml
Expand Up @@ -29,26 +29,31 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v1
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-tinytex@v2
- run: tlmgr --version

- name: Install additional LaTeX packages
run: |
tlmgr install txfonts upquote caption
tlmgr list --only-installed
- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v1
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
error-on: '"error"'

2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -51,4 +51,4 @@ Encoding: UTF-8
Language: en-US
VignetteBuilder: knitr
LinkingTo: Rcpp, RcppArmadillo
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Binary file modified vignettes/fftw.pdf
Binary file not shown.
Binary file modified vignettes/multivariate.pdf
Binary file not shown.
242 changes: 242 additions & 0 deletions vignettes/multivariate.tex
@@ -0,0 +1,242 @@
\documentclass[11pt]{article}\usepackage[]{graphicx}\usepackage[]{xcolor}
% maxwidth is the original width if it is less than linewidth
% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\let\hlipl\hlkwb

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
\def\at@end@of@kframe{}%
\ifinner\ifhmode%
\def\at@end@of@kframe{\end{minipage}}%
\begin{minipage}{\columnwidth}%
\fi\fi%
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
\colorbox{shadecolor}{##1}\hskip-\fboxsep
% There is no \\@totalrightmargin, so:
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width
\@totalleftmargin\z@ \linewidth\hsize
\@setminipage}}%
{\par\unskip\endMakeFramed%
\at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}
% !Rnw weave = knitr
%% \VignetteIndexEntry{Multivariate PSD}
%% \VignetteEngine{knitr::knitr}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyvrb}
\usepackage[pdfborder={0 0 0}]{hyperref}
\usepackage{url}
\usepackage{upquote}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{float}
\usepackage{natbib}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{geometry}
\geometry{verbose,tmargin=3cm,bmargin=5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage[font=sf, labelfont={sf,bf}, margin=2cm]{caption}
\usepackage{color}
\usepackage{txfonts}

%%
%\input{supp_mathsyms}
%%

\newcommand{\Rcmd}[1]{\texttt{#1}}
\newcommand{\psd}[0]{\href{https://github.com/abarbour/psd/}{\color{blue}\Rcmd{psd}}}

\title{Multivariate methods for the \Rcmd{psd} package}
\author{Jonathan R. Kennel and Andrew J. Barbour}
%

\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\maketitle
%
\begin{abstract}
%
This vignette provides a brief description of the outputs of the multivariate methods contained in the \Rcmd{psd} package. Multivariate methods are commonly used for investigating relationships between inputs and outputs.
%
\end{abstract}

\tableofcontents
\clearpage

\section{Univariate Power Spectral Densities}

To calculate the univariate power spectral density, simply pass a
single timeseries to \Rcmd{pspectrum}. Please see the psd overview vignette for more information.




\section{Multivariate Power Spectral Densities}

The \Rcmd{pspectrum} function can also used to calculate the multivariate power spectral density.
As an example, the WIPP 30 dataset from BETCO will be used (\citet{Toll2007}).
There are three data series provided in this dataset corresponding to water levels,
barometric pressure changes and Earth tides. \Rcmd{pspectrum} for a multivariate
series takes a matrix input with each column referring to a different series.
The first column(s) refers to the input, and the last columns are the outputs.
This order can also be changed if desired. The method currently only handles
one output but can take multiple inputs. The following outputs in addition
to the typical univariate output of \Rcmd{pspectrum} are returned:

\begin{itemize}
\item Auto-spectra and cross-spectra (complex matrix)
\item Coherence (real matrix)
\item Phase (real matrix)
\item Transfer functions (complex matrix)
\end{itemize}


\input{figure/loadwipp.tex}

\input{figure/calcmv.tex}


\input{figure/names.tex}

\input{figure/plotnames.tex}


\clearpage

\subsection{Number of tapers}

For the multivariate psd method, the same numbers of tapers at a given frequency is used for each series. These numbers can be chosen in one of three ways using the \Rcmd{riedsid\_column} parameter:

\begin{itemize}
\item The maximum number of tapers of all the series for each frequency (riedsid\_column = 0)
\item The minimum number of tapers of all the series for each frequency (riedsid\_column < 0);
\item The number of tapers can be selected based on a specific series (riedsid\_column = column\_number).
\end{itemize}

\input{figure/Tapers.tex}
\input{figure/Taperplot.tex}

\subsubsection{Specifying the number of tapers}

The number of tapers can also be specified as a single value.

\input{figure/taperspecification.tex}

The number of tapers can also be specified as a vector of values. The length of the vector is equal to one-half the number of rows rounded down (i.e. integer division). The example below uses an approximately linearly increasing taper vector.

\input{figure/taperspecification2.tex}

\newpage

\subsection{Equations}

\begin{itemize}

\item \Rcmd{`coh'}: $ \text{coherence}_{xy} = |G_{xy}|^2 / (G_{xx} * G_{yy})$

\item \Rcmd{`phase'}: $ \text{phase}_{xy} = Arg(G_{xy})$

\item \Rcmd{`transfer'}: \href{https://en.wikipedia.org/wiki/Cramer%27s_rule}{Cramer's Rule} is used to solve for the transfer function with the complex array \Rcmd{pspec} as the input. Thus:

\item $ \text{gain} = Mod(\text{transfer}) $
\item $ \text{phase} = Arg(\text{transfer}) $

\end{itemize}



\subsection{Auto-spectra and Cross-spectra}

The auto-spectra and cross-spectra are stored in the \Rcmd{pspec} list item returned from \Rcmd{pspectrum}. It is a complex numbered three-dimensional array with the dimensions equal to the length of the psd X number of variables X number of variables. The diagonal of the array are the auto-spectra and the off diagonals are the cross-spectra.


\input{figure/pspec.tex}


\newpage

\subsection{Coherence}

The coherence is stored in result from pspectrum and contains the coherence between input and each of the outputs. In this section we will use a constant number of tapers to get a result similar to \Rcmd{spec.pgram}.




\input{figure/coh.tex}

\input{figure/cohbaplot.tex}

\input{figure/cohetplot.tex}


\subsection{Phase}

The phase is stored in result from pspectrum and contains the cross-spectrum phase. The Earth tide phase fluctuates rapidly because for many frequencies the spectral power is very small.



\input{figure/phase.tex}

\input{figure/phasebaplot.tex}

\input{figure/phaseetplot.tex}

\subsection{Frequency Response}

The multivariate method calculates the auto and cross-spectra and also solves for a frequency response. The frequency response is stored as a complex number matrix. A three column matrix was provided to pspectrum which results a two column matrix of frequency responses.

\input{figure/transfergain.tex}

\input{figure/transfergainplot.tex}


\input{figure/transferphase.tex}

\input{figure/transferphaseplot.tex}

\section{Conclusion}

The \Rcmd{psd} package can handle multivariate time series and provides results including the auto and cross-spectra, phase, coherence, and the frequency response function.


\section*{Session Info}
\input{figure/SI.tex}


%% bib and index
\bibliographystyle{apalike}
\bibliography{REFS}

\end{document}
Binary file modified vignettes/normalization.pdf
Binary file not shown.
Binary file modified vignettes/psd_overview.pdf
Binary file not shown.

0 comments on commit b5944e5

Please sign in to comment.