MulaiMulai sekarang secara gratis

Seasonal Adjustment During Tax Season

Many time series exhibit strong seasonal behavior. The procedure for removing the seasonal component of a time series is called seasonal adjustment. For example, most economic data published by the government is seasonally adjusted.

You saw earlier that by taking first differences of a random walk, you get a stationary white noise process. For seasonal adjustments, instead of taking first differences, you will take differences with a lag corresponding to the periodicity.

Look again at the ACF of H&R Block's quarterly earnings, pre-loaded in the DataFrame HRB, and there is a clear seasonal component. The autocorrelation is high for lags 4,8,12,16,… because of the spike in earnings every four quarters during tax season. Apply a seasonal adjustment by taking the fourth difference (four represents the periodicity of the series). Then compute the autocorrelation of the transformed series.

Latihan ini adalah bagian dari kursus

Time Series Analysis in Python

Lihat Kursus

Petunjuk latihan

  • Create a new DataFrame of seasonally adjusted earnings by taking the lag-4 difference of quarterly earnings using the .diff() method.
  • Examine the first 10 rows of the seasonally adjusted DataFrame and notice that the first four rows are NaN.
  • Drop the NaN rows using the .dropna() method.
  • Plot the autocorrelation function of the seasonally adjusted DataFrame.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Import the plot_acf module from statsmodels
from statsmodels.graphics.tsaplots import plot_acf

# Seasonally adjust quarterly earnings
HRBsa = ___

# Print the first 10 rows of the seasonally adjusted series
print(HRBsa.___)

# Drop the NaN data in the first four rows
HRBsa = ___

# Plot the autocorrelation function of the seasonally adjusted series
plot_acf(HRBsa)
plt.show()
Edit dan Jalankan Kode