How to determine if a time series is stationery in R

This recipe helps you determine if a time series is stationery in R

Recipe Objective

How to determine if a time series is stationary

Time series is a statistical technique that deals with time series data or trend analysis. Time series data means the data is collected over a period of time/ intervals. To check if a time series data is stationary or not, we use the Dickey-Fuller test using the adf.test function of the tseries package. This test makes the following assumptions: H0 (Null hypothesis): The time series data is non-stationary. HA (Alternate hypothesis): The time series data is stationary. This recipe demonstrates an example to determine if a time series is stationary in R.

Get Access to Time Series Analysis Real World Projects in Python

Step 1 - Install required library

library(tseries)

Step 2 - Generate random time series data

data <- rnorm(50)
data_ts <- ts(data,,frequency=4)
data_ts

Step 3 - Plot the data

plot(data_ts)

Step 4 - Perform the dickey-fuller test

adf.test(data_ts)

As the number of lags used for the test is 12, we get a t_stat value of -3.2316 and a p value of 0.09234. As the p value is > 0.05, we say that we cannot reject the null hypothesis. Hence the data is non-stationary in nature.

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

Mastering A/B Testing: A Practical Guide for Production
In this A/B Testing for Machine Learning Project, you will gain hands-on experience in conducting A/B tests, analyzing statistical significance, and understanding the challenges of building a solution for A/B testing in a production environment.

Learn How to Build PyTorch Neural Networks from Scratch
In this deep learning project, you will learn how to build PyTorch neural networks from scratch.

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Build a Text Classification Model with Attention Mechanism NLP
In this NLP Project, you will learn to build a multi class text classification model with attention mechanism.

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

AWS Project to Build and Deploy LSTM Model with Sagemaker
In this AWS Sagemaker Project, you will learn to build a LSTM model on Sagemaker for sales forecasting while analyzing the impact of weather conditions on Sales.