Learn R Programming

RolWinMulCor (version 0.4.0)

rolwinmulcor_1win: Estimate and plot the Rolling Window Correlation for the multi-variate case

Description

The rolwinmulcor_1win function estimates the rolling (running) window correlation among multiple time series (multi-variate case) sampled on identical time points for ONLY ONE window-length and plots the correlation coefficients and their respective p-values. The multivariate case is based on the concept of multiple regression and generalizes the standard coefficient of correlation. We follow to Abdi (2007) to implement computationally this technique. The rolwinmulcor_1win function is highly flexible since this contains a great number of parameters to control the estimation of correlation and the features of the plot output. For example, rolwinmulcor_1win function contains parameters to remove the (linear) trend contained in the time series under analysis, to choose different p-value correction methods (which are used to address the multiple comparison problem), or to personalise the plot output. A list of parameters are described in the following lines.

Usage

rolwinmulcor_1win(inputdata, varnametsY="", varnametsX="", units="", 
                  coltsY="black", coltsX="", LWDtsY=1, LWDtsX="", 
                  LWDcoef=1, LWDpval=1, CEXLAB=1.15, CEXAXIS=1.05, 
                  NUMLABX=5, parcen=c(0.5,25), colCOEF="black", 
                  colPVAL="gray", rmltrd="Y", Scale="Y", widthwin=3, 
                  Align="center", pvalcorectmethod="BH", device="screen", 
                  Hfig=1200, Wfig=900, resfig=150, Hpdf=5.15, Wpdf=13.5, 
                  HeigWin1=2.05, HeigWin2=2.75, ofilename)

Arguments

inputdata

Matrix of P columns: time, dependent variable (\(Y\)), and independent variables (\(X_1, X_2,..., X_{P-2}\)).

varnametsY

Name of the dependent variable: \(Y\). Please note that the name of this variable MUST be defined.

varnametsX

Name of the independent variables: \(X_1, X_2,..., X_{p-2}\). Please note that the names of these variables MUST defined in this way: varnametsX=paste("X1", "X2",..., sep=", ").

units

Time's unit (e.g. days, weeks, years, etc.) for the time series under analysis. Please note that the units MUST de defined.

coltsY, coltsX

The colors to be used when the dependent (\(Y\)) and independent (\(X_1, X_2,...\)) variables are plotted, by default for the dependent variable the color is ``black'' (although other colors can be used) and the colors for the independent variables MUST be provided (e.g. coltsX=c("red","blue",...)).

LWDtsY, LWDtsX

These parameters are used to define the line-widths when the dependent and independent variables are plotted, by default and for the dependent variable this has a value of 1 (although other values (widths) can be used), and for the independent variables the line-widths MUST be provided (e.g. LWDtsX = c(1,2,...)).

LWDcoef, LWDpval

The line-widths to be used when the correlation coefficients and their respective p-values are plotted, by default these parameters have a value of 1, but other values (widths) can be used.

CEXLAB, CEXAXIS

The parameters are used to plot the sizes of the X-axis and Y-axis labels and X- and Y-axis, by default these parameters have values of 1.15 and 1.05, respectively, but it is possible to use other values.

NUMLABX

Number of labels for (all) the X's axis, by the default is 5, but it is possible to use other values.

parcen

These parameters contain two values: the first one is to control the position of the title, by default it is 0.5, but you should try with other close values to obtain the title centered, e.g. 0.4 or 0.8 (please avoid to use large values); the second value is to define the spaces between the names of variables, by default is 25 spaces, but you could try other values to fit properly the names of variables in the title. We use ``mtext'' to produce the title (please loot at R>?mtext for more information).

colCOEF, colPVAL

The colors to be used when the correlation coefficients and their corresponding p-values are plotted, by default the colors are ``black'' and ``gray,'' but it is possible to use other colors.

rmltrd

Remove (by default is ``Y'' or ``y''; please use ``N'' or ``n'' otherwise) the linear trend in the time series under analysis.

Scale

Scale (by default is ``Y'' or ``y''; please use ``N'' or ``n'' otherwise) is used to ``normalize'' or ``standardize'' the time series under analysis.

widthwin

Window's size to compute the rolling window correlations, this MUST be odd (i.e. of the form 2m + 1, where m is a natural number), the minimum values is 3 (the default value), but this information MUST be provided.

Align

To align the rolling object, RolWinMulCor ONLY uses the ``center'' option (please look at: R>?rollapply) to ensure that variations in the correlation are aligned with the variations in the relationship of the time series under study rather than being shifted (Polanco-Mart<U+00ED>nez 2019).

pvalcorectmethod

The p-value correction method to be used, by default the method of Benjamini and Hochberg (BH) (1995) is used since this is less conservative and performs much better than Bonferroni, but other six methods (e.g. Holm, Bonferroni, etc.) are available (please look at: R>?p.adjust).

device

Kind of plot output (please look at: R>?device), there are five options: ``png'', ``jpeg/jpg'', ``eps'', ``pdf'' and ``screen.'' By default device is ``screen.''

Hfig, Wfig

Plot's height and width (for the device) for the plot in ``png'' and ``jpg'' format (look at R>?png or R>?jpg), by default Hfig and Wfig have values of 1200 and 900, but other values can be used.

resfig

Image resolution (in ``ppi'') for the plot in ``png'' and ``jpg'' format (look at R>?png , R>?jpg or R>?jpeg), by default this has a value of 150, but other mage resolutions can be used.

Hpdf, Wpdf

Plot's height and width (for the device) for ``pdf'' or ``eps'' format (>R?pdf or >R?postscript), by default Hpdf and Wpdf are equal to 5.15 and 13.5, but it is possible to use other values.

HeigWin1, HeigWin2

Proportion of window's size to plot the time series under analysis (HeigWin1) and the rolling window correlation coefficients and p-values (HeigWin2) (look at: R>?layout to get more information). By default HeigWin1 and HeigWin2 have value of 2.05 and 2.75, but it is possible to use other values.

ofilename

Output file name.

Value

Outputs:

Plot output: screen or 'plot_multivariate_' + 'ofilename + .png, .jpg, .eps or .pdf'.

Numerical output: a list containing Correlation_coefficients, P_values_corrected, and P_values_not_corrected, which are self-explanatory.

Details

The rolwinmulcor_1win function estimates the rolling window correlation among multiple time series (multi-variate case) sampled on identical time points for ONLY ONE window-length and plots the rolling correlation coefficients and their respective p-values. rolwinmulcor_1win uses the functions rollapply (package:zoo) that is able to tackle matrices, the native R function p.adjust (package:stats), and some pieces of code and an auxiliary function that we have created specifically for our function rolwinmulcor_1win and RolWinMulCor R package.

References

Abdi H. Multiple correlation coefficient, in Encyclopedia of Measurement and Statistics, N. J. Salkind, Ed. Sage, Thousand Oaks, CA, USA, 2007; 648-651. <URL: https://personal.utdallas.edu/~herve/Abdi-MCC2007-pretty.pdf>.

Benjamini, Y., and Hochberg, Y. (1995). Controlling the false discovery rate: a practical and powerful approach to multiple testing. Journal of the Royal Statistical Society Series B, 57 (1), 289-300. <URL: https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1995.tb02031.x>.

Polanco-Mart<U+00ED>nez, J. M. (2019). Dynamic relationship analysis between NAFTA stock markets using nonlinear, nonparametric, non-stationary methods. Nonlinear Dynamics, 97(1), 369-389. <URL: https://doi.org/10.1007/s11071-019-04974-y>.

Examples

Run this code
# NOT RUN {
 # Loading packages
 library("RolWinMulCor") 
 library("zoo") 
 library("pracma") 
 # Loading data set  
 data(synthetic_data)
 # Testing the function 'rolwinmulcor_1win' (multi-variate case)
 # Window length = 51 and plot output in screen format 
 test1_rolwinmulcor_1win <- rolwinmulcor_1win(synthetic_data, varnametsY="Y", 
                             varnametsX=paste("X1", "X2", "X3", sep=", "), 
                             coltsX = c("red", "blue", "green"), units="NU", 
                             parcen=c(0.6,25), widthwin=51, device="screen")
 #  Window length = 75 and plot output in screen format 
 test2_rolwinmulcor_1win <- rolwinmulcor_1win(synthetic_data, varnametsY="Y", 
                             varnametsX=paste("X1", "X2", "X3", sep=", "), 
                             coltsX = c("red", "blue", "green"), units="NU", 
                             parcen=c(0.6,25), widthwin=75, device="screen")
# }

Run the code above in your browser using DataLab