Python package for statistical analysis of time series using resampling methods
Project description
stresampling
The aim of the package
The Python package stresampling implements resampling methods applicable to stationary timeseries, especially the stationary bootstrap (Politis, D. N. and Romano, J. P.) method for estimating statistical properties of stationary timeseries, using the bootstrap percentile, the bias-corrected, or the bootstrap-t methods, with an optimal choice of the parameter (Politis, D.N. and White, H., Patton, A., Politis, D.N. and White, H.) from a single time series.
The aim of the package is to provide an easy and intuitive interface to calculate statistics of desired quantities using single one timeseries, with minimal dependencies on other packages.
Authors
Yoshihiko Nishikawa (Tohoku University), Jun Takahashi (University of New Mexico), and Takashi Takahashi (University of Tokyo)
Requirements
- Python>=3.6
- numpy>=1.13.3
- scipy>=0.19.1
- psutil>=5.9.0
Usage
The stresampling package is very simple and intuitive to use. What you need are the timeseries you wish to analyze, a quantity of interest, and the coverage probability for the output confidence interval.
The following is a simple example showing how to use the package:
import numpy as np
from stresampling import stationary_bootstrap as sbm
def phys(timeseries): # Kurtosis of the distribution
return np.mean(timeseries**4.0) / np.mean(timeseries**2.0)**2.0
def main():
file = 'data/timeseries.dat'
timeseries = np.loadtxt(file)
print(timeseires.shape) # (10000,)
print(timeseries)
alpha = 0.68
stat = sbm.conf_int(timeseries, phys, alpha)
print('Mean:', stat.mean, 'Standard error:', stat.se, 'Lower and upper confidence limits:', stat.low, stat.up)
if __name__ == "__main__":
main()
Detail of the conf_int
function
stresampling.stationary_bootstrap.conf_int(seq, phys, alpha, number_bsamples, parallel=True, method='percentile')
-
parameters
-
seq
: ndarrayInput timeseries of shape (timeseries length, *)
-
phys
: FunctionA method to calculate the desired quantity
Note that the
conf_int
function currently supports only a scalar output -
alpha
: Real number in [0, 1]The coverage probability of the output confidence interval
-
number_bsamples
: Integer value, optionalThe number of bootstrap samples to be built
The default value is 1000
-
parallel
: Bool, optionalBuild bootstrap samples using multiple cores if True
The default is True
-
method
: {'percentile', 'bt', 'bca'}, optionalSpecify which method will be used to estimate the confidence limits
The default is 'percentile'
- 'percentile': the bootstrap percentile method
- 'bt': the bootstrap-t method
- 'bca': the bias-corrected method. Note that no acceleration is used in this package.
-
-
Return: Stat: a class including
mean
: The estimate of the quantityse
: The standard error of the estimatelow
andup
: The lower and upper confidence limitsprob
: The estimated optimal probability for the stationary bootstrap methoddist
: ndarray of the sorted bootstrap samples of the quantityautocorr
: ndarray for the unnormalized autocorrelation function of the timeseries
Installation
You can easily install the package via pypi as
pip install stresampling
or, by cloning the repository,
git clone https://github.com/YoshihikoNishikawa/stresampling.git
cd stresampling
pip install .
Future development
We will implement other resampling methods such as the circular bootstrap and the subsampling method in the future updates.
Citation
If you use this package or find it useful, please cite arXiv:2112.11837.
Contributing
If you wish to contribute, please submit a pull request.
If you find an issue or a bug, please contact us or raise an issue.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file stresampling-1.0.1.tar.gz
.
File metadata
- Download URL: stresampling-1.0.1.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 297dabe5b92c504a7b7e673981bbea89aee81b8696403f4e5c4c6de0eb4a42a1 |
|
MD5 | 1cbf509c02e98e7f7674a733156f9130 |
|
BLAKE2b-256 | d1d5187b519d941bff931dc8954d6cbd92e759cfe7c5a4b9497e4cb7762069bc |
File details
Details for the file stresampling-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: stresampling-1.0.1-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f4c9a81ed904f7386e06f58c469f2d1ff8b187e319f5c4b724c9d6a30e1afbe |
|
MD5 | 06c8e4b299d3b6a8a4f4af563dfa4158 |
|
BLAKE2b-256 | bc833389ce21775a43e08a1f0a36048385a504774b3ba28b170aac90b344e307 |