本文簡要介紹 python 語言中 scipy.stats.mstats.sen_seasonal_slopes
的用法。
用法:
scipy.stats.mstats.sen_seasonal_slopes(x)#
計算季節性 Theil-Sen 和 Kendall 斜率估計器。
Sen 斜率的季節性概括計算 2D 數組的 “season”(列)內所有值對之間的斜率。它返回一個數組,其中包含每個季節的 “within-season” 斜率中位數(每個季節的 Theil-Sen 斜率估計器),並返回所有季節的 within-season 斜率中位數(季節性 Kendall 斜率估計器)。
- x: 類似二維數組
每一列x包含一個季節內因變量的測量值。每個季節的自變量(通常是時間)假設為
np.arange(x.shape[0])
.
- result:
SenSeasonalSlopesResult
實例 返回值是一個具有以下屬性的對象:
- intra_slope ndarray
對於每個季節,Theil-Sen 坡度估計器:within-season 坡度的中值。
- inter_slope 浮點數
季節性肯德爾斜率估計器:所有季節within-season 斜率的中位數。
- result:
參數 ::
返回 ::
注意:
季節內的坡度 為:
對於 的不同整數索引對 。
元素
歸來的intra_slope數組是中位數 全麵的 ;這是季節的 Theil-Sen 坡度估算器 。返回的inter_slope值,更廣為人知的名稱是季節性肯德爾斜率估計器,是 全麵的 .參考:
[1]羅伯特·M·赫希、詹姆斯·R·斯萊克和理查德·A·史密斯。 “月度水質數據趨勢分析技術。”水資源研究18.1(1982):107-121。
例子:
假設我們對四個季節中的每個季節的因變量有 100 個觀測值:
>>> import numpy as np >>> rng = np.random.default_rng() >>> x = rng.random(size=(100, 4))
我們計算季節性斜率:
>>> from scipy import stats >>> intra_slope, inter_slope = stats.mstats.sen_seasonal_slopes(x)
如果我們定義一個函數來計算一個季節內觀測值之間的所有斜率:
>>> def dijk(yi): ... n = len(yi) ... x = np.arange(n) ... dy = yi - yi[:, np.newaxis] ... dx = x - x[:, np.newaxis] ... # we only want unique pairs of distinct indices ... mask = np.triu(np.ones((n, n), dtype=bool), k=1) ... return dy[mask]/dx[mask]
那麽
intra_slope
的元素i
是dijk[x[:, i]]
的中位數:>>> i = 2 >>> np.allclose(np.median(dijk(x[:, i])), intra_slope[i]) True
inter_slope
是dijk
返回的所有季節值的中位數:>>> all_slopes = np.concatenate([dijk(x[:, i]) for i in range(x.shape[1])]) >>> np.allclose(np.median(all_slopes), inter_slope) True
由於數據是隨機生成的,我們預計所有季節內和跨季節的中位斜率幾乎為零,事實上它們是:
>>> intra_slope.data array([ 0.00124504, -0.00277761, -0.00221245, -0.00036338]) >>> inter_slope -0.0010511779872922058
相關用法
- Python SciPy mstats.sem用法及代碼示例
- Python SciPy mstats.trim用法及代碼示例
- Python SciPy mstats.winsorize用法及代碼示例
- Python SciPy mstats.argstoarray用法及代碼示例
- Python SciPy mstats.trima用法及代碼示例
- Python SciPy mstats.tmin用法及代碼示例
- Python SciPy mstats.tmax用法及代碼示例
- Python SciPy mstats.kruskalwallis用法及代碼示例
- Python SciPy mstats.zscore用法及代碼示例
- Python SciPy mstats.zmap用法及代碼示例
- Python SciPy mstats.mode用法及代碼示例
- Python SciPy mstats.hmean用法及代碼示例
- Python SciPy mstats.variation用法及代碼示例
- Python SciPy mstats.compare_medians_ms用法及代碼示例
- Python SciPy mstats.gmean用法及代碼示例
- Python SciPy mstats.pearsonr用法及代碼示例
- Python SciPy mstats.kruskal用法及代碼示例
- Python SciPy mstats.tmean用法及代碼示例
- Python SciPy mstats.mquantiles用法及代碼示例
- Python SciPy mstats.count_tied_groups用法及代碼示例
- Python SciPy mstats.chisquare用法及代碼示例
- Python SciPy mstats.describe用法及代碼示例
- Python SciPy mstats.find_repeats用法及代碼示例
- Python SciPy matlab.loadmat用法及代碼示例
- Python SciPy misc.ascent用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.stats.mstats.sen_seasonal_slopes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。