我刚开始进行数据分析,并且我了解R的基本知识。我的公司曾经使用Eviews运行预测模型,现在他们要求我将其全部放到R上,这样我也可以运行模型(我没有Eviews或知道如何使用它!)。谁能帮帮我吗?如果您对R有任何推荐的材料,我也将不胜感激。
代码获取带有多个变量的xls文件。然后,它运行具有不同变量组合的许多模型,并将所有内容存储在一个组中(我只显示第一个模型,因为有100多个!!)。最后,它为每个模型计算MAE和RMSE。
欢迎任何帮助!非常感谢
'##########################################################
'# Modelos para PIM
'##########################################################
'Defines working path
cd " "
' Limpa workfile anterior
close pim_linked.wf1
wfcreate(wf=pim_linked,page=origin) m 1991m01 2020m12
delete *
'Lê dados da pim.xls no worksheet origem
read(s=origem,b2) pim.xls 12
' Define tabela para armazenar resultados
table tab_mom
table tab_yoy
'Linha incrementa a cada modelo
!linha = 1
' Escolher x como o numero até o mês da ultima observação da PIM
!x = @dtoo("2018:06")
'Define ultima data da amostra
%data = @otod(!x)
%dataproj = @otod(!x + 1)
''''Geral
group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) dlog(energia) _
@seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
!linha = !linha + 1
group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) _
@seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
!linha = !linha + 1
group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) _
@seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
!fim = !linha
For !i = 1 To !fim
smpl 2002m01 %data
equation eqt{!i}.ls(n) modelo_mom{!i}
smpl %dataproj %dataproj
eqt{!i}.forecast proj
y(!x + 1) = proj(!x + 1)
smpl 2002m1 %dataproj 'Amplia amostra para dessazonalizar
y.x12(mode=a,sfile="P:\Macro\X12\omegav03all\x12a\PIMeviews.txt") 'Dessazonaliza série
tab_mom(!i,1) = proj(!x + 1) 'Armazena projeção para y(!x + 1) na primeira coluna
tab_mom(!i,2) = y_sa(!x + 1) 'Armazena proj y_sa(!x + 1)
tab_mom(!i,3) = eqt{!i}.@rbar2 'Armazena R^2 ajustado na terceira coluna
tab_mom(!i,4) = eqt{!i}.@aic
tab_mom(!i,5) = eqt{!i}.@schwarz
'tab_mom(!i,6) = eqt.@dw
'Forecast one month ahear, for 12 months
For !j = 1 To 12
series pim_frcst
%ultima_data = @otod(!x - !j)
%data_previsao = @otod(!x - !j + 1)
smpl 2002m01 %ultima_data
equation eqt_f.ls(n) modelo_mom{!i}
smpl %data_previsao %data_previsao
eqt_f.forecast pim_forecast
pim_frcst(!x - !j + 1) = pim_forecast(!x - !j + 1)
Next
smpl 2002m01 %data
genr pimF_errs = pim_frcst - y
genr pimF_errs_sqrt = pimF_errs^2
tab_mom(!i,6) = @sqrt(@mean(pimF_errs_sqrt))
tab_mom(!i,7) = @mean(abs(pimF_errs))
tab_mom(!i,8) = (y_sa(!x+1)/y_sa(!x) - 1)*100 'Armazena variação percentual com ajuste sazonal na quinta coluna
下一步