เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ประมาณลำดับของโมเดล: PACF

เครื่องมือที่มีประโยชน์อย่างหนึ่งในการระบุลำดับของโมเดล AR คือการดู Partial Autocorrelation Function (PACF) ในแบบฝึกหัดนี้ จะจำลองอนุกรมเวลาสองชุด ได้แก่ AR(1) และ AR(2) แล้วคำนวณ PACF ตัวอย่างสำหรับแต่ละชุด สังเกตได้ว่าสำหรับ AR(1) ค่า PACF ที่ lag-1 จะมีนัยสำคัญ และหลังจากนั้นจะเข้าใกล้ศูนย์ ส่วน AR(2) ค่า PACF ที่ lag-1 และ lag-2 จะมีนัยสำคัญ และเป็นศูนย์หลังจากนั้น

เช่นเดียวกับที่ใช้ฟังก์ชัน plot_acf ในแบบฝึกหัดก่อนหน้า ในที่นี้จะใช้ฟังก์ชันชื่อ plot_pacf จากโมดูล statsmodels

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การวิเคราะห์อนุกรมเวลาด้วย Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • นำเข้าโมดูลสำหรับจำลองข้อมูลและสำหรับ plot PACF
  • จำลอง AR(1) ที่มี \(\small \phi=0.6\) (จำไว้ว่าเครื่องหมายของพารามิเตอร์ AR จะถูกกลับด้าน)
  • Plot PACF สำหรับ simulated_data_1 โดยใช้ฟังก์ชัน plot_pacf
  • จำลอง AR(2) ที่มี \(\small \phi_1=0.6, \phi_2=0.3\) (กลับเครื่องหมายเช่นเดิม)
  • Plot PACF สำหรับ simulated_data_2 โดยใช้ฟังก์ชัน plot_pacf

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Import the modules for simulating data and for plotting the PACF
from statsmodels.tsa.arima_process import ArmaProcess
from statsmodels.graphics.tsaplots import plot_pacf

# Simulate AR(1) with phi=+0.6
ma = np.array([1])
ar = np.array([1, -0.6])
AR_object = ArmaProcess(ar, ma)
simulated_data_1 = ___.generate_sample(nsample=5000)

# Plot PACF for AR(1)
plot_pacf(___, lags=20)
plt.show()

# Simulate AR(2) with phi1=+0.6, phi2=+0.3
ma = np.array([1])
ar = np.array([1, ___, ___])
AR_object = ArmaProcess(ar, ma)
simulated_data_2 = ___.generate_sample(nsample=5000)

# Plot PACF for AR(2)
plot_pacf(___, lags=20)
plt.show()
แก้ไขและรันโค้ด