cor_ts {BINCOR} | R Documentation |
Bi-variate correlation
Description
The cor_ts
function estimates the correlation between the
binned time series. cor_ts
estimates three types of correlation
coefficients: Pearson’s correlation, Spearman’s and Kendall’s rank correlations
by means of the R native function cor.test (package:stats). The cor_ts
function has an option to remove the linear trend of the time series under analysis
(other pre-processing methods could be used) and its parameters are
described in the following lines.
Usage
cor_ts(bints1, bints2, varnamets1="NULL", varnamets2="NULL", KoCM, rmltrd="N",
device="screen", Hfig, Wfig, Hpdf, Wpdf, resfig, ofilename)
Arguments
bints1 , bints2 |
The bints1 and bints2 are the binned time series. |
varnamets1 , varnamets2 |
varnamets[1][2] are the names of the variables under study. |
KoCM |
KoCM indicates the correlation estimator: pearson for Pearson (the option by default), spearman for Spearman and kendall for Kendall. |
rmltrd |
This is the option used to remove the linear trend in the time series under study (by default the linear trend is not removed, but it can be activated with the option “Y” or “y”). |
device |
The type of the output device (by default the option is “screen”, and the other options are “jpg”, “png” and “pdf”) for the scatter plot for the binned time series. |
Hfig |
The height for the scatter plot in “jpg” or “png” format. |
Wfig |
The width for the scatter plot in “jpg” or “png” format. |
Hpdf |
The height for the scatter plot in “pdf” format. |
Wpdf |
The width for the scatter plot in “pdf” format. |
resfig |
resfig is the resolution in “ppi” (by default R does not record a resolution in the image file, except for BMP) for the scatter plot (“jpg” or “png” formats), an adequate value could be 150 ppi. |
ofilename |
The output filename for the scatter plot of the binned time series. |
Details
The cor_ts
estimate the correlation between two binned
time series by means of the R native function cor.test (package:stats).
Value
Output: an object of the form cor.test containing the correlation
coefficient and the statistical significance.
Output plot: screen or 'ofilename + .png, .jpg or .pdf'.
Author(s)
Josué M. Polanco-Martínez (a.k.a. jomopo).
BC3 - Basque Centre for Climate Change, Bilbao, SPAIN.
EPOC UMR CNRS 5805 - U. de Bordeaux, Pessac, FRANCE.
Web1: https://scholar.google.es/citations?user=8djLIhcAAAAJ&hl=en.
Web2: http://www.researchgate.net/profile/Josue_Polanco-Martinez.
Email: josue.m.polanco@gmail.com
References
Mudelsee, M. (2010). Climate Time Series Analysis: Classical Statistical and
Bootstrap Methods. Springer.
Mudelsee, M. (2014). Climate Time Series Analysis: Classical Statistical and
Bootstrap Methods, Second Edition. Springer.
Polanco-Martínez, J.M., Medina-Elizalde, M.A., Sánchez Goñi, M.F., M. Mudelsee. (2018). BINCOR: an R package to estimate the correlation between two unevenly spaced time series. Ms. under review (second round).
Examples
#####################################################################
#:: Figure 2 (Polanco-Martínez et al. (2018), (mimeo)).
#####################################################################
library("BINCOR")
library("pracma")
#####################################################################
#:: Loading the time series under analysis: example 1 (ENSO vs. NHSST)
#####################################################################
data(ENSO)
data(NHSST)
#####################################################################
# Computing the binned time series though our bin_cor function
#####################################################################
bincor.tmp <- bin_cor(ENSO.dat, NHSST.dat, FLAGTAU=3, "output_ENSO_NHSST.tmp")
binnedts <- bincor.tmp$Binned_time_series
#####################################################################
# Testing our cor_ts function: cor_ts.R
#####################################################################
# screen (scatterplot) and Pearson
cor_ts(binnedts[,1:2], binnedts[,c(1,3)], "ENSO-Nino3", "SST NH Mean",
KoCM="pearson", rmltrd="y")
# PDF format (scatterplot) and Kendall
cor_ts(binnedts[,1:2], binnedts[,c(1,3)], "ENSO-Nino3", "SST NH Mean",
KoCM="kendall", rmltrd="y", device="pdf", Hpdf=6, Wpdf=9, resfig=300,
ofilename="scatterplot_ENSO_SST")
# JPG format (scatterplot) and Spearman
cor_ts( binnedts[,1:2], binnedts[,c(1,3)], "ENSO-Nino3", "SST NH Mean",
KoCM="spearman", rmltrd="y", device="jpg", Hfig=900, Wfig=1200,
resfig=150, ofilename="scatterplot_ENSO_SST")