From 1c21dc0aa06b022090e4eeb93f06892422388131 Mon Sep 17 00:00:00 2001 From: Niklas Selke <n.selke@fz-juelich.de> Date: Mon, 22 May 2023 17:24:12 +0200 Subject: [PATCH] Fixed an issue when calling the moving block bootstrap algorithm with 'method=OLS'. --- toarstats/trends/interface.py | 2 +- toarstats/trends/ols.py | 2 +- toarstats/trends/utils.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/toarstats/trends/interface.py b/toarstats/trends/interface.py index 3cb825f..9998380 100644 --- a/toarstats/trends/interface.py +++ b/toarstats/trends/interface.py @@ -63,7 +63,7 @@ def calculate_trend(method, data, quantiles=None): if not all(0 < quantile < 1 for quantile in quantile_list): raise ValueError("The quantiles must be strictly between 0 and 1.") anomalies_series = calculate_anomalies(data_in) - if method == "quant_reg": + if method == "quant": fit = { quantile: quant_reg(anomalies_series, quantile) for quantile in quantile_list diff --git a/toarstats/trends/ols.py b/toarstats/trends/ols.py index 766ca2f..a34cf32 100644 --- a/toarstats/trends/ols.py +++ b/toarstats/trends/ols.py @@ -21,7 +21,7 @@ def ols(data): :return: The trend with its uncertainty and p value """ fit = smf.ols("value~datetime", data).fit(method="qr").params - mbb = moving_block_bootstrap("OLS", data, quantile) + mbb = moving_block_bootstrap("OLS", data) fit_se = np.nanstd(mbb, axis=0) fit_pv = 2*scipy.stats.t.sf(x=abs(fit/fit_se), df=len(data)-2) return {"trend": fit, "uncertainty": fit_se, "p_value": fit_pv} diff --git a/toarstats/trends/utils.py b/toarstats/trends/utils.py index 18f55b0..bd6167a 100644 --- a/toarstats/trends/utils.py +++ b/toarstats/trends/utils.py @@ -42,13 +42,14 @@ def calculate_anomalies(data): }).sort_values("datetime") -def moving_block_bootstrap(method, data, quantile, num_samples=1000): +def moving_block_bootstrap(method, data, quantile=None, num_samples=1000): """Perform the moving block bootstrap algorithm. :param method: either ``"OLS"`` or ``"quant"`` :param data: data containing a list of date time values and associated parameter values - :param quantile: a single quantile, must be between 0 and 1 + :param quantile: a single quantile, must be between 0 and 1 if + ``method="quant"`` :param num_samples: number of sampled trends :return: A list of sampled trends -- GitLab