d <- read.csv("PIBs.csv")
head(d)
##       MES      PIB SELIC BALANCO_COMERCIAL IPCA     PETR3    DOLAR
## 1 06/2015 149.4935 10667              4.53 0.79 14.163810 3.114658
## 2 05/2015 153.5034  9853              2.76 0.74 14.349500 3.056024
## 3 04/2015 160.2191  9518              0.49 0.71 12.566000 3.044019
## 4 03/2015 163.1275 10400              0.46 1.32  8.997727 3.148231
## 5 02/2015 144.7614  8224             -2.84 1.22  9.400556 2.818145
## 6 01/2015 147.9899  9351             -3.17 1.24  8.930952 2.635859
##   IBOVESPA    APPLE     EEFT      ALL3    VALE3    ITSA3    LAME3 DATE
## 1 53483.08 255.6127 120.4391  8.952727 40.25429 17.76667 26.11810  JUN
## 2 55807.56 257.5230 120.4860  9.863333 43.68400 18.75300 26.80700  MAI
## 3 54495.87 254.5829 115.9657  8.392381 39.13300 19.16000 26.71900  ABR
## 4 50405.28 251.9414 111.1227 10.281000 38.85364 17.99000 25.28364  MAR
## 5 50131.35 250.8626 104.0621 12.777895 42.76778 18.07667 24.10556  FEV
## 6 48369.31 221.2830 102.0165 12.131304 42.15143 17.30571 24.98571  JAN

summary(lm(PIB ~ SELIC + BALANCO_COMERCIAL + IPCA + DATE, data=d))
## 
## Call:
## lm(formula = PIB ~ SELIC + BALANCO_COMERCIAL + IPCA + DATE, data = d)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -18.2790  -5.2385   0.1907   5.8256  16.8731 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        1.791e+02  3.989e+00  44.903  < 2e-16 ***
## SELIC             -3.656e-03  2.706e-04 -13.513  < 2e-16 ***
## BALANCO_COMERCIAL -3.438e+00  5.297e-01  -6.491 1.64e-09 ***
## IPCA               9.400e+00  3.352e+00   2.804  0.00581 ** 
## DATEAGO            5.681e+00  3.655e+00   1.554  0.12252    
## DATEDEZ           -3.178e+00  3.594e+00  -0.884  0.37813    
## DATEFEV           -1.891e+01  3.572e+00  -5.292 4.99e-07 ***
## DATEJAN           -2.241e+01  3.693e+00  -6.069 1.32e-08 ***
## DATEJUL            1.593e+00  3.662e+00   0.435  0.66425    
## DATEJUN            2.036e+00  3.627e+00   0.562  0.57542    
## DATEMAI           -4.203e-01  3.593e+00  -0.117  0.90706    
## DATEMAR           -3.888e+00  3.541e+00  -1.098  0.27431    
## DATENOV           -1.033e+01  3.545e+00  -2.913  0.00422 ** 
## DATEOUT           -2.548e+00  3.540e+00  -0.720  0.47290    
## DATESET            3.347e-01  3.570e+00   0.094  0.92545    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.641 on 130 degrees of freedom
## Multiple R-squared:  0.7724, Adjusted R-squared:  0.7479 
## F-statistic: 31.51 on 14 and 130 DF,  p-value: < 2.2e-16

Modelo autoregressivo: ordem 1

d2 <- cbind(d[1:144,]$PIB, d[2:145,]$PIB) 
colnames(d2) <- c("PIB", "PIB-1")
d2 <- as.data.frame(d2)
summary(lm(PIB~., data = d2))
## 
## Call:
## lm(formula = PIB ~ ., data = d2)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -8.641 -3.442 -1.211  1.229 19.869 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.92522    3.64629   2.448   0.0156 *  
## `PIB-1`      0.93661    0.02667  35.121   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.495 on 142 degrees of freedom
## Multiple R-squared:  0.8968, Adjusted R-squared:  0.896 
## F-statistic:  1234 on 1 and 142 DF,  p-value: < 2.2e-16

Modelo autoregressivo: ordem 2

d3 <- cbind(d[1:143,]$PIB, d[2:144,]$PIB, d[3:145,]$PIB) 
colnames(d3) <- c("PIB", "PIB-1", "PIB-2")
d3 <- as.data.frame(d3)
summary(lm(PIB~., data = d3))
## 
## Call:
## lm(formula = PIB ~ ., data = d3)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -8.639 -3.440 -1.044  1.483 19.748 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.03768    3.71469   2.164   0.0322 *  
## `PIB-1`      0.79568    0.08367   9.510   <2e-16 ***
## `PIB-2`      0.14783    0.08289   1.784   0.0767 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.472 on 140 degrees of freedom
## Multiple R-squared:  0.8967, Adjusted R-squared:  0.8952 
## F-statistic: 607.7 on 2 and 140 DF,  p-value: < 2.2e-16

Modelo autoregressivo: ordem 3

d4 <- cbind(d[1:142,]$PIB, d[2:143,]$PIB, d[3:144,]$PIB, d[4:145,]$PIB) 
colnames(d4) <- c("PIB", "PIB-1", "PIB-2", "PIB-3")
d4 <- as.data.frame(d4)
summary(lm(PIB~., data = d4))
## 
## Call:
## lm(formula = PIB ~ ., data = d4)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.5014 -3.6246 -0.4552  1.7570 17.5192 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.77073    3.63381   1.863 0.064551 .  
## `PIB-1`      0.74825    0.08127   9.207 4.86e-16 ***
## `PIB-2`     -0.09814    0.10301  -0.953 0.342408    
## `PIB-3`      0.30383    0.08109   3.747 0.000262 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.25 on 138 degrees of freedom
## Multiple R-squared:  0.9041, Adjusted R-squared:  0.902 
## F-statistic: 433.6 on 3 and 138 DF,  p-value: < 2.2e-16

Modelo autoregressivo: com sazonalidade

ds <- cbind(d[1:134,]$PIB, d[2:135,]$PIB, d[3:136,]$PIB, d[4:137,]$PIB, d[12:145,]$PIB) 
colnames(ds) <- c("PIB", "PIB-1", "PIB-2", "PIB-3", "PIB-12")
ds <- as.data.frame(ds)
ms12 <- lm(PIB~., data = ds)
summary(lm(PIB~., data = ds))
## 
## Call:
## lm(formula = PIB ~ ., data = ds)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -10.4167  -2.6006  -0.3581   2.4981  17.3133 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.86276    3.58170   2.195   0.0299 *  
## `PIB-1`      0.59167    0.07791   7.594 5.51e-12 ***
## `PIB-2`     -0.11381    0.09226  -1.234   0.2196    
## `PIB-3`      0.11405    0.07766   1.469   0.1443    
## `PIB-12`     0.36273    0.05868   6.181 7.73e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.613 on 129 degrees of freedom
## Multiple R-squared:  0.9166, Adjusted R-squared:  0.9141 
## F-statistic: 354.6 on 4 and 129 DF,  p-value: < 2.2e-16

Previsão 1: Julho/2015

v1 <- ms12$coefficients
pib_jul <- (149.4935)*(0.592) + d$PIB[2]*(-0.114) + d$PIB[3]*(0.114) + d$PIB[4]*(0.363) + 7.863
## [1] 156.344

Previsão 2: Agosto/2015

pib_ago <- (pib_jul)*(0.592) + d$PIB[1]*(-0.114) + d$PIB[2]*(0.114) + d$PIB[3]*(0.363) + 7.863
## [1] 159.0353

Previsão 3: Setembro/2015

pib_set <- (pib_ago)*(0.592) + (pib_jul)*(-0.114) + d$PIB[1]*(0.114) + d$PIB[2]*(0.363) + 7.863
## [1] 156.9527