Skip to content
Snippets Groups Projects
Commit 1c21dc0a authored by Niklas Selke's avatar Niklas Selke
Browse files

Fixed an issue when calling the moving block bootstrap algorithm with 'method=OLS'.

parent 8e6e48a0
No related branches found
No related tags found
2 merge requests!9Develop,!6Niklas issue009 feat calculate quantile regression
......@@ -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
......
......@@ -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}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment