2

I am trying to find whether my time series is additive or multiplicative I tried two-approach

  1. If the variance is high and varying with time i.e. high variability then the series is multiplicative or else its additive, but confused should it be on detrended series or original

  2. I have converted the blog code here

The converted python code is here :

import pandas as pd
import numpy as np
df=pd.read_csv("https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv")
df['Month'] = pd.to_datetime(df['Month'])
# Set the column 'Date' as index (skip if already done)
df = df.set_index('Month')
##Trend
df['Trend']=[0]*(7-1)+list(pd.Series(df['Passengers']).rolling(window=7).mean().iloc[7-1:].values)
# De-trend data
df['detrended_a']=df['Passengers']-df['Trend']
df['detrended_m']=df['Passengers']/df['Trend']
### Make seasonals
df['seasonal_a']=[0]*(7-1)+list(pd.Series(df['detrended_a']).rolling(window=7).mean().iloc[7-1:].values)
df['seasonal_m']=[0]*(7-1)+list(pd.Series(df['detrended_m']).rolling(window=7).mean().iloc[7-1:].values)
### residuals
df['residual_a']=df['detrended_a'] - df['seasonal_a']
df['residual_m']=df['detrended_m'] / df['seasonal_m']
import statsmodels.api as sm
acf_a = sum(pd.Series(sm.tsa.acf(df['residual_a'])).fillna(0))
acf_m= sum(pd.Series(sm.tsa.acf(df['residual_m'])).fillna(0))
if acf_a>acf_m:
   print("Additive")
else:
    print("Multiplicative")

But yet I am not sure about its usability across different kinds of series. If any one can help me to improve this method or suggest any better method

rinki nag
  • 25
  • 5

0 Answers0