Skip to content

Python package for statistical analysis of stationary timeseries using resampling methods

License

Notifications You must be signed in to change notification settings

YoshihikoNishikawa/stresampling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stresampling

license pypi python

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(timeseries.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: ndarray

      Input timeseries of shape (timeseries length, *)

    • phys: Function

      A 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, optional

      The number of bootstrap samples to be built

      The default value is 1000

    • parallel: Bool, optional

      Build bootstrap samples using multiple cores if True

      The default is True

    • method: {'percentile', 'bt', 'symbt', 'bc'}, optional

      Specify which method will be used to estimate the confidence limits

      The default is 'percentile'

  • Return: Stat: a class including

    • mean: The estimate of the quantity
    • se: The standard error of the estimate
    • low and up: The lower and upper confidence limits
    • prob: The estimated optimal probability for the stationary bootstrap method
    • dist: ndarray of the sorted bootstrap samples of the quantity
    • autocorr: 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.

About

Python package for statistical analysis of stationary timeseries using resampling methods

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages