From 5714aa4ed01dd6cb9bfa534a28386b9b411a1de7 Mon Sep 17 00:00:00 2001 From: Julien Emile-Geay Date: Mon, 15 Sep 2025 18:21:21 -0700 Subject: [PATCH 1/3] switched phaseran() to phaseran2(). Retired the old one --- pyleoclim/core/series.py | 4 +- pyleoclim/core/surrogateseries.py | 4 +- pyleoclim/utils/tsutils.py | 154 +++++++++++++++--------------- 3 files changed, 81 insertions(+), 81 deletions(-) diff --git a/pyleoclim/core/series.py b/pyleoclim/core/series.py index 6f72517b..4e942cc4 100644 --- a/pyleoclim/core/series.py +++ b/pyleoclim/core/series.py @@ -4206,7 +4206,7 @@ def causality(self, target_series, method='liang', timespan=None, settings=None, # pyleoclim.utils.tsmodel.ar1_sim : AR(1) simulator # pyleoclim.utils.tsmodel.uar1_sim : maximum likelihood AR(1) simulator - # pyleoclim.utils.tsutils.phaseran2 : phase randomization + # pyleoclim.utils.tsutils.phaseran : phase randomization # pyleoclim.utils.tsutils.random_time_axis : random time index vector according to a specific probability model # ''' @@ -4248,7 +4248,7 @@ def causality(self, target_series, method='liang', timespan=None, settings=None, # elif method == 'phaseran': # if self.is_evenly_spaced() and time_pattern != "random": - # y_surr = tsutils.phaseran2(self.value, number) + # y_surr = tsutils.phaseran(self.value, number) # else: # raise ValueError("Phase-randomization presently requires evenly-spaced series.") diff --git a/pyleoclim/core/surrogateseries.py b/pyleoclim/core/surrogateseries.py index 197d6042..2e6cc7f4 100644 --- a/pyleoclim/core/surrogateseries.py +++ b/pyleoclim/core/surrogateseries.py @@ -110,7 +110,7 @@ def from_series(self, target_series): pyleoclim.utils.tsmodel.uar1_sim : maximum likelihood AR(1) simulator - pyleoclim.utils.tsutils.phaseran2 : phase randomization + pyleoclim.utils.tsutils.phaseran : phase randomization Examples -------- @@ -140,7 +140,7 @@ def from_series(self, target_series): elif self.method == 'phaseran': if target_series.is_evenly_spaced(): - y_surr = tsutils.phaseran2(target_series.value, self.number) + y_surr = tsutils.phaseran(target_series.value, self.number) else: raise ValueError("Phase-randomization presently requires evenly-spaced series.") diff --git a/pyleoclim/utils/tsutils.py b/pyleoclim/utils/tsutils.py index 740dcbb8..56795679 100644 --- a/pyleoclim/utils/tsutils.py +++ b/pyleoclim/utils/tsutils.py @@ -17,7 +17,7 @@ 'detect_outliers_DBSCAN', 'detect_outliers_kmeans', 'remove_outliers', - 'phaseran2', + 'phaseran', 'custom_year_averages' ] @@ -1904,82 +1904,82 @@ def make_even_axis(x=None,start=None,stop=None,step=None,step_style=None,no_nans return time_axis -def phaseran(recblk, nsurr): - ''' Simultaneous phase randomization of a set of time series - - It creates blocks of surrogate data with the same second order properties as the original - time series dataset by transforming the original data into the frequency domain, randomizing the - phases simultaneoulsy across the time series and converting the data back into the time domain. - - Written by Carlos Gias for MATLAB - - http://www.mathworks.nl/matlabcentral/fileexchange/32621-phase-randomization/content/phaseran.m - - Parameters - ---------- - recblk : numpy array - 2D array , Row: time sample. Column: recording. - An odd number of time samples (height) is expected. - If that is not the case, recblock is reduced by 1 sample before the surrogate data is created. - The class must be double and it must be nonsparse. - - nsurr : int - is the number of image block surrogates that you want to generate. - - Returns - ------- - surrblk : numpy array - 3D multidimensional array image block with the surrogate datasey along the third dimension - - See also - -------- - - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series - pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate - - References - ---------- - - - Prichard, D., Theiler, J. Generating Surrogate Data for Time Series with Several Simultaneously Measured Variables (1994) Physical Review Letters, Vol 73, Number 7 - - - Carlos Gias (2020). Phase randomization, MATLAB Central File Exchange - ''' - # Get parameters - nfrms = recblk.shape[0] - - if nfrms % 2 == 0: - nfrms = nfrms-1 - recblk = recblk[0:nfrms] - - len_ser = int((nfrms-1)/2) - interv1 = np.arange(1, len_ser+1) - interv2 = np.arange(len_ser+1, nfrms) - - # Fourier transform of the original dataset - fft_recblk = np.fft.fft(recblk) - - surrblk = np.zeros((nfrms, nsurr)) - - # for k in tqdm(np.arange(nsurr)): - for k in np.arange(nsurr): - ph_rnd = np.random.rand(len_ser) - - # Create the random phases for all the time series - ph_interv1 = np.exp(2*np.pi*1j*ph_rnd) - ph_interv2 = np.conj(np.flipud(ph_interv1)) - - # Randomize all the time series simultaneously - fft_recblk_surr = np.copy(fft_recblk) - fft_recblk_surr[interv1] = fft_recblk[interv1] * ph_interv1 - fft_recblk_surr[interv2] = fft_recblk[interv2] * ph_interv2 - - # Inverse transform - surrblk[:, k] = np.real(np.fft.ifft(fft_recblk_surr)) - - return surrblk - - -def phaseran2(y, nsurr): +# def phaseran(recblk, nsurr): +# ''' Simultaneous phase randomization of a set of time series +# +# It creates blocks of surrogate data with the same second order properties as the original +# time series dataset by transforming the original data into the frequency domain, randomizing the +# phases simultaneoulsy across the time series and converting the data back into the time domain. +# +# Written by Carlos Gias for MATLAB +# +# http://www.mathworks.nl/matlabcentral/fileexchange/32621-phase-randomization/content/phaseran.m +# +# Parameters +# ---------- +# recblk : numpy array +# 2D array , Row: time sample. Column: recording. +# An odd number of time samples (height) is expected. +# If that is not the case, recblock is reduced by 1 sample before the surrogate data is created. +# The class must be double and it must be nonsparse. +# +# nsurr : int +# is the number of image block surrogates that you want to generate. +# +# Returns +# ------- +# surrblk : numpy array +# 3D multidimensional array image block with the surrogate datasey along the third dimension +# +# See also +# -------- +# +# pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series +# pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate +# +# References +# ---------- +# +# - Prichard, D., Theiler, J. Generating Surrogate Data for Time Series with Several Simultaneously Measured Variables (1994) Physical Review Letters, Vol 73, Number 7 +# +# - Carlos Gias (2020). Phase randomization, MATLAB Central File Exchange +# ''' +# # Get parameters +# nfrms = recblk.shape[0] +# +# if nfrms % 2 == 0: +# nfrms = nfrms-1 +# recblk = recblk[0:nfrms] +# +# len_ser = int((nfrms-1)/2) +# interv1 = np.arange(1, len_ser+1) +# interv2 = np.arange(len_ser+1, nfrms) +# +# # Fourier transform of the original dataset +# fft_recblk = np.fft.fft(recblk) +# +# surrblk = np.zeros((nfrms, nsurr)) +# +# # for k in tqdm(np.arange(nsurr)): +# for k in np.arange(nsurr): +# ph_rnd = np.random.rand(len_ser) +# +# # Create the random phases for all the time series +# ph_interv1 = np.exp(2*np.pi*1j*ph_rnd) +# ph_interv2 = np.conj(np.flipud(ph_interv1)) +# +# # Randomize all the time series simultaneously +# fft_recblk_surr = np.copy(fft_recblk) +# fft_recblk_surr[interv1] = fft_recblk[interv1] * ph_interv1 +# fft_recblk_surr[interv2] = fft_recblk[interv2] * ph_interv2 +# +# # Inverse transform +# surrblk[:, k] = np.real(np.fft.ifft(fft_recblk_surr)) +# +# return surrblk + + +def phaseran(y, nsurr): ''' Phase randomization of a time series y, of even or odd length. From f7b77fd9d2dbb868e33457e02b6a3f0e0f40c0b0 Mon Sep 17 00:00:00 2001 From: Julien Emile-Geay Date: Mon, 15 Sep 2025 18:29:38 -0700 Subject: [PATCH 2/3] retired old correlation utils --- pyleoclim/core/series.py | 2 - pyleoclim/utils/correlation.py | 340 ++++++++++++++++----------------- 2 files changed, 169 insertions(+), 173 deletions(-) diff --git a/pyleoclim/core/series.py b/pyleoclim/core/series.py index 4e942cc4..276ece67 100644 --- a/pyleoclim/core/series.py +++ b/pyleoclim/core/series.py @@ -3936,8 +3936,6 @@ def correlation(self, target_series, alpha=0.05, statistic='pearsonr', method = See also -------- - pyleoclim.utils.correlation.corr_sig : Correlation function (marked for deprecation) - pyleoclim.utils.correlation.association : SciPy measures of association between variables pyleoclim.series.surrogates : parametric and non-parametric surrogates of any Series object diff --git a/pyleoclim/utils/correlation.py b/pyleoclim/utils/correlation.py index fa32ffce..57e13eb8 100644 --- a/pyleoclim/utils/correlation.py +++ b/pyleoclim/utils/correlation.py @@ -5,89 +5,87 @@ """ __all__ = [ - 'corr_sig', 'fdr', 'association' ] import numpy as np import scipy.stats as stats -from sklearn import preprocessing -from .tsmodel import ar1_fit_evenly, isopersistent_rn -from .tsutils import phaseran +from .tsmodel import ar1_fit_evenly +#from .tsutils import phaseran -def corr_sig(y1, y2, nsim=1000, method='isospectral', alpha=0.05): - """ Estimates the Pearson's correlation and associated significance between two non IID time series +# def corr_sig(y1, y2, nsim=1000, method='isospectral', alpha=0.05): +# """ Estimates the Pearson's correlation and associated significance between two non IID time series - The significance of the correlation is assessed using one of the following methods: +# The significance of the correlation is assessed using one of the following methods: - 1) 'ttest': T-test adjusted for effective sample size. - This is a parametric test (data are Gaussian and identically distributed) with a rather ad-hoc adjustment. - It is instantaneous but makes a lot of assumptions about the data, many of which may not be met. - 2) 'isopersistent': AR(1) modeling of x and y. - This is a parametric test as well (series follow an AR(1) model) but - solves the issue by direct simulation. - 3) 'isospectral': phase randomization of original inputs. (default) - This is a non-parametric method, assuming only wide-sense stationarity +# 1) 'ttest': T-test adjusted for effective sample size. +# This is a parametric test (data are Gaussian and identically distributed) with a rather ad-hoc adjustment. +# It is instantaneous but makes a lot of assumptions about the data, many of which may not be met. +# 2) 'isopersistent': AR(1) modeling of x and y. +# This is a parametric test as well (series follow an AR(1) model) but +# solves the issue by direct simulation. +# 3) 'isospectral': phase randomization of original inputs. (default) +# This is a non-parametric method, assuming only wide-sense stationarity - For 2 and 3, computational requirements scale with nsim. - When possible, nsim should be at least 1000. +# For 2 and 3, computational requirements scale with nsim. +# When possible, nsim should be at least 1000. - Parameters - ---------- - y1 : array - vector of (real) numbers of same length as y2, no NaNs allowed +# Parameters +# ---------- +# y1 : array +# vector of (real) numbers of same length as y2, no NaNs allowed - y2 : array - vector of (real) numbers of same length as y1, no NaNs allowed +# y2 : array +# vector of (real) numbers of same length as y1, no NaNs allowed - nsim : int - the number of simulations [default: 1000] +# nsim : int +# the number of simulations [default: 1000] - method : str; {'ttest','isopersistent','isospectral' (default)} - method for significance testing +# method : str; {'ttest','isopersistent','isospectral' (default)} +# method for significance testing - alpha : float - significance level for critical value estimation [default: 0.05] - - Returns - ------- - res : dict - the result dictionary, containing - - - r : float - correlation coefficient - - p : float - the p-value - - signif : bool - true if significant; false otherwise - Note that signif = True if and only if p <= alpha. +# alpha : float +# significance level for critical value estimation [default: 0.05] + +# Returns +# ------- +# res : dict +# the result dictionary, containing + +# - r : float +# correlation coefficient +# - p : float +# the p-value +# - signif : bool +# true if significant; false otherwise +# Note that signif = True if and only if p <= alpha. - See also - -------- +# See also +# -------- - pyleoclim.utils.correlation.corr_ttest : Estimates the significance of correlations between 2 time series using the classical T-test adjusted for effective sample size - pyleoclim.utils.correlation.corr_isopersist : Computes correlation between two timeseries, and their significance using Ar(1) modeling - pyleoclim.utils.correlation.corr_isospec : Estimates the significance of the correlation using phase randomization - pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate +# pyleoclim.utils.correlation.corr_ttest : Estimates the significance of correlations between 2 time series using the classical T-test adjusted for effective sample size +# pyleoclim.utils.correlation.corr_isopersist : Computes correlation between two timeseries, and their significance using Ar(1) modeling +# pyleoclim.utils.correlation.corr_isospec : Estimates the significance of the correlation using phase randomization +# pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate - """ - y1 = np.array(y1, dtype=float) - y2 = np.array(y2, dtype=float) - - assert np.size(y1) == np.size(y2), 'The size of y1 and y2 should be the same' - - if method == 'ttest': - (r, signif, p) = corr_ttest(y1, y2, alpha=alpha) - elif method == 'isopersistent': - (r, signif, p) = corr_isopersist(y1, y2, alpha=alpha, nsim=nsim) - elif method == 'isospectral': - (r, signif, p) = corr_isospec(y1, y2, alpha=alpha, nsim=nsim) +# """ +# y1 = np.array(y1, dtype=float) +# y2 = np.array(y2, dtype=float) + +# assert np.size(y1) == np.size(y2), 'The size of y1 and y2 should be the same' + +# if method == 'ttest': +# (r, signif, p) = corr_ttest(y1, y2, alpha=alpha) +# elif method == 'isopersistent': +# (r, signif, p) = corr_isopersist(y1, y2, alpha=alpha, nsim=nsim) +# elif method == 'isospectral': +# (r, signif, p) = corr_isospec(y1, y2, alpha=alpha, nsim=nsim) - res={'r':r,'signif':signif,'p':p} +# res={'r':r,'signif':signif,'p':p} - return res +# return res def fdr(pvals, qlevel=0.05, method='original', adj_method=None, adj_args={}): ''' Determine significance based on the false discovery rate @@ -239,155 +237,155 @@ def corr_ttest(y1, y2, alpha=0.05, df_min=10): return r, signif, pval, rcrit -def corr_isopersist(y1, y2, alpha=0.05, nsim=1000): - ''' Computes the Pearson's correlation between two timeseries, and their significance using Ar(1) modeling. +# def corr_isopersist(y1, y2, alpha=0.05, nsim=1000): +# ''' Computes the Pearson's correlation between two timeseries, and their significance using Ar(1) modeling. - The significance is gauged via a non-parametric (Monte Carlo) simulation of - correlations with nsim AR(1) processes with identical persistence - properties as x and y ; the measure of which is the lag-1 autocorrelation (g). - - Parameters - ---------- - y1 : array - vectors of (real) numbers with identical length, no NaNs allowed +# The significance is gauged via a non-parametric (Monte Carlo) simulation of +# correlations with nsim AR(1) processes with identical persistence +# properties as x and y ; the measure of which is the lag-1 autocorrelation (g). + +# Parameters +# ---------- +# y1 : array +# vectors of (real) numbers with identical length, no NaNs allowed - y2 : array - vectors of (real) numbers with identical length, no NaNs allowed +# y2 : array +# vectors of (real) numbers with identical length, no NaNs allowed - alpha : float - significance level for critical value estimation [default: 0.05] +# alpha : float +# significance level for critical value estimation [default: 0.05] - nsim : int - number of simulations [default: 1000] +# nsim : int +# number of simulations [default: 1000] - Returns - ------- - r : float - correlation between x and y +# Returns +# ------- +# r : float +# correlation between x and y - signif : bool - true (1) if significant; false (0) otherwise +# signif : bool +# true (1) if significant; false (0) otherwise - pval : float - test p-value (the probability of the test statstic exceeding the observed one by chance alone) - - Notes - ----- - - The probability of obtaining a test statistic at least as extreme as the one actually observed, - assuming that the null hypothesis is true. - The test is 1 tailed on |r|: Ho = { |r| = 0 }, Ha = { |r| > 0 } - The test is rejected (signif = 1) if pval <= alpha, otherwise signif=0; - (Some Rights Reserved) Hepta Technologies, 2009 - v1.0 USC, Aug 10 2012, based on corr_signif. +# pval : float +# test p-value (the probability of the test statstic exceeding the observed one by chance alone) + +# Notes +# ----- + +# The probability of obtaining a test statistic at least as extreme as the one actually observed, +# assuming that the null hypothesis is true. +# The test is 1 tailed on |r|: Ho = { |r| = 0 }, Ha = { |r| > 0 } +# The test is rejected (signif = 1) if pval <= alpha, otherwise signif=0; +# (Some Rights Reserved) Hepta Technologies, 2009 +# v1.0 USC, Aug 10 2012, based on corr_signif. - See also - -------- +# See also +# -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series - pyleoclim.utils.correlation.corr_ttest: Estimates Pearson's correlation and associated significance using a t-test - pyleoclim.utils.correlation.corr_isospec : Estimates Pearson's correlation and associated significance using - pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate +# pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series +# pyleoclim.utils.correlation.corr_ttest: Estimates Pearson's correlation and associated significance using a t-test +# pyleoclim.utils.correlation.corr_isospec : Estimates Pearson's correlation and associated significance using +# pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate - ''' +# ''' - r = stats.pearsonr(y1, y2)[0] - ra = np.abs(r) +# r = stats.pearsonr(y1, y2)[0] +# ra = np.abs(r) - y1_red, g1 = isopersistent_rn(y1, nsim) - y2_red, g2 = isopersistent_rn(y2, nsim) +# y1_red, g1 = isopersistent_rn(y1, nsim) +# y2_red, g2 = isopersistent_rn(y2, nsim) - rs = np.zeros(nsim) - for i in np.arange(nsim): - rs[i] = stats.pearsonr(y1_red[:, i], y2_red[:, i])[0] +# rs = np.zeros(nsim) +# for i in np.arange(nsim): +# rs[i] = stats.pearsonr(y1_red[:, i], y2_red[:, i])[0] - rsa = np.abs(rs) +# rsa = np.abs(rs) - xi = np.linspace(0, 1.1*np.max([ra, np.max(rsa)]), 200) - kde = stats.gaussian_kde(rsa) - prob = kde(xi).T +# xi = np.linspace(0, 1.1*np.max([ra, np.max(rsa)]), 200) +# kde = stats.gaussian_kde(rsa) +# prob = kde(xi).T - diff = np.abs(ra - xi) - # min_diff = np.min(diff) - pos = np.argmin(diff) +# diff = np.abs(ra - xi) +# # min_diff = np.min(diff) +# pos = np.argmin(diff) - pval = np.trapz(prob[pos:], xi[pos:]) +# pval = np.trapz(prob[pos:], xi[pos:]) - rcrit = np.percentile(rsa, 100*(1-alpha)) - signif = ra >= rcrit +# rcrit = np.percentile(rsa, 100*(1-alpha)) +# signif = ra >= rcrit - return r, signif, pval +# return r, signif, pval -def corr_isospec(y1, y2, alpha=0.05, nsim=1000): - ''' Estimates the significance of the correlation using phase randomization +# def corr_isospec(y1, y2, alpha=0.05, nsim=1000): +# ''' Estimates the significance of the correlation using phase randomization - Estimates the significance of correlations between non IID - time series by phase randomization of original inputs. - This function creates 'nsim' random time series that have the same power - spectrum as the original time series but random phases. +# Estimates the significance of correlations between non IID +# time series by phase randomization of original inputs. +# This function creates 'nsim' random time series that have the same power +# spectrum as the original time series but random phases. - Parameters - ---------- - y1 : array - vectors of (real) numbers with identical length, no NaNs allowed +# Parameters +# ---------- +# y1 : array +# vectors of (real) numbers with identical length, no NaNs allowed - y2 : array - vectors of (real) numbers with identical length, no NaNs allowed +# y2 : array +# vectors of (real) numbers with identical length, no NaNs allowed - alpha : float - significance level for critical value estimation [default: 0.05] +# alpha : float +# significance level for critical value estimation [default: 0.05] - nsim : int - number of simulations [default: 1000] +# nsim : int +# number of simulations [default: 1000] - Returns - ------- - r : float - correlation between y1 and y2 +# Returns +# ------- +# r : float +# correlation between y1 and y2 - signif : bool - true (1) if significant; false (0) otherwise +# signif : bool +# true (1) if significant; false (0) otherwise - F : float - Fraction of time series with higher correlation coefficents than observed (approximates the p-value). +# F : float +# Fraction of time series with higher correlation coefficents than observed (approximates the p-value). - See also - -------- +# See also +# -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series - pyleoclim.utils.correlation.corr_ttest : Estimates Pearson's correlation and associated significance using a t-test - pyleoclim.utils.correlation.corr_isopersist : Estimates Pearson's correlation and associated significance using AR(1) simulations - pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate +# pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series +# pyleoclim.utils.correlation.corr_ttest : Estimates Pearson's correlation and associated significance using a t-test +# pyleoclim.utils.correlation.corr_isopersist : Estimates Pearson's correlation and associated significance using AR(1) simulations +# pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate - References - ---------- +# References +# ---------- - - Ebisuzaki, W, 1997: A method to estimate the statistical significance of a correlation when the data are serially correlated. J. of Climate, 10, 2147-2153. +# - Ebisuzaki, W, 1997: A method to estimate the statistical significance of a correlation when the data are serially correlated. J. of Climate, 10, 2147-2153. - - Prichard, D., Theiler, J. Generating Surrogate Data for Time Series with Several Simultaneously Measured Variables (1994) Physical Review Letters, Vol 73, Number 7 (Some Rights Reserved) USC Climate Dynamics Lab, 2012. - ''' - r = stats.pearsonr(y1, y2)[0] +# - Prichard, D., Theiler, J. Generating Surrogate Data for Time Series with Several Simultaneously Measured Variables (1994) Physical Review Letters, Vol 73, Number 7 (Some Rights Reserved) USC Climate Dynamics Lab, 2012. +# ''' +# r = stats.pearsonr(y1, y2)[0] - # generate phase-randomized samples using the Theiler & Prichard method - Y1surr = phaseran(y1, nsim) - Y2surr = phaseran(y2, nsim) +# # generate phase-randomized samples using the Theiler & Prichard method +# Y1surr = phaseran(y1, nsim) +# Y2surr = phaseran(y2, nsim) - # compute correlations - Y1s = preprocessing.scale(Y1surr) - Y2s = preprocessing.scale(Y2surr) +# # compute correlations +# Y1s = preprocessing.scale(Y1surr) +# Y2s = preprocessing.scale(Y2surr) - n = np.size(y1) - C = np.dot(np.transpose(Y1s), Y2s) / (n-1) - rSim = np.diag(C) +# n = np.size(y1) +# C = np.dot(np.transpose(Y1s), Y2s) / (n-1) +# rSim = np.diag(C) - # compute fraction of values higher than observed - F = np.sum(np.abs(rSim) >= np.abs(r)) / nsim +# # compute fraction of values higher than observed +# F = np.sum(np.abs(rSim) >= np.abs(r)) / nsim - # establish significance - signif = F < alpha # significant or not? +# # establish significance +# signif = F < alpha # significant or not? - return r, signif, F +# return r, signif, F ''' The FDR procedures translated from fdr.R by Dr. Chris Paciorek (https://www.stat.berkeley.edu/~paciorek/research/code/code.html) From c44580f0b6a6a7d12c101ac04ddb116ee163153e Mon Sep 17 00:00:00 2001 From: Julien Emile-Geay Date: Tue, 16 Sep 2025 10:00:00 -0700 Subject: [PATCH 3/3] cleaned up docstrings removed references to unused functions --- pyleoclim/core/corr.py | 3 +-- pyleoclim/core/correns.py | 3 +-- pyleoclim/utils/correlation.py | 8 -------- pyleoclim/utils/tsmodel.py | 2 -- pyleoclim/utils/tsutils.py | 2 -- 5 files changed, 2 insertions(+), 16 deletions(-) diff --git a/pyleoclim/core/corr.py b/pyleoclim/core/corr.py index 4e07179c..9ae48565 100644 --- a/pyleoclim/core/corr.py +++ b/pyleoclim/core/corr.py @@ -62,9 +62,8 @@ class Corr: See also -------- - pyleoclim.utils.correlation.corr_sig : Correlation function - pyleoclim.utils.correlation.fdr : FDR function + pyleoclim.utils.correlation.association : workhorse function to compute various metrics of association ''' def __init__(self, r, p, r_crit, signif, alpha, p_fmt_td=0.01, p_fmt_style='exp'): diff --git a/pyleoclim/core/correns.py b/pyleoclim/core/correns.py index 1653547c..2c7937bc 100644 --- a/pyleoclim/core/correns.py +++ b/pyleoclim/core/correns.py @@ -80,9 +80,8 @@ class CorrEns: See also -------- - - pyleoclim.utils.correlation.corr_sig : Correlation function + pyleoclim.utils.correlation.association : workhorse function to compute various metrics of association pyleoclim.utils.correlation.fdr : FDR (False Discovery Rate) function ''' diff --git a/pyleoclim/utils/correlation.py b/pyleoclim/utils/correlation.py index 57e13eb8..a5f15faa 100644 --- a/pyleoclim/utils/correlation.py +++ b/pyleoclim/utils/correlation.py @@ -130,7 +130,6 @@ def fdr(pvals, qlevel=0.05, method='original', adj_method=None, adj_args={}): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series References @@ -206,9 +205,6 @@ def corr_ttest(y1, y2, alpha=0.05, df_min=10): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series - pyleoclim.utils.correlation.corr_isopersist : Estimate Pearson's correlation and associated significance using AR(1) - pyleoclim.utils.correlation.corr_isospec : Estimate Pearson's correlation and associated significance using phase randomization pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate """ @@ -409,7 +405,6 @@ def fdr_basic(pvals,qlevel=0.05): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series pyleoclim.utils.correlation.fdf : Determine significance based on the false discovery rate References @@ -459,7 +454,6 @@ def fdr_master(pvals, qlevel=0.05, method='original'): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series pyleoclim.utils.correlation.fdf : Determine significance based on the false discovery rate References @@ -496,7 +490,6 @@ def storey(edf_quantile, pvals): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series pyleoclim.utils.correlation.fdf : Determine significance based on the false discovery rate References @@ -545,7 +538,6 @@ def prop_alt(pvals, adj_method='mean', adj_args={'edf_lower': 0.8, 'num_steps': See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series pyleoclim.utils.correlation.fdf : Determine significance based on the false discovery rate References diff --git a/pyleoclim/utils/tsmodel.py b/pyleoclim/utils/tsmodel.py index 0f3b48c1..4113c049 100644 --- a/pyleoclim/utils/tsmodel.py +++ b/pyleoclim/utils/tsmodel.py @@ -298,7 +298,6 @@ def isopersistent_rn(y, p): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate Notes @@ -340,7 +339,6 @@ def sm_ar1_sim(n, p, g, sig): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate ''' diff --git a/pyleoclim/utils/tsutils.py b/pyleoclim/utils/tsutils.py index 56795679..7205da2b 100644 --- a/pyleoclim/utils/tsutils.py +++ b/pyleoclim/utils/tsutils.py @@ -1934,7 +1934,6 @@ def make_even_axis(x=None,start=None,stop=None,step=None,step_style=None,no_nans # See also # -------- # -# pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series # pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate # # References @@ -2001,7 +2000,6 @@ def phaseran(y, nsurr): See also -------- - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate References