使用glarma包估算BARMA模型

时间:2018-06-14 01:14:08

标签: r time-series forecasting

我正在尝试使用来自R的glarma软件包来估计一个没有移动avarage组件的二进制自回归移动平均(BARMA)模型.jstat文件(https://www.jstatsoft.org/article/view/v067i07)认为BARMA模型可以适应glarma软件包但它没有给出任何拟合二项分布的例子,伯努利是我感兴趣的特例。在实践中,我想得到经济衰退的概率(衰退时y = 1,扩张时y = 0)使用二进制变量的过去观察和连续预测器,比如x。

z<-(
"Month_Year         X Y
86     1996-02  99.45975 0
87     1996-03  99.65509 0
88     1996-04  99.84560 0
89     1996-05 100.01900 0
90     1996-06 100.16610 0
91     1996-07 100.28170 0
92     1996-08 100.36410 0
93     1996-09 100.43720 0
94     1996-10 100.52220 0
95     1996-11 100.63570 0
96     1996-12 100.76500 0
97     1997-01 100.89550 0
98     1997-02 101.00230 0
99     1997-03 101.07710 0
100    1997-04 101.10980 0
101    1997-05 101.08710 0
102    1997-06 101.00720 0
103    1997-07 100.86730 0
104    1997-08 100.66720 0
105    1997-09 100.40610 1
106    1997-10 100.08910 1
107    1997-11  99.73795 1
108    1997-12  99.41429 1
109    1998-01  99.17356 1
110    1998-02  99.04559 1
111    1998-03  98.99677 1
112    1998-04  98.97177 1
113    1998-05  98.91449 1
114    1998-06  98.79021 1
115    1998-07  98.58416 1
116    1998-08  98.31280 1
117    1998-09  98.03580 1
118    1998-10  97.83183 1
119    1998-11  97.75050 1
120    1998-12  97.79238 1
121    1999-01  97.94292 1
122    1999-02  98.18636 1
123    1999-03  98.51665 1
124    1999-04  98.91557 1
125    1999-05  99.34491 1
126    1999-06  99.74365 0
127    1999-07 100.07490 0
128    1999-08 100.32100 0
129    1999-09 100.49780 0
130    1999-10 100.62220 0
131    1999-11 100.71340 0
132    1999-12 100.79530 0
133    2000-01 100.88310 0
134    2000-02 100.98710 0
135    2000-03 101.10020 0
136    2000-04 101.21350 0
137    2000-05 101.32690 0
138    2000-06 101.42570 0
139    2000-07 101.48150 0
140    2000-08 101.47170 0
141    2000-09 101.40530 0
142    2000-10 101.30170 0
143    2000-11 101.18180 0
144    2000-12 101.05700 1
145    2001-01 100.91470 1
146    2001-02 100.72290 1
147    2001-03 100.45690 1
148    2001-04 100.11370 1
149    2001-05  99.70970 1
150    2001-06  99.29787 1
151    2001-07  98.94471 1
152    2001-08  98.70450 1
153    2001-09  98.59423 1
154    2001-10  98.61945 1
155    2001-11  98.76863 1
156    2001-12  98.99450 1
157    2002-01  99.24209 1
158    2002-02  99.45296 1
159    2002-03  99.59255 1
160    2002-04  99.64648 1
161    2002-05  99.61874 1
162    2002-06  99.53635 1
163    2002-07  99.42953 1
164    2002-08  99.31564 1
165    2002-09  99.19376 1
166    2002-10  99.05710 1
167    2002-11  98.91230 1
168    2002-12  98.76412 1
169    2003-01  98.63148 1
170    2003-02  98.52281 1
171    2003-03  98.44492 1
172    2003-04  98.40364 1
173    2003-05  98.41142 1
174    2003-06  98.50822 1
175    2003-07  98.73607 1
176    2003-08  99.10629 0
177    2003-09  99.56125 0
178    2003-10 100.01620 0
179    2003-11 100.39520 0
180    2003-12 100.65770 0
181    2004-01 100.79950 0
182    2004-02 100.84060 0
183    2004-03 100.82970 0
184    2004-04 100.81450 0
185    2004-05 100.82410 0
186    2004-06 100.85740 0
187    2004-07 100.88310 0
188    2004-08 100.86770 0
189    2004-09 100.79620 1
190    2004-10 100.66380 1
191    2004-11 100.47460 1
192    2004-12 100.24670 1
193    2005-01 100.00600 1
194    2005-02  99.77551 1
195    2005-03  99.55034 1
196    2005-04  99.32622 1
197    2005-05  99.11332 1
198    2005-06  98.93478 1
199    2005-07  98.81171 1
200    2005-08  98.75800 1
201    2005-09  98.77325 1
202    2005-10  98.85077 1
203    2005-11  98.99262 1
204    2005-12  99.19006 0
205    2006-01  99.40803 0
206    2006-02  99.61194 0
207    2006-03  99.77552 0
208    2006-04  99.88607 0
209    2006-05  99.94712 0
210    2006-06  99.98738 0
211    2006-07 100.04780 0
212    2006-08 100.14650 0
213    2006-09 100.30130 0
214    2006-10 100.51280 0
215    2006-11 100.75700 0
216    2006-12 101.00010 0
217    2007-01 101.23690 0
218    2007-02 101.48260 0
219    2007-03 101.73630 0
220    2007-04 102.00100 0
221    2007-05 102.25590 0
222    2007-06 102.49180 0
223    2007-07 102.70640 0
224    2007-08 102.89490 0
225    2007-09 103.06730 0
226    2007-10 103.20180 0
227    2007-11 103.27270 0
228    2007-12 103.27810 0
229    2008-01 103.24160 0
230    2008-02 103.19320 0
231    2008-03 103.11820 0
232    2008-04 102.98450 0
233    2008-05 102.72400 1
234    2008-06 102.25180 1
235    2008-07 101.47420 1
236    2008-08 100.50930 1
237    2008-09  99.40029 1
238    2008-10  98.26229 1
239    2008-11  97.28954 1
240    2008-12  96.63335 1
241    2009-01  96.35611 1
242    2009-02  96.43845 1
243    2009-03  96.81737 1
244    2009-04  97.40713 0
245    2009-05  98.09644 0
246    2009-06  98.79945 0
247    2009-07  99.46492 0
248    2009-08 100.06810 0
249    2009-09 100.59230 0
250    2009-10 101.02140 0
251    2009-11 101.34270 0
252    2009-12 101.55690 0
253    2010-01 101.67500 0
254    2010-02 101.71390 0
255    2010-03 101.69120 0
256    2010-04 101.62320 0
257    2010-05 101.54930 0
258    2010-06 101.51170 0
259    2010-07 101.53350 0
260    2010-08 101.62020 0
261    2010-09 101.75220 0
262    2010-10 101.89080 0
263    2010-11 101.99610 0
264    2010-12 102.05080 0
265    2011-01 102.05290 0
266    2011-02 102.00730 0
267    2011-03 101.91880 0
268    2011-04 101.77360 0
269    2011-05 101.56500 1
270    2011-06 101.30440 1
271    2011-07 101.02060 1
272    2011-08 100.76050 1
273    2011-09 100.56920 1
274    2011-10 100.46990 1
275    2011-11 100.45810 1
276    2011-12 100.51640 1
277    2012-01 100.60950 1
278    2012-02 100.70350 1
279    2012-03 100.76430 0
280    2012-04 100.78170 0
281    2012-05 100.77250 0
282    2012-06 100.77170 0
283    2012-07 100.79880 0
284    2012-08 100.84520 0
285    2012-09 100.88340 0
286    2012-10 100.88510 0
287    2012-11 100.84560 0
288    2012-12 100.77100 0
289    2013-01 100.66200 0
290    2013-02 100.52760 0
291    2013-03 100.37900 0
292    2013-04 100.22020 0
293    2013-05 100.05030 0
294    2013-06  99.87241 0
295    2013-07  99.71181 0
296    2013-08  99.58968 0
297    2013-09  99.48809 0
298    2013-10  99.37336 0
299    2013-11  99.24930 1
300    2013-12  99.12724 1
301    2014-01  99.01431 1
302    2014-02  98.92592 1
303    2014-03  98.86857 1
304    2014-04  98.83715 1
305    2014-05  98.81997 1
306    2014-06  98.81721 1
307    2014-07  98.81522 1
308    2014-08  98.78034 1
309    2014-09  98.69115 1
310    2014-10  98.53143 1
311    2014-11  98.31426 1
312    2014-12  98.06211 1
313    2015-01  97.80693 1
314    2015-02  97.56847 1
315    2015-03  97.35264 1
316    2015-04  97.17543 1
317    2015-05  97.02750 1
318    2015-06  96.90185 1
319    2015-07  96.80600 1
320    2015-08  96.74126 1
321    2015-09  96.71504 1
322    2015-10  96.71930 1
323    2015-11  96.73604 1
324    2015-12  96.77872 1
325    2016-01  96.87116 1
326    2016-02  97.04812 1
327    2016-03  97.31297 1
328    2016-04  97.64771 1
329    2016-05  98.02731 1
330    2016-06  98.43169 1
331    2016-07  98.82601 1
332    2016-08  99.16944 1
333    2016-09  99.44402 0
334    2016-10  99.63253 0
335    2016-11  99.76746 0
336    2016-12  99.89494 0
337    2017-01 100.04950 0
338    2017-02 100.22390 0
339    2017-03 100.40570 0
340    2017-04 100.59000 0
341    2017-05 100.78670 0
342    2017-06 101.00930 0
343    2017-07 101.28520 0
344    2017-08 101.61680 0
345    2017-09 101.98400 0
346    2017-10 102.35380 0
347    2017-11 102.70540 0
348    2017-12 103.04680 0
349    2018-01 103.37380 0
350    2018-02 103.65930 0
351    2018-03 103.88830 0"
)
df2<-read.table(text=z,header=T)

根据帮助页面,对于二项式情况,y变量应为矩阵nx2,其中一列具有成功次数(衰退),另一列具有失败次数(扩展)。此外,jstat论文认为&#34;身份残差的使用允许在Wang和Li(2011)中考虑的BARMA模型适合使用glarma包。&#34;那么,为了我的拟合目的(拟合二元AR(1),x作为外生预测因子),应该这样做:

y=df2[,3] #selecting binary variable
y1<-ifelse(y==1,1,0) #1 for recessions (success)
y2<-ifelse(y==0,1,0) #1 for expansions (failure)
yy<-cbind(y1,y2) #binding both
const<-rep(1,nrow(yy)) #creating a constant
x<- df2[,2] #continuous variable

myglarma <- glarma(yy, cbind(const,x), phiLags = 1, phiInit=0, type = "Bin", 
                   method = "NR",
                   residuals = "Identity",
                   maxit = 1000, grad = 1e-6)

但是,我收到以下错误:glarma中的错误(yy,cbind(const,x),phiLags = 2,phiInit = 1,type =&#34; Bin&#34;,:Fisher Scoring无法收敛最初的估计。

我说得对吗?如何解决收敛问题?感谢所有提前。

0 个答案:

没有答案