Block bootstrapping time series data

The usual bootstrapping method doesn't preserve the ordering of time series data, and it is, therefore, unsuitable for trend estimation. In the block bootstrapping approach, we split data into non-overlapping blocks of equal size and use those blocks to generate new samples. In this recipe, we will apply a very naive and easy-to-implement linear model with annual temperature data. The procedure for this recipe is as follows:

  1. Split the data into blocks and generate new data samples.
  2. Fit the data to a line or calculate the first differences of the new data.
  3. Repeat the previous step to build a list of slopes or medians of the first differences.

How to do it...

  1. The imports are as follows:
    import dautil as dl import random ...

Get Python Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.