Skip to main content

Python package for statistical analysis of time series using resampling methods

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stresampling-1.0.2.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

stresampling-1.0.2-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file stresampling-1.0.2.tar.gz.

File metadata

  • Download URL: stresampling-1.0.2.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for stresampling-1.0.2.tar.gz
Algorithm Hash digest
SHA256 4e155d7d2965b46f820157720e0cfe3c6f0aa35a7441a3928920ee9dc7468dde
MD5 8da06aa60c277272d2cd7ad2bdd0d04c
BLAKE2b-256 a2d5deba25f4fecc3a48bfc40b739af2e6bea3b28ef2be3f552b1e7dfef890be

See more details on using hashes here.

File details

Details for the file stresampling-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for stresampling-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e33209f89827643bdd5145b6bacf4f2b6f3bc012c8af65b02878b5865b2b3e1
MD5 623433bce8b6c67feb4f23f6f6fc45fa
BLAKE2b-256 444e2a8b5f063e7f66f34cf21e4a6d28a42d58212525bca0ca4f884e4fb268d1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page