您好,登錄后才能下訂單哦!
這篇文章主要介紹怎么使用python實(shí)現(xiàn)畫AR模型時(shí)序圖,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
背景:
用python畫AR模型的時(shí)序圖。
結(jié)果:
代碼:
import numpy as np import matplotlib.pyplot as plt """ AR(1)的時(shí)序圖:x[t]=a*x[t-1]+e """ num = 2000 e = np.random.rand(num) x = np.empty(num) """ 平穩(wěn)AR(1) """ a = -0.5 x[0] = 2 for i in range(1,num): x[i] = a*x[i-1]+e[i] plt.subplot(321,title = "AR({0}):x[t]={1}*x[t-1]+e".format(1,a)) plt.plot(x,"or") """ 非平穩(wěn)AR(1) """ a = -1.01 x[0] = 2 for i in range(1,num): x[i] = a*x[i-1]+e[i] plt.subplot(322,title = "AR({0}):x[t]={1}*x[t-1]+e".format(1,a)) plt.plot(x,".b") """ 平穩(wěn)AR(2) """ a = -0.2 b = 0.7 x[0] = 2 for i in range(2,num): x[i] = a*x[i-1]+b*x[i-2]+e[i] plt.subplot(323,title = "AR({0}):x[t]={1}*x[t-1]+{2}*x[t-2]+e".format(2,a,b)) plt.plot(x,"og") """ 非平穩(wěn)AR(2) """ a = -0.3 b = 0.8 x[0] = 2 for i in range(2,num): x[i] = a*x[i-1]+b*x[i-2]+e[i] plt.subplot(324,title = "AR({0}):x[t]={1}*x[t-1]+{2}*x[t-2]+e".format(2,a,b)) plt.plot(x,".y") """ 非平穩(wěn)AR(2) """ a = -0.2 b = 0.8 x[0] = 2 for i in range(2,num): x[i] = a*x[i-1]+b*x[i-2]+e[i] plt.subplot(313,title = "AR({0}):x[t]={1}*x[t-1]+{2}*x[t-2]+e".format(2,a,b)) plt.plot(x,"+",color="purple") plt.show()
以上是“怎么使用python實(shí)現(xiàn)畫AR模型時(shí)序圖”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。