options locale=pt_BR encoding=utf8;
ods graphics on;/* 1) Dados (vírgula decimal) */
data safra_raw;
length Safra $7;
infile datalines dsd truncover;
input Safra :$7.
Producao :commax20. Importacao :commax20. Consumo :commax20.
Exportacao :commax20. Est_Inicial :commax20. Est_Final :commax20.;
datalines;
1999/00,31640,9,1770,5,34480,
2000/01,42289,3,548,8249,
2001/02,35280,7,362,3,35594,
2002/03,47410,9,806,2,36917,
2003/04,42128,5,299,4,38110,
2004/05,35006,7,596,1,39527,
2005/06,42514,9,1011,3,40033,
2006/07,51369,9,1164,3,42839,
2007/08,58652,3,652,0,45408,
2008/09,51003,8,1181,6,46760,
2009/10,56018,1,388,9,49223,
2010/11,57406,9,764,1,50653,
2011/12,72979,5,776,1,51683,
2012/13,81505,7,893,2,52646,
2013/14,80051,7,789,2,53520,
2014/15,84672,4,315,4,56483,3,
2015/16,66530,6,3336,2,56319,
2016/17,97842,8,952,5,57547,9,
2017/18,80709,5,900,7,59048,4,
2018/19,100042,7,1596,4,61937,
2019/20,102586,4,1453,4,67021,
2020/21,87096,8,3090,715167,
2021/22,113130,4,2615,1,74534,
2022/23,131892,6,1313,2,79465,
2023/24,115697,2,1644,7,83995,
2024/25,137005,1,1700,0,90298,
;
run;
data safra;
set safra_raw;
Ano = input(substr(Safra,1,4), 4.);
run;
/* 2) Regressão robusta – MM (alta robustez a outliers em X e Y) */
proc robustreg data=safra method=MM
plots=(rdplot ddplot histogram qqplot);
model Consumo = Producao Importacao Exportacao Est_Inicial
/ diagnostics leverage itprint;
id Safra;
output out=rob_mm
r=resid_mm sr=stdres_mm weight=weight_mm
outlier=out_mm leverage=lev_mm pred=pred_mm;
run;
/* 3) Regressão robusta – M (bisquare padrão), com tuning explícito */
proc robustreg data=safra
method=M(wf=bisquare(c=4.685) scale=med)
plots=(rdplot ddplot histogram qqplot);
model Consumo = Producao Importacao Exportacao Est_Inicial
/ diagnostics leverage itprint;
id Safra;
output out=rob_m
r=resid_m sr=stdres_m weight=weight_m
outlier=out_m leverage=lev_m pred=pred_m;
run;
/* 4) (Opcional) LTS para detecção de pontos de alta alavancagem e FWLS */
proc robustreg data=safra method=LTS fwls
plots=(rdplot ddplot);
model Consumo = Producao Importacao Exportacao Est_Inicial
/ diagnostics leverage;
id Safra;
run;
ods graphics off;
Nenhum comentário:
Postar um comentário