path <- "d:/Users/thomas.daher/Desktop/cimento/dados_parte2/"
# cimento
cimento <- read_excel(paste(path, "Obras hidreletricas.xlsx", sep = ""),sheet = "cimento_51") %>%
dplyr::select(data, cimento_51_barra)
#calcário
calcario <- read_excel(paste(path, "calcario.xlsx", sep = "")) %>% dplyr::select(data,calcario)
# diesel
diesel <- read_excel(paste(path, "Obras hidreletricas.xlsx", sep = ""), sheet = "Oleo diesel") %>% dplyr::select(data,diesel)
#coque de petroleo
#coque_antigo <- read_excel("d:/Users/thomas.daher/Desktop/cimento/dados_parte2/coque de petroleo.xlsx", sheet = "dados antigos")
#coque_antigo <- coque_antigo %>% group_by(data) %>% summarise(valor = sum(valor), kg = sum(kg)) %>%mutate(valor_por_kg = valor / kg)
#coque_novo <- read_excel("d:/Users/thomas.daher/Desktop/cimento/dados_parte2/coque de petroleo.xlsx", sheet = "dados novos")
#coque_novo <- coque_novo %>% group_by(data) %>% summarise(valor = sum(`Valor FOB (US$)`), kg = sum(`Quilograma Líquido`)) %>% mutate(valor_por_kg = valor / kg)
#coque <- rbind(coque_antigo,coque_novo)
#rm(coque_antigo,coque_novo)
#producao cimento
prod_cim <- read_excel("d:/Users/thomas.daher/Desktop/cimento/dados_parte2/prod_cimento.xlsx")
prod_cim <- prod_cim %>%
pivot_longer(cols = -ano, names_to = "mes", values_to = "prod_cim") %>%
mutate(data = as.Date(paste(ano, mes, "01", sep = "-"), format = "%Y-%m-%d")) %>% dplyr::select(data, prod_cim)
# serie lubrificantes e combustiveis
combustiveis <- read_excel("d:/Users/thomas.daher/Desktop/cimento/dados_parte2/combustiveis.xlsx") %>% dplyr::select(data, combustiveis)
IPCA <- read_excel("d:/Users/thomas.daher/Desktop/cimento/dados_parte2/ipca.xlsx") %>% dplyr::select(data, IPCA_100)
## Criando dataframes e deflacionando
# Criando o data.frame
df <- merge(x = merge(x = merge(x = cimento, y = diesel, by = "data", all.x = TRUE), y = calcario, by = "data", all.x = TRUE), y = combustiveis, by = "data", all.x = TRUE)
df <- df %>%
inner_join(IPCA, by = "data")
# Defina uma função para deflação
deflacionar_serie <- function(valor_nominal, ipca) {
return((valor_nominal / ipca)*100)
}
# Aplique a função de deflação para cada série no DataFrame
df <- df %>%
mutate(
cimento_deflacionado = deflacionar_serie(cimento_51_barra, IPCA_100),
diesel_deflacionado = deflacionar_serie(diesel, IPCA_100),
calcario_deflacionado = deflacionar_serie(calcario, IPCA_100),
combustiveis_deflacionado = deflacionar_serie(combustiveis, IPCA_100)
)
df <- df %>% dplyr::select(data, cimento_deflacionado, diesel_deflacionado, calcario_deflacionado, combustiveis_deflacionado, IPCA_100)
#Teste de Raiz unitária
ts_cimento <- ts(df$cimento_deflacionado, frequency = 12)
ts_calcario <- ts(df$calcario_deflacionado, frequency = 12)
ts_diesel <- ts(df$diesel_deflacionado, frequency = 12)
ts_combustivel <- ts(df$combustiveis_deflacionado, frequency = 12)
ts_series <- ts(cbind(ts_cimento,ts_calcario,ts_diesel,ts_combustivel), start = c(1979, 12), frequency = 12)
### plotando series em nivel
ggplot(df) +
geom_line(aes(x = data, y = cimento_deflacionado, color = "cimento"), linetype = "solid", size = 1) +
geom_line(aes(x = data, y = calcario_deflacionado, color = "calcario"), linetype = "solid", size = 1) +
geom_line(aes(x = data, y = diesel_deflacionado, color = "diesel"), linetype = "solid", size = 1) +
geom_line(aes(x = data, y = combustiveis_deflacionado, color = "combustiveis"), linetype = "solid", size = 1) +
labs(title = "Séries deflacionadas de cimento, calcario, diesel e combustiveis",
x = "data",
y = "serie",
color = "Séries em nível") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
#cimento
adf.test(ts_cimento)
##
## Augmented Dickey-Fuller Test
##
## data: ts_cimento
## Dickey-Fuller = -2.819, Lag order = 7, p-value = 0.2312
## alternative hypothesis: stationary
# diff_cimento
adf.test(diff(ts_cimento))
## Warning in adf.test(diff(ts_cimento)): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff(ts_cimento)
## Dickey-Fuller = -6.4094, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
#calcario
adf.test(ts_calcario)
##
## Augmented Dickey-Fuller Test
##
## data: ts_calcario
## Dickey-Fuller = -3.6511, Lag order = 7, p-value = 0.02836
## alternative hypothesis: stationary
# diff_calcario
#adf.test(diff(ts_calcario))
#diesel
adf.test(ts_diesel)
##
## Augmented Dickey-Fuller Test
##
## data: ts_diesel
## Dickey-Fuller = -1.3595, Lag order = 7, p-value = 0.847
## alternative hypothesis: stationary
# diff_diesel
adf.test(diff(ts_diesel))
## Warning in adf.test(diff(ts_diesel)): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff(ts_diesel)
## Dickey-Fuller = -6.5866, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
#combustiveis
adf.test(ts_combustivel)
##
## Augmented Dickey-Fuller Test
##
## data: ts_combustivel
## Dickey-Fuller = -1.1255, Lag order = 7, p-value = 0.9175
## alternative hypothesis: stationary
# diff_combustiveis
adf.test(diff(ts_combustivel))
## Warning in adf.test(diff(ts_combustivel)): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff(ts_combustivel)
## Dickey-Fuller = -6.4255, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
Podemos notar que fora a série calcário que já é estacionária em nível as demais séries apresentam raiz unitária, ao calcular a primeira diferença todas se apresentam estacionárias.
#Cimento
# Plot the time series
autoplot(ts_cimento) + labs(title = "Cimento")
# Decompose the time series
decomposition <- decompose(ts_cimento)
autoplot(decomposition) + labs(title = "Decomposition cimento")
monthplot(ts_cimento, col='darkblue', col.base='red',
main='cimento médio por mês',
ylab='cimento', lty.base=2)
#Calcario
# Plot the time series
autoplot(ts_calcario) + labs(title = "Calcario")
# Decompose the time series
decomposition <- decompose(ts_calcario)
autoplot(decomposition) + labs(title = "Decomposition calcario")
monthplot(ts_calcario, col='darkblue', col.base='red',
main='calcario médio por mês',
ylab='calcario', lty.base=2)
#Diesel
# Plot the time series
autoplot(ts_diesel) + labs(title = "Diesel")
# Decompose the time series
decomposition <- decompose(ts_diesel)
autoplot(decomposition) + labs(title = "Decomposition diesel")
monthplot(ts_diesel, col='darkblue', col.base='red',
main='diesel médio por mês',
ylab='diesel', lty.base=2)
#Combustiveis
# Plot the time series
autoplot(ts_combustivel) + labs(title = "Combustiveis")
# Decompose the time series
decomposition <- decompose(ts_combustivel)
autoplot(decomposition) + labs(title = "Decomposition calcario")
monthplot(ts_combustivel, col='darkblue', col.base='red',
main='combustivel médio por mês',
ylab='combustivel', lty.base=2)
A decomposição das séries mostra indicios de temdência e sazonalidade para todas, vamos então utilizar o comando auto.sarima para ver o que ele decide com modelo para explicar as séries.
# cimento
cimento_arima <- auto.arima(ts_cimento, seasonal = TRUE)
summary(cimento_arima)
## Series: ts_cimento
## ARIMA(3,1,1)
##
## Coefficients:
## ar1 ar2 ar3 ma1
## -0.2886 0.0396 -0.3787 0.4370
## s.e. 0.0943 0.0520 0.0512 0.0969
##
## sigma^2 = 218: log likelihood = -1429.01
## AIC=2868.02 AICc=2868.19 BIC=2887.28
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.5641433 14.66025 5.699562 1.876182 5.134145 0.1892661
## ACF1
## Training set -0.009962158
adf.test(residuals(cimento_arima))
## Warning in adf.test(residuals(cimento_arima)): p-value smaller than printed
## p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals(cimento_arima)
## Dickey-Fuller = -5.6875, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
# calcario
calcario_arima <- auto.arima(ts_calcario, seasonal = TRUE)
summary(calcario_arima)
## Series: ts_calcario
## ARIMA(2,1,3)
##
## Coefficients:
## ar1 ar2 ma1 ma2 ma3
## -1.1610 -0.6201 1.0001 0.3863 -0.3790
## s.e. 0.0628 0.0727 0.0728 0.1024 0.0624
##
## sigma^2 = 30.14: log likelihood = -1084.89
## AIC=2181.78 AICc=2182.02 BIC=2204.89
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.3527988 5.442902 2.750066 0.2025024 2.778048 0.288509
## ACF1
## Training set -0.006032054
adf.test(residuals(calcario_arima))
## Warning in adf.test(residuals(calcario_arima)): p-value smaller than printed
## p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals(calcario_arima)
## Dickey-Fuller = -7.6747, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
# diesel
diesel_arima <- auto.arima(ts_diesel, seasonal = TRUE)
summary(diesel_arima)
## Series: ts_diesel
## ARIMA(2,1,1)
##
## Coefficients:
## ar1 ar2 ma1
## 0.2319 0.1662 -0.6292
## s.e. 0.3783 0.1669 0.3687
##
## sigma^2 = 259.7: log likelihood = -1459.74
## AIC=2927.48 AICc=2927.6 BIC=2942.89
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.4599975 16.02332 8.97183 -0.8323906 5.121249 0.3613955
## ACF1
## Training set 0.003041679
adf.test(residuals(diesel_arima))
## Warning in adf.test(residuals(diesel_arima)): p-value smaller than printed
## p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals(diesel_arima)
## Dickey-Fuller = -6.2925, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
# combustivel
combustivel_arima <- auto.arima(ts_combustivel, seasonal = TRUE)
summary(combustivel_arima)
## Series: ts_combustivel
## ARIMA(1,1,1)(0,0,2)[12]
##
## Coefficients:
## ar1 ma1 sma1 sma2
## -0.8488 0.6913 -0.0885 -0.1182
## s.e. 0.0996 0.1388 0.0579 0.0531
##
## sigma^2 = 112: log likelihood = -1313.11
## AIC=2636.21 AICc=2636.39 BIC=2655.47
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.6714353 10.50734 6.685125 -0.01327149 4.022656 0.2634335
## ACF1
## Training set -0.03508005
adf.test(residuals(combustivel_arima))
## Warning in adf.test(residuals(combustivel_arima)): p-value smaller than printed
## p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals(combustivel_arima)
## Dickey-Fuller = -6.3955, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
Curiosamente o auto.arima determina primeira diferença para o calcario que já é estacionário em primeiro ordem como observado pelo teste ADF.
# Function to perform breakpoint analysis for each univariate time series
perform_breakpoint_analysis <- function(ts) {
mts_object <- ts(ts, start = c(1979, 12), frequency = 12)
bp_results <- breakpoints(mts_object ~ 1)
print(paste("Resumo de quebra da serie", deparse(substitute(ts)), sep = " "))
summary(bp_results)
}
#definindo os dados
ts_cimento <- df$cimento_deflacionado
ts_calcario <- df$calcario_deflacionado
ts_diesel <- df$diesel_deflacionado
ts_combustiveis <- df$combustiveis_deflacionado
# Perform breakpoint analysis for each univariate time series
perform_breakpoint_analysis(ts_cimento)
## [1] "Resumo de quebra da serie ts_cimento"
##
## Optimal (m+1)-segment partition:
##
## Call:
## breakpoints.formula(formula = mts_object ~ 1)
##
## Breakpoints at observation number:
##
## m = 1 78
## m = 2 78 130
## m = 3 77 129 240
## m = 4 77 129 243 297
## m = 5 77 129 187 241 297
##
## Corresponding to breakdates:
##
## m = 1 1986(5)
## m = 2 1986(5) 1990(9)
## m = 3 1986(4) 1990(8) 1999(11)
## m = 4 1986(4) 1990(8) 2000(2) 2004(8)
## m = 5 1986(4) 1990(8) 1995(6) 1999(12) 2004(8)
##
## Fit:
##
## m 0 1 2 3 4 5
## RSS 1902725 672309 560909 471478 435966 422931
## BIC 4005 3653 3602 3553 3537 3539
perform_breakpoint_analysis(ts_calcario)
## [1] "Resumo de quebra da serie ts_calcario"
##
## Optimal (m+1)-segment partition:
##
## Call:
## breakpoints.formula(formula = mts_object ~ 1)
##
## Breakpoints at observation number:
##
## m = 1 87
## m = 2 87 243
## m = 3 55 107 243
## m = 4 55 107 159 251
## m = 5 55 107 159 245 297
##
## Corresponding to breakdates:
##
## m = 1 1987(2)
## m = 2 1987(2) 2000(2)
## m = 3 1984(6) 1988(10) 2000(2)
## m = 4 1984(6) 1988(10) 1993(2) 2000(10)
## m = 5 1984(6) 1988(10) 1993(2) 2000(4) 2004(8)
##
## Fit:
##
## m 0 1 2 3 4 5
## RSS 192382 67889 33951 32632 31888 31909
## BIC 3205 2853 2623 2621 2625 2637
perform_breakpoint_analysis(ts_diesel)
## [1] "Resumo de quebra da serie ts_diesel"
##
## Optimal (m+1)-segment partition:
##
## Call:
## breakpoints.formula(formula = mts_object ~ 1)
##
## Breakpoints at observation number:
##
## m = 1 83
## m = 2 83 274
## m = 3 83 186 274
## m = 4 83 135 187 274
## m = 5 83 135 187 245 297
##
## Corresponding to breakdates:
##
## m = 1 1986(10)
## m = 2 1986(10) 2002(9)
## m = 3 1986(10) 1995(5) 2002(9)
## m = 4 1986(10) 1991(2) 1995(6) 2002(9)
## m = 5 1986(10) 1991(2) 1995(6) 2000(4) 2004(8)
##
## Fit:
##
## m 0 1 2 3 4 5
## RSS 1570275 372469 285528 258728 257253 271707
## BIC 3938 3447 3366 3344 3353 3384
perform_breakpoint_analysis(ts_combustiveis)
## [1] "Resumo de quebra da serie ts_combustiveis"
##
## Optimal (m+1)-segment partition:
##
## Call:
## breakpoints.formula(formula = mts_object ~ 1)
##
## Breakpoints at observation number:
##
## m = 1 269
## m = 2 104 249
## m = 3 104 245 297
## m = 4 104 160 245 297
## m = 5 52 104 160 245 297
##
## Corresponding to breakdates:
##
## m = 1 2002(4)
## m = 2 1988(7) 2000(8)
## m = 3 1988(7) 2000(4) 2004(8)
## m = 4 1988(7) 1993(3) 2000(4) 2004(8)
## m = 5 1984(3) 1988(7) 1993(3) 2000(4) 2004(8)
##
## Fit:
##
## m 0 1 2 3 4 5
## RSS 1889848 513187 328289 212397 210464 210187
## BIC 4002 3559 3415 3275 3283 3295
bp_results <- breakpoints(ts_cimento ~ 1)
lm_break <- lm(ts_cimento ~ breakfactor(bp_results, breaks = 4))
summary(lm_break)
##
## Call:
## lm(formula = ts_cimento ~ breakfactor(bp_results, breaks = 4))
##
## Residuals:
## Min 1Q Median 3Q Max
## -115.747 -17.543 -4.751 20.972 177.026
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 19.094 4.057 4.706
## breakfactor(bp_results, breaks = 4)segment2 184.796 6.390 28.920
## breakfactor(bp_results, breaks = 4)segment3 113.922 5.251 21.694
## breakfactor(bp_results, breaks = 4)segment4 172.414 6.319 27.286
## breakfactor(bp_results, breaks = 4)segment5 135.149 6.390 21.150
## Pr(>|t|)
## (Intercept) 3.66e-06 ***
## breakfactor(bp_results, breaks = 4)segment2 < 2e-16 ***
## breakfactor(bp_results, breaks = 4)segment3 < 2e-16 ***
## breakfactor(bp_results, breaks = 4)segment4 < 2e-16 ***
## breakfactor(bp_results, breaks = 4)segment5 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 35.6 on 344 degrees of freedom
## Multiple R-squared: 0.7709, Adjusted R-squared: 0.7682
## F-statistic: 289.3 on 4 and 344 DF, p-value: < 2.2e-16
residuals_cimento <- (residuals(lm_break))
adf.test(residuals_cimento)
## Warning in adf.test(residuals_cimento): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals_cimento
## Dickey-Fuller = -5.6718, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
bp_results <- breakpoints(ts_calcario ~ 1)
lm_break <- lm(ts_calcario ~ breakfactor(bp_results, breaks = 3))
summary(lm_break)
##
## Call:
## lm(formula = ts_calcario ~ breakfactor(bp_results, breaks = 3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.987 -5.713 0.310 5.761 42.860
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 68.030 1.311 51.88
## breakfactor(bp_results, breaks = 3)segment2 27.568 1.881 14.65
## breakfactor(bp_results, breaks = 3)segment3 41.302 1.554 26.58
## breakfactor(bp_results, breaks = 3)segment4 64.476 1.616 39.89
## Pr(>|t|)
## (Intercept) <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment2 <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment3 <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment4 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.725 on 345 degrees of freedom
## Multiple R-squared: 0.8304, Adjusted R-squared: 0.8289
## F-statistic: 563 on 3 and 345 DF, p-value: < 2.2e-16
residuals_calcario <- (residuals(lm_break))
adf.test(residuals_calcario)
## Warning in adf.test(residuals_calcario): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals_calcario
## Dickey-Fuller = -4.8386, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
bp_results <- breakpoints(ts_diesel ~ 1)
lm_break <- lm(ts_diesel ~ breakfactor(bp_results, breaks = 3))
summary(lm_break)
##
## Call:
## lm(formula = ts_diesel ~ breakfactor(bp_results, breaks = 3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -71.190 -9.617 -0.494 9.720 94.383
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 272.042 3.006 90.50
## breakfactor(bp_results, breaks = 3)segment2 -137.982 4.039 -34.16
## breakfactor(bp_results, breaks = 3)segment3 -161.747 4.190 -38.60
## breakfactor(bp_results, breaks = 3)segment4 -108.752 4.363 -24.93
## Pr(>|t|)
## (Intercept) <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment2 <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment3 <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment4 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 27.38 on 345 degrees of freedom
## Multiple R-squared: 0.8352, Adjusted R-squared: 0.8338
## F-statistic: 583 on 3 and 345 DF, p-value: < 2.2e-16
residuals_diesel <- (residuals(lm_break))
adf.test(residuals_diesel)
## Warning in adf.test(residuals_diesel): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals_diesel
## Dickey-Fuller = -4.1921, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
bp_results <- breakpoints(ts_combustiveis ~ 1)
lm_break <- lm(ts_combustiveis ~ breakfactor(bp_results, breaks = 3))
summary(lm_break)
##
## Call:
## lm(formula = ts_combustiveis ~ breakfactor(bp_results, breaks = 3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -68.56 -15.77 -5.78 14.46 81.01
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 186.831 2.433 76.79
## breakfactor(bp_results, breaks = 3)segment2 -63.825 3.207 -19.90
## breakfactor(bp_results, breaks = 3)segment3 60.554 4.214 14.37
## breakfactor(bp_results, breaks = 3)segment4 132.691 4.214 31.49
## Pr(>|t|)
## (Intercept) <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment2 <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment3 <2e-16 ***
## breakfactor(bp_results, breaks = 3)segment4 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24.81 on 345 degrees of freedom
## Multiple R-squared: 0.8876, Adjusted R-squared: 0.8866
## F-statistic: 908.2 on 3 and 345 DF, p-value: < 2.2e-16
residuals_combustiveis <- (residuals(lm_break))
adf.test(residuals_combustiveis)
## Warning in adf.test(residuals_combustiveis): p-value smaller than printed
## p-value
##
## Augmented Dickey-Fuller Test
##
## data: residuals_combustiveis
## Dickey-Fuller = -4.277, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
Aplico a quebra estrutural nas séries em nível para ver on que irá diferenciar das séries fitadas.
Analisando pelo menor BIC todas as séries apontam que não há quebra estrutural.
K <- VARselect(ts_series, lag.max = 12, type = "both") # optimal lag selected by AIC
K <- K$selection[1]
K
## AIC(n)
## 12
var_model <- VAR(ts_series, p = K, type = "none")
# Summary of the VAR model
summary(var_model)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: ts_cimento, ts_calcario, ts_diesel, ts_combustivel
## Deterministic variables: none
## Sample size: 337
## Log Likelihood: -4621.813
## Roots of the characteristic polynomial:
## 1.002 0.9908 0.9838 0.9838 0.9264 0.9264 0.9253 0.9253 0.9136 0.9136 0.9022 0.9022 0.8973 0.8973 0.8912 0.8912 0.883 0.883 0.8626 0.8626 0.8591 0.8591 0.856 0.856 0.8544 0.8544 0.8499 0.8499 0.8441 0.8441 0.84 0.84 0.8392 0.8392 0.8202 0.8201 0.8201 0.8121 0.8121 0.7838 0.7838 0.7427 0.7145 0.7145 0.6572 0.6177 0.6177 0.2029
## Call:
## VAR(y = ts_series, p = K, type = "none")
##
##
## Estimation results for equation ts_cimento:
## ===========================================
## ts_cimento = ts_cimento.l1 + ts_calcario.l1 + ts_diesel.l1 + ts_combustivel.l1 + ts_cimento.l2 + ts_calcario.l2 + ts_diesel.l2 + ts_combustivel.l2 + ts_cimento.l3 + ts_calcario.l3 + ts_diesel.l3 + ts_combustivel.l3 + ts_cimento.l4 + ts_calcario.l4 + ts_diesel.l4 + ts_combustivel.l4 + ts_cimento.l5 + ts_calcario.l5 + ts_diesel.l5 + ts_combustivel.l5 + ts_cimento.l6 + ts_calcario.l6 + ts_diesel.l6 + ts_combustivel.l6 + ts_cimento.l7 + ts_calcario.l7 + ts_diesel.l7 + ts_combustivel.l7 + ts_cimento.l8 + ts_calcario.l8 + ts_diesel.l8 + ts_combustivel.l8 + ts_cimento.l9 + ts_calcario.l9 + ts_diesel.l9 + ts_combustivel.l9 + ts_cimento.l10 + ts_calcario.l10 + ts_diesel.l10 + ts_combustivel.l10 + ts_cimento.l11 + ts_calcario.l11 + ts_diesel.l11 + ts_combustivel.l11 + ts_cimento.l12 + ts_calcario.l12 + ts_diesel.l12 + ts_combustivel.l12
##
## Estimate Std. Error t value Pr(>|t|)
## ts_cimento.l1 1.41601 0.10006 14.152 < 2e-16 ***
## ts_calcario.l1 -1.11714 0.24286 -4.600 6.33e-06 ***
## ts_diesel.l1 -0.09904 0.06274 -1.579 0.11554
## ts_combustivel.l1 -0.10106 0.08992 -1.124 0.26197
## ts_cimento.l2 -0.18533 0.17107 -1.083 0.27956
## ts_calcario.l2 0.34223 0.36751 0.931 0.35252
## ts_diesel.l2 -0.04520 0.06999 -0.646 0.51886
## ts_combustivel.l2 -0.02160 0.11916 -0.181 0.85626
## ts_cimento.l3 -0.53214 0.17421 -3.055 0.00246 **
## ts_calcario.l3 0.63889 0.36835 1.734 0.08390 .
## ts_diesel.l3 0.16973 0.07367 2.304 0.02194 *
## ts_combustivel.l3 0.01737 0.12262 0.142 0.88744
## ts_cimento.l4 0.48350 0.17487 2.765 0.00606 **
## ts_calcario.l4 0.14696 0.36081 0.407 0.68408
## ts_diesel.l4 -0.01359 0.07486 -0.182 0.85604
## ts_combustivel.l4 0.10755 0.12245 0.878 0.38051
## ts_cimento.l5 -0.22474 0.17707 -1.269 0.20538
## ts_calcario.l5 -0.14584 0.35673 -0.409 0.68298
## ts_diesel.l5 -0.08814 0.07393 -1.192 0.23415
## ts_combustivel.l5 0.09324 0.12240 0.762 0.44683
## ts_cimento.l6 0.28163 0.17548 1.605 0.10960
## ts_calcario.l6 -0.04942 0.35130 -0.141 0.88823
## ts_diesel.l6 0.01108 0.07129 0.155 0.87655
## ts_combustivel.l6 -0.03750 0.12183 -0.308 0.75844
## ts_cimento.l7 -0.13851 0.17329 -0.799 0.42477
## ts_calcario.l7 0.04021 0.34969 0.115 0.90853
## ts_diesel.l7 0.01402 0.07246 0.193 0.84674
## ts_combustivel.l7 0.10498 0.12141 0.865 0.38792
## ts_cimento.l8 -0.29561 0.17172 -1.721 0.08624 .
## ts_calcario.l8 -0.03074 0.34835 -0.088 0.92974
## ts_diesel.l8 0.04605 0.07343 0.627 0.53110
## ts_combustivel.l8 -0.07430 0.12544 -0.592 0.55409
## ts_cimento.l9 0.21126 0.17049 1.239 0.21631
## ts_calcario.l9 -0.17348 0.35034 -0.495 0.62085
## ts_diesel.l9 0.01786 0.07228 0.247 0.80497
## ts_combustivel.l9 -0.11127 0.12510 -0.889 0.37450
## ts_cimento.l10 -0.17402 0.17124 -1.016 0.31037
## ts_calcario.l10 0.83274 0.35259 2.362 0.01885 *
## ts_diesel.l10 -0.08014 0.07223 -1.109 0.26818
## ts_combustivel.l10 -0.03474 0.12520 -0.277 0.78163
## ts_cimento.l11 0.27406 0.16706 1.640 0.10200
## ts_calcario.l11 -0.43490 0.34123 -1.274 0.20352
## ts_diesel.l11 -0.01046 0.06791 -0.154 0.87772
## ts_combustivel.l11 0.15999 0.12191 1.312 0.19045
## ts_cimento.l12 -0.14176 0.10103 -1.403 0.16164
## ts_calcario.l12 -0.01692 0.22335 -0.076 0.93968
## ts_diesel.l12 0.07432 0.05591 1.329 0.18478
## ts_combustivel.l12 -0.09765 0.09426 -1.036 0.30104
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 12.73 on 289 degrees of freedom
## Multiple R-Squared: 0.994, Adjusted R-squared: 0.993
## F-statistic: 1004 on 48 and 289 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation ts_calcario:
## ============================================
## ts_calcario = ts_cimento.l1 + ts_calcario.l1 + ts_diesel.l1 + ts_combustivel.l1 + ts_cimento.l2 + ts_calcario.l2 + ts_diesel.l2 + ts_combustivel.l2 + ts_cimento.l3 + ts_calcario.l3 + ts_diesel.l3 + ts_combustivel.l3 + ts_cimento.l4 + ts_calcario.l4 + ts_diesel.l4 + ts_combustivel.l4 + ts_cimento.l5 + ts_calcario.l5 + ts_diesel.l5 + ts_combustivel.l5 + ts_cimento.l6 + ts_calcario.l6 + ts_diesel.l6 + ts_combustivel.l6 + ts_cimento.l7 + ts_calcario.l7 + ts_diesel.l7 + ts_combustivel.l7 + ts_cimento.l8 + ts_calcario.l8 + ts_diesel.l8 + ts_combustivel.l8 + ts_cimento.l9 + ts_calcario.l9 + ts_diesel.l9 + ts_combustivel.l9 + ts_cimento.l10 + ts_calcario.l10 + ts_diesel.l10 + ts_combustivel.l10 + ts_cimento.l11 + ts_calcario.l11 + ts_diesel.l11 + ts_combustivel.l11 + ts_cimento.l12 + ts_calcario.l12 + ts_diesel.l12 + ts_combustivel.l12
##
## Estimate Std. Error t value Pr(>|t|)
## ts_cimento.l1 0.010558 0.042558 0.248 0.80425
## ts_calcario.l1 0.761624 0.103300 7.373 1.77e-12 ***
## ts_diesel.l1 -0.035075 0.026686 -1.314 0.18976
## ts_combustivel.l1 -0.016066 0.038246 -0.420 0.67475
## ts_cimento.l2 0.106903 0.072764 1.469 0.14288
## ts_calcario.l2 -0.039443 0.156318 -0.252 0.80097
## ts_diesel.l2 -0.040828 0.029768 -1.372 0.17127
## ts_combustivel.l2 0.017283 0.050683 0.341 0.73336
## ts_cimento.l3 -0.179830 0.074099 -2.427 0.01584 *
## ts_calcario.l3 0.239468 0.156675 1.528 0.12750
## ts_diesel.l3 0.006642 0.031336 0.212 0.83230
## ts_combustivel.l3 -0.038870 0.052155 -0.745 0.45671
## ts_cimento.l4 0.176207 0.074378 2.369 0.01849 *
## ts_calcario.l4 -0.017321 0.153467 -0.113 0.91021
## ts_diesel.l4 0.013589 0.031839 0.427 0.66983
## ts_combustivel.l4 0.050751 0.052082 0.974 0.33065
## ts_cimento.l5 -0.201685 0.075315 -2.678 0.00783 **
## ts_calcario.l5 0.084932 0.151732 0.560 0.57608
## ts_diesel.l5 -0.005666 0.031446 -0.180 0.85714
## ts_combustivel.l5 0.069103 0.052061 1.327 0.18544
## ts_cimento.l6 0.102195 0.074637 1.369 0.17199
## ts_calcario.l6 -0.056381 0.149421 -0.377 0.70620
## ts_diesel.l6 0.056021 0.030321 1.848 0.06568 .
## ts_combustivel.l6 -0.003401 0.051821 -0.066 0.94772
## ts_cimento.l7 0.030764 0.073708 0.417 0.67671
## ts_calcario.l7 -0.083354 0.148738 -0.560 0.57563
## ts_diesel.l7 0.044420 0.030818 1.441 0.15057
## ts_combustivel.l7 -0.075521 0.051641 -1.462 0.14471
## ts_cimento.l8 -0.079117 0.073040 -1.083 0.27962
## ts_calcario.l8 -0.030457 0.148167 -0.206 0.83728
## ts_diesel.l8 -0.022810 0.031232 -0.730 0.46578
## ts_combustivel.l8 0.001314 0.053355 0.025 0.98038
## ts_cimento.l9 0.095449 0.072517 1.316 0.18914
## ts_calcario.l9 0.056017 0.149013 0.376 0.70725
## ts_diesel.l9 -0.009439 0.030742 -0.307 0.75904
## ts_combustivel.l9 -0.012123 0.053209 -0.228 0.81994
## ts_cimento.l10 -0.092714 0.072834 -1.273 0.20406
## ts_calcario.l10 0.223730 0.149969 1.492 0.13683
## ts_diesel.l10 -0.014707 0.030724 -0.479 0.63252
## ts_combustivel.l10 0.006504 0.053253 0.122 0.90288
## ts_cimento.l11 0.112586 0.071058 1.584 0.11419
## ts_calcario.l11 -0.233362 0.145141 -1.608 0.10897
## ts_diesel.l11 0.020678 0.028883 0.716 0.47461
## ts_combustivel.l11 -0.008545 0.051853 -0.165 0.86923
## ts_cimento.l12 -0.085652 0.042970 -1.993 0.04717 *
## ts_calcario.l12 0.099033 0.094999 1.042 0.29807
## ts_diesel.l12 -0.014532 0.023780 -0.611 0.54161
## ts_combustivel.l12 0.012473 0.040091 0.311 0.75594
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 5.416 on 289 degrees of freedom
## Multiple R-Squared: 0.998, Adjusted R-squared: 0.9977
## F-statistic: 2985 on 48 and 289 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation ts_diesel:
## ==========================================
## ts_diesel = ts_cimento.l1 + ts_calcario.l1 + ts_diesel.l1 + ts_combustivel.l1 + ts_cimento.l2 + ts_calcario.l2 + ts_diesel.l2 + ts_combustivel.l2 + ts_cimento.l3 + ts_calcario.l3 + ts_diesel.l3 + ts_combustivel.l3 + ts_cimento.l4 + ts_calcario.l4 + ts_diesel.l4 + ts_combustivel.l4 + ts_cimento.l5 + ts_calcario.l5 + ts_diesel.l5 + ts_combustivel.l5 + ts_cimento.l6 + ts_calcario.l6 + ts_diesel.l6 + ts_combustivel.l6 + ts_cimento.l7 + ts_calcario.l7 + ts_diesel.l7 + ts_combustivel.l7 + ts_cimento.l8 + ts_calcario.l8 + ts_diesel.l8 + ts_combustivel.l8 + ts_cimento.l9 + ts_calcario.l9 + ts_diesel.l9 + ts_combustivel.l9 + ts_cimento.l10 + ts_calcario.l10 + ts_diesel.l10 + ts_combustivel.l10 + ts_cimento.l11 + ts_calcario.l11 + ts_diesel.l11 + ts_combustivel.l11 + ts_cimento.l12 + ts_calcario.l12 + ts_diesel.l12 + ts_combustivel.l12
##
## Estimate Std. Error t value Pr(>|t|)
## ts_cimento.l1 -1.875e-01 1.126e-01 -1.664 0.09711 .
## ts_calcario.l1 2.412e-01 2.734e-01 0.882 0.37826
## ts_diesel.l1 4.239e-01 7.062e-02 6.002 5.83e-09 ***
## ts_combustivel.l1 4.897e-01 1.012e-01 4.838 2.13e-06 ***
## ts_cimento.l2 -5.312e-02 1.926e-01 -0.276 0.78285
## ts_calcario.l2 1.441e-01 4.137e-01 0.348 0.72789
## ts_diesel.l2 4.262e-01 7.878e-02 5.410 1.32e-07 ***
## ts_combustivel.l2 -4.396e-01 1.341e-01 -3.278 0.00117 **
## ts_cimento.l3 -1.179e-01 1.961e-01 -0.601 0.54801
## ts_calcario.l3 -3.832e-03 4.146e-01 -0.009 0.99263
## ts_diesel.l3 -8.351e-06 8.293e-02 0.000 0.99992
## ts_combustivel.l3 8.943e-02 1.380e-01 0.648 0.51757
## ts_cimento.l4 5.831e-01 1.968e-01 2.962 0.00331 **
## ts_calcario.l4 -4.085e-01 4.061e-01 -1.006 0.31537
## ts_diesel.l4 8.250e-02 8.426e-02 0.979 0.32833
## ts_combustivel.l4 -2.009e-01 1.378e-01 -1.458 0.14601
## ts_cimento.l5 -3.100e-01 1.993e-01 -1.555 0.12103
## ts_calcario.l5 1.648e-01 4.016e-01 0.411 0.68174
## ts_diesel.l5 1.852e-02 8.322e-02 0.223 0.82407
## ts_combustivel.l5 6.291e-02 1.378e-01 0.457 0.64831
## ts_cimento.l6 -1.432e-02 1.975e-01 -0.073 0.94225
## ts_calcario.l6 6.577e-01 3.954e-01 1.663 0.09734 .
## ts_diesel.l6 -7.018e-02 8.024e-02 -0.875 0.38250
## ts_combustivel.l6 -1.253e-01 1.371e-01 -0.914 0.36156
## ts_cimento.l7 8.199e-02 1.951e-01 0.420 0.67458
## ts_calcario.l7 -6.165e-01 3.936e-01 -1.566 0.11842
## ts_diesel.l7 1.757e-01 8.156e-02 2.154 0.03206 *
## ts_combustivel.l7 3.017e-01 1.367e-01 2.208 0.02806 *
## ts_cimento.l8 -2.734e-02 1.933e-01 -0.141 0.88762
## ts_calcario.l8 -9.457e-03 3.921e-01 -0.024 0.98078
## ts_diesel.l8 -8.234e-02 8.266e-02 -0.996 0.32001
## ts_combustivel.l8 -8.568e-02 1.412e-01 -0.607 0.54445
## ts_cimento.l9 1.184e-01 1.919e-01 0.617 0.53779
## ts_calcario.l9 1.060e-01 3.944e-01 0.269 0.78831
## ts_diesel.l9 -1.555e-01 8.136e-02 -1.912 0.05688 .
## ts_combustivel.l9 -3.880e-02 1.408e-01 -0.276 0.78312
## ts_cimento.l10 -4.630e-01 1.928e-01 -2.402 0.01693 *
## ts_calcario.l10 3.122e-01 3.969e-01 0.787 0.43220
## ts_diesel.l10 1.523e-01 8.131e-02 1.873 0.06210 .
## ts_combustivel.l10 1.235e-01 1.409e-01 0.876 0.38149
## ts_cimento.l11 2.543e-01 1.881e-01 1.352 0.17729
## ts_calcario.l11 -5.824e-01 3.841e-01 -1.516 0.13054
## ts_diesel.l11 2.608e-02 7.644e-02 0.341 0.73318
## ts_combustivel.l11 -6.221e-02 1.372e-01 -0.453 0.65064
## ts_cimento.l12 9.349e-02 1.137e-01 0.822 0.41169
## ts_calcario.l12 5.175e-02 2.514e-01 0.206 0.83707
## ts_diesel.l12 -1.794e-02 6.293e-02 -0.285 0.77580
## ts_combustivel.l12 -1.057e-01 1.061e-01 -0.996 0.32011
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 14.33 on 289 degrees of freedom
## Multiple R-Squared: 0.9944, Adjusted R-squared: 0.9935
## F-statistic: 1077 on 48 and 289 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation ts_combustivel:
## ===============================================
## ts_combustivel = ts_cimento.l1 + ts_calcario.l1 + ts_diesel.l1 + ts_combustivel.l1 + ts_cimento.l2 + ts_calcario.l2 + ts_diesel.l2 + ts_combustivel.l2 + ts_cimento.l3 + ts_calcario.l3 + ts_diesel.l3 + ts_combustivel.l3 + ts_cimento.l4 + ts_calcario.l4 + ts_diesel.l4 + ts_combustivel.l4 + ts_cimento.l5 + ts_calcario.l5 + ts_diesel.l5 + ts_combustivel.l5 + ts_cimento.l6 + ts_calcario.l6 + ts_diesel.l6 + ts_combustivel.l6 + ts_cimento.l7 + ts_calcario.l7 + ts_diesel.l7 + ts_combustivel.l7 + ts_cimento.l8 + ts_calcario.l8 + ts_diesel.l8 + ts_combustivel.l8 + ts_cimento.l9 + ts_calcario.l9 + ts_diesel.l9 + ts_combustivel.l9 + ts_cimento.l10 + ts_calcario.l10 + ts_diesel.l10 + ts_combustivel.l10 + ts_cimento.l11 + ts_calcario.l11 + ts_diesel.l11 + ts_combustivel.l11 + ts_cimento.l12 + ts_calcario.l12 + ts_diesel.l12 + ts_combustivel.l12
##
## Estimate Std. Error t value Pr(>|t|)
## ts_cimento.l1 0.05620 0.08281 0.679 0.4979
## ts_calcario.l1 -0.26707 0.20100 -1.329 0.1850
## ts_diesel.l1 -0.13446 0.05192 -2.590 0.0101 *
## ts_combustivel.l1 0.93626 0.07442 12.581 <2e-16 ***
## ts_cimento.l2 -0.05011 0.14158 -0.354 0.7237
## ts_calcario.l2 0.27467 0.30416 0.903 0.3673
## ts_diesel.l2 0.06896 0.05792 1.191 0.2348
## ts_combustivel.l2 0.16154 0.09862 1.638 0.1025
## ts_cimento.l3 -0.07037 0.14418 -0.488 0.6259
## ts_calcario.l3 0.17529 0.30485 0.575 0.5657
## ts_diesel.l3 -0.02014 0.06097 -0.330 0.7414
## ts_combustivel.l3 -0.14474 0.10148 -1.426 0.1549
## ts_cimento.l4 0.15156 0.14472 1.047 0.2959
## ts_calcario.l4 -0.06274 0.29861 -0.210 0.8337
## ts_diesel.l4 0.01150 0.06195 0.186 0.8529
## ts_combustivel.l4 0.04740 0.10134 0.468 0.6403
## ts_cimento.l5 -0.22671 0.14655 -1.547 0.1230
## ts_calcario.l5 0.03874 0.29524 0.131 0.8957
## ts_diesel.l5 0.01004 0.06119 0.164 0.8697
## ts_combustivel.l5 0.06605 0.10130 0.652 0.5149
## ts_cimento.l6 0.15486 0.14523 1.066 0.2872
## ts_calcario.l6 0.02839 0.29074 0.098 0.9223
## ts_diesel.l6 0.01999 0.05900 0.339 0.7350
## ts_combustivel.l6 -0.04247 0.10083 -0.421 0.6739
## ts_cimento.l7 -0.05885 0.14342 -0.410 0.6819
## ts_calcario.l7 -0.07062 0.28941 -0.244 0.8074
## ts_diesel.l7 0.10310 0.05997 1.719 0.0866 .
## ts_combustivel.l7 -0.05604 0.10048 -0.558 0.5775
## ts_cimento.l8 0.07415 0.14212 0.522 0.6023
## ts_calcario.l8 -0.46495 0.28830 -1.613 0.1079
## ts_diesel.l8 -0.04037 0.06077 -0.664 0.5071
## ts_combustivel.l8 0.08934 0.10382 0.861 0.3902
## ts_cimento.l9 -0.07738 0.14110 -0.548 0.5838
## ts_calcario.l9 0.52713 0.28995 1.818 0.0701 .
## ts_diesel.l9 -0.07996 0.05982 -1.337 0.1824
## ts_combustivel.l9 -0.11264 0.10353 -1.088 0.2775
## ts_cimento.l10 0.09657 0.14172 0.681 0.4962
## ts_calcario.l10 -0.29735 0.29181 -1.019 0.3091
## ts_diesel.l10 0.07044 0.05978 1.178 0.2396
## ts_combustivel.l10 0.06324 0.10362 0.610 0.5421
## ts_cimento.l11 -0.06792 0.13826 -0.491 0.6236
## ts_calcario.l11 0.02261 0.28241 0.080 0.9363
## ts_diesel.l11 -0.01550 0.05620 -0.276 0.7829
## ts_combustivel.l11 0.06029 0.10089 0.598 0.5506
## ts_cimento.l12 -0.01481 0.08361 -0.177 0.8595
## ts_calcario.l12 0.17021 0.18485 0.921 0.3579
## ts_diesel.l12 -0.01433 0.04627 -0.310 0.7570
## ts_combustivel.l12 -0.06794 0.07801 -0.871 0.3845
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 10.54 on 289 degrees of freedom
## Multiple R-Squared: 0.9977, Adjusted R-squared: 0.9974
## F-statistic: 2644 on 48 and 289 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## ts_cimento ts_calcario ts_diesel ts_combustivel
## ts_cimento 162.11 56.34 78.77 64.35
## ts_calcario 56.34 29.32 33.80 29.76
## ts_diesel 78.77 33.80 205.40 78.25
## ts_combustivel 64.35 29.76 78.25 111.04
##
## Correlation matrix of residuals:
## ts_cimento ts_calcario ts_diesel ts_combustivel
## ts_cimento 1.0000 0.8172 0.4317 0.4796
## ts_calcario 0.8172 1.0000 0.4355 0.5215
## ts_diesel 0.4317 0.4355 1.0000 0.5181
## ts_combustivel 0.4796 0.5215 0.5181 1.0000
# Get residuals from the VAR model
var_residuals <- residuals(var_model)
# Perform structural change analysis on residuals
bp_results <- breakpoints(var_residuals ~ 1)
summary(bp_results)
##
## Optimal (m+1)-segment partition:
##
## Call:
## breakpoints.formula(formula = var_residuals ~ 1)
##
## Breakpoints at observation number:
##
## m = 1 267
## m = 2 217 267
## m = 3 166 217 267
## m = 4 73 166 217 267
## m = 5 55 115 166 217 267
##
## Corresponding to breakdates:
##
## m = 1
## m = 2 0.643916913946588
## m = 3 0.492581602373887 0.643916913946588
## m = 4 0.216617210682493 0.492581602373887 0.643916913946588
## m = 5 0.163204747774481 0.341246290801187 0.492581602373887 0.643916913946588
##
## m = 1 0.792284866468843
## m = 2 0.792284866468843
## m = 3 0.792284866468843
## m = 4 0.792284866468843
## m = 5 0.792284866468843
##
## Fit:
##
## m 0 1 2 3 4 5
## RSS 46849 46661 46430 46246 45997 45998
## BIC 2631 2641 2651 2662 2671 2683
# Plot dos resíduos
df_residuals <- as.data.frame(var_residuals)
df_residuals$date <- seq(as.Date("1980-01-01"), by = "month", length.out = nrow(df_residuals))
ggplot(df_residuals, aes(x = date)) +
geom_line(aes(y = ts_cimento), color = "blue", size = 0.5) +
geom_line(aes(y = ts_calcario), color = "red", size = 0.5) +
geom_line(aes(y = ts_diesel), color = "green", size = 0.5) +
geom_line(aes(y = ts_combustivel), color = "purple", size = 0.5) +
labs(title = "Residuos do VAR",
x = "Data",
y = "Valores") +
scale_color_manual(values = c("blue", "red", "green", "purple"))
## Johansen_test
residual_series <- ts(cbind(residuals_cimento
,residuals_calcario
,residuals_diesel
,residuals_combustiveis)
,start = c(1979, 12)
,frequency = 12)
# Escolha a ordem do modelo VAR usando VARselect
var_select <- VARselect(residual_series, lag.max = 12, type = "both")
lag_order_aic <- var_select$selection[1]
# Ajuste o modelo VAR com a ordem escolhida
var_model <- VAR(residual_series, p = lag_order_aic, type = "both")
# Extraia os resíduos do modelo VAR
residuos <- residuals(var_model)
# Realize o Teste de Johansen nos resíduos
johansen_test <- ca.jo(residuos, type = "trace", K = lag_order_aic)
# Imprima os resultados
summary(johansen_test)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: trace statistic , with linear trend
##
## Eigenvalues (lambda):
## [1] 0.12048025 0.10899446 0.09410827 0.08833657
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 3 | 30.61 6.50 8.18 11.65
## r <= 2 | 63.33 15.66 17.95 23.52
## r <= 1 | 101.53 28.71 31.52 37.22
## r = 0 | 144.02 45.23 48.28 55.43
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## residuals_cimento.l9 residuals_calcario.l9
## residuals_cimento.l9 1.0000000 1.000000
## residuals_calcario.l9 -0.2299607 -1.518691
## residuals_diesel.l9 -1.2506182 1.540053
## residuals_combustiveis.l9 0.3682120 4.705377
## residuals_diesel.l9 residuals_combustiveis.l9
## residuals_cimento.l9 1.0000000 1.00000000
## residuals_calcario.l9 -0.7441308 -6.97575705
## residuals_diesel.l9 0.9666042 0.01813024
## residuals_combustiveis.l9 -1.2486374 0.31641825
##
## Weights W:
## (This is the loading matrix)
##
## residuals_cimento.l9 residuals_calcario.l9
## residuals_cimento.d -0.57919209 -0.10438205
## residuals_calcario.d -0.08639064 -0.02041699
## residuals_diesel.d 0.45394699 -0.12939641
## residuals_combustiveis.d -0.04378582 -0.16604201
## residuals_diesel.l9 residuals_combustiveis.l9
## residuals_cimento.d -0.42795610 0.12290312
## residuals_calcario.d -0.04450983 0.15329905
## residuals_diesel.d -0.31452530 0.09661786
## residuals_combustiveis.d 0.19377846 0.02856311