datos <- read.xlsx(xlsxFile = '../datos.xlsx')
datos$Fecha <- as.Date(x = datos$Fecha, origin = '1899/12/30')
datos.2 <-
melt(
data = datos
, id.vars = 'Fecha'
, variable.name = 'Variable'
, value.name = 'Valor'
)
ggplot(data = datos.2, mapping = aes(x = Fecha, y = Valor)) +
facet_wrap(facets = 'Variable', ncol = 1, scales = 'free') +
geom_line() +
theme_minimal()
cor(x = datos[,2:5])
## M1 M0 REMESAS INPC
## M1 1.0000000 0.9986188 0.8808909 0.9789979
## M0 0.9986188 1.0000000 0.8892578 0.9736943
## REMESAS 0.8808909 0.8892578 1.0000000 0.8613145
## INPC 0.9789979 0.9736943 0.8613145 1.0000000
corrplot::corrplot(corr = cor(x = datos[,2:5]))
El M0 representa, en promedio, el 31.87% del M1.
¿Hubo algún cambio en la pendiente M1 a partir de la pandemia?
ggplot(data = datos, mapping = aes(x = Fecha, y = M1)) +
geom_line() +
theme_minimal()
ggplot(data = datos, mapping = aes(x = Fecha, y = log(M1))) +
geom_line() +
theme_minimal()
regresion.1 <- lm(data = datos[which(datos$Fecha < '2020/01/01'),], formula = log(M1) ~ Fecha)
summary(regresion.1)
##
## Call:
## lm(formula = log(M1) ~ Fecha, data = datos[which(datos$Fecha <
## "2020/01/01"), ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.10298 -0.03029 -0.00145 0.02874 0.11568
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.652e+01 2.166e-02 762.7 <2e-16 ***
## Fecha 3.175e-04 1.454e-06 218.4 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.04428 on 227 degrees of freedom
## Multiple R-squared: 0.9953, Adjusted R-squared: 0.9952
## F-statistic: 4.768e+04 on 1 and 227 DF, p-value: < 2.2e-16
regresion.2 <- lm(data = datos[which(datos$Fecha >= '2020/01/01'),], formula = log(M1) ~ Fecha)
summary(regresion.2)
##
## Call:
## lm(formula = log(M1) ~ Fecha, data = datos[which(datos$Fecha >=
## "2020/01/01"), ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.055600 -0.008208 0.002384 0.014476 0.038866
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.567e+01 2.974e-01 52.70 <2e-16 ***
## Fecha 3.626e-04 1.591e-05 22.78 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.02182 on 27 degrees of freedom
## Multiple R-squared: 0.9506, Adjusted R-squared: 0.9487
## F-statistic: 519.1 on 1 and 27 DF, p-value: < 2.2e-16
regresion.2$coefficients
## (Intercept) Fecha
## 1.567259e+01 3.625694e-04
beta.teorica <- summary(regresion.1)$coefficients[2, 1]
beta.est <- summary(regresion.2)$coefficients[2, 1]
beta.se <- summary(regresion.2)$coefficients[2, 2]
est.t <- (beta.est - beta.teorica)/beta.se
grados.libertad <- nrow(datos[which(datos$Fecha >= '2020/01/01'),]) - 2
prueba.t <- pt(q = abs(est.t), df = grados.libertad, lower.tail = FALSE)*2
El coeficiente de la pendiente antes de la pandemia es igual a 0.0003.
El coeficiente de la pendiente después de la pandemia es igual a 0.0004.
El valor p de la prueba t es igual a 0.00867. Parece que sí hubo un cambio, aunque menor.
ggplot(data = datos, mapping = aes(x = Fecha, y = log(M1))) +
geom_line() +
geom_smooth(data = datos[which(datos$Fecha < '2020/01/01'),],method = 'lm') +
geom_smooth(data = datos[which(datos$Fecha >= '2020/01/01'),],method = 'lm', color = 'red') +
theme_minimal()
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
¿Y la intersección?
alpha.teorica <- summary(regresion.1)$coefficients[1, 1]
alpha.est <- summary(regresion.2)$coefficients[1, 1]
alpha.se <- summary(regresion.2)$coefficients[1, 2]
alpha.est.t <- (alpha.est - alpha.teorica)/alpha.se
grados.libertad <- nrow(datos[which(datos$Fecha >= '2020/01/01'),]) - 2
alpha.prueba.t <- pt(q = abs(alpha.est.t), df = grados.libertad, lower.tail = FALSE)*2
El coeficiente de la intersección antes de la pandemia es igual a 16.5240.
El coeficiente de la intersección después de la pandemia es igual a 15.6726.
El valor p de la prueba t es igual a 0.00803. Nuevamente, los coeficientes parecen ser efectivamente diferentes, aunque la diferencia no particularmente grande.