Path: blob/master/Time Forecasting using Python/3.1 Non-Stationary data to Stationary Data.ipynb
3074 views
Transforming non-stationary data into stationary data is crucial for time series analysis, especially for models that assume stationarity (e.g., ARIMA models). Here are common techniques to achieve stationarity:
Differencing
Differencing is the most widely used method to remove trends and seasonality.
First-order differencing:
Subtract each value from the previous one.
Seasonal differencing:
Seasonal differencing is used to remove seasonal components of a time series. This involves subtracting the value from the same season in the previous cycle. Mathematically, for a given time series
Subtract the value from the same time period in the previous cycle.
Example
Suppose we have the following list of monthly sales data with a seasonality period
Transformation
Applying mathematical transformations can stabilize the variance.
Log transformation:
Useful when the variance grows with the mean.
Log transformation is often used in time series analysis to stabilize the variance and make the data more normally distributed. This transformation is particularly useful when dealing with data that has exponential growth patterns or heteroscedasticity (non-constant variance).
Please note:
Handling Zero or Negative Values: The log transformation can only be applied to positive values. If your data contains zero or negative values, you need to handle them appropriately (e.g., adding a constant to shift the data before transformation).
Choice of Base: While natural logarithm (base - e) is commonly used, you can use other bases such as 10 or 2 depending on the context. For example, you can use math.log10(value) for log base 10.
(2+3+4+5)/4 (2-10.25)**2+(3-10.25)**2+/ 4 S.D = sqr(Varince)
Square root transformation:
Square root transformation is a technique used to reduce the skewness of a distribution, particularly for right-skewed data. It involves applying the square root function to each value in the data set.
Useful for reducing skewness.
This transformation can help stabilize the variance and make the data more normally distributed.
Detrending
Detrending is the process of removing trends from a time series to isolate the underlying cyclical, seasonal, or irregular components. Trends in a time series represent long-term movements or changes in the mean level of the data over time. By detrending, we aim to study the more subtle fluctuations around the trend.
Using linear regression: Fit a linear model and subtract the fitted values.
Example of Detrending using Differencing
. Seasonal Adjustment
Remove seasonal effects by subtracting the seasonal mean.
Combining Techniques
Often, a combination of these techniques is required to achieve stationarity. For instance, you might first difference the data and then apply a log transformation.
Example Workflow:
Here's a complete example workflow combining differencing and transformation:
Verifying Stationarity
After transforming the data, it's important to verify that it is stationary. This can be done using statistical tests like the Augmented Dickey-Fuller (ADF) test
Quick Practice
To perform a lab work to transform two given input series into stationary data with following methods
diffrencing -Transforming
detrending
Seasonal differencing