library("foreign")
library("olsrr")
library("mctest")
library("GGally")
library('ggplot2')
importacion <- read.dta("Importaciones.dta")
head(importacion)
## OBS Importacion PBI Consumo Inversion
## 1 1 159 1493 1081 42
## 2 2 191 1755 1269 31
## 3 3 227 2021 1460 21
## 4 4 276 2319 1643 51
## 5 5 333 2698 1866 39
## 6 6 490 3234 2238 70
ggplot(data=importacion,aes(PBI,Importacion)) + geom_point() +
labs(title="Figura 01: Diagrama de Dispersiñón",x="PBI",y="Importación")
ggplot(data=importacion,aes(Consumo,Importacion)) + geom_point() +
labs(title="Figura 02: Diagrama de Dispersión",x="Consumo",y="Importación")
ggplot(data=importacion,aes(Inversion,Importacion)) + geom_point() +
labs(title="Figura 03: Diagrama de Dispersión",x="Inversion",y="Importación")
modelo_b<-lm(Importacion~PBI,data=importacion)
summary(modelo_b)
##
## Call:
## lm(formula = Importacion ~ PBI, data = importacion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -40.646 -11.996 2.491 12.301 40.143
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.586e+02 2.136e+01 -7.423 1.44e-06 ***
## PBI 1.934e-01 8.704e-03 22.218 1.88e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.8 on 16 degrees of freedom
## Multiple R-squared: 0.9686, Adjusted R-squared: 0.9666
## F-statistic: 493.7 on 1 and 16 DF, p-value: 1.879e-13
\[ y_i = -158.6 + 0.1934x_i \]
modelo<-lm(Importacion~PBI+Consumo+Inversion,data=importacion)
summary(modelo)
##
## Call:
## lm(formula = Importacion ~ PBI + Consumo + Inversion, data = importacion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.208 -18.354 -3.479 12.973 41.008
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -197.2511 41.2525 -4.782 0.000293 ***
## PBI 0.0322 0.1869 0.172 0.865650
## Consumo 0.2427 0.2854 0.851 0.409268
## Inversion 0.4142 0.3223 1.285 0.219545
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.58 on 14 degrees of freedom
## Multiple R-squared: 0.973, Adjusted R-squared: 0.9673
## F-statistic: 168.4 on 3 and 14 DF, p-value: 3.212e-11
\[ y_i = -197.2511 + 0.0322*PBI + 0.2427*Consumo + 0.4142*Inversión \]
ols_plot_resid_qq(modelo)
ols_test_normality(modelo)
## -----------------------------------------------
## Test Statistic pvalue
## -----------------------------------------------
## Shapiro-Wilk 0.9472 0.3822
## Kolmogorov-Smirnov 0.1295 0.8864
## Cramer-von Mises 1.5556 1e-04
## Anderson-Darling 0.3177 0.5098
## -----------------------------------------------
ols_test_correlation(modelo)
## [1] 0.9796756
ols_plot_resid_fit(modelo)
ols_plot_resid_hist(modelo)
ols_vif_tol(modelo)
## Variables Tolerance VIF
## 1 PBI 0.002128828 469.742135
## 2 Consumo 0.002130509 469.371343
## 3 Inversion 0.952492105 1.049877
modelo22<-lm(PBI~Consumo,data=importacion)
summary(modelo22)
##
## Call:
## lm(formula = PBI ~ Consumo, data = importacion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -48.560 -24.798 2.318 15.206 61.059
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -178.86840 30.36845 -5.89 2.28e-05 ***
## Consumo 1.52591 0.01764 86.52 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 30.24 on 16 degrees of freedom
## Multiple R-squared: 0.9979, Adjusted R-squared: 0.9977
## F-statistic: 7485 on 1 and 16 DF, p-value: < 2.2e-16
ols_coll_diag(modelo)
## Tolerance and Variance Inflation Factor
## ---------------------------------------
## Variables Tolerance VIF
## 1 PBI 0.002128828 469.742135
## 2 Consumo 0.002130509 469.371343
## 3 Inversion 0.952492105 1.049877
##
##
## Eigenvalue and Condition Index
## ------------------------------
## Eigenvalue Condition Index intercept PBI Consumo Inversion
## 1 3.828206e+00 1.000000 0.001099435 8.996646e-06 7.863753e-06 0.01021285
## 2 1.328711e-01 5.367627 0.004243486 1.095900e-04 9.077341e-05 0.94601139
## 3 3.886081e-02 9.925256 0.304450325 5.956447e-04 3.248061e-04 0.04224592
## 4 6.258059e-05 247.330562 0.690206755 9.992858e-01 9.995766e-01 0.00152984
ols_plot_resid_fit_spread(modelo)
ols_correlations(modelo)
## Correlations
## -------------------------------------------
## Variable Zero Order Partial Part
## -------------------------------------------
## PBI 0.984 0.046 0.008
## Consumo 0.985 0.222 0.037
## Inversion 0.266 0.325 0.056
## -------------------------------------------
ols_plot_obs_fit(modelo)
ols_plot_diagnostics(modelo)
ols_vif_tol(modelo)
## Variables Tolerance VIF
## 1 PBI 0.002128828 469.742135
## 2 Consumo 0.002130509 469.371343
## 3 Inversion 0.952492105 1.049877
modelo2<-lm(Importacion~PBI+Inversion,data=importacion)
summary(modelo2)
##
## Call:
## lm(formula = Importacion ~ PBI + Inversion, data = importacion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.69 -15.69 2.48 11.55 39.60
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.678e+02 2.219e+01 -7.562 1.71e-06 ***
## PBI 1.910e-01 8.748e-03 21.833 8.82e-13 ***
## Inversion 4.049e-01 3.191e-01 1.269 0.224
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.37 on 15 degrees of freedom
## Multiple R-squared: 0.9716, Adjusted R-squared: 0.9679
## F-statistic: 257 on 2 and 15 DF, p-value: 2.478e-12
modelo3<-lm(Importacion~PBI,data=importacion)
summary(modelo3)
##
## Call:
## lm(formula = Importacion ~ PBI, data = importacion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -40.646 -11.996 2.491 12.301 40.143
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.586e+02 2.136e+01 -7.423 1.44e-06 ***
## PBI 1.934e-01 8.704e-03 22.218 1.88e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.8 on 16 degrees of freedom
## Multiple R-squared: 0.9686, Adjusted R-squared: 0.9666
## F-statistic: 493.7 on 1 and 16 DF, p-value: 1.879e-13
ols_plot_diagnostics(modelo3)
importacion$log.importacion <-log(importacion$Importacion)
importacion$log.PBI <-log(importacion$PBI)
modelo4<-lm(log.importacion~log.PBI,data=importacion)
summary(modelo4)
##
## Call:
## lm(formula = log.importacion ~ log.PBI, data = importacion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.116670 -0.040118 0.005274 0.043508 0.073848
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.78151 0.39756 -14.54 1.21e-10 ***
## log.PBI 1.47452 0.05134 28.72 3.40e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.05638 on 16 degrees of freedom
## Multiple R-squared: 0.981, Adjusted R-squared: 0.9798
## F-statistic: 824.9 on 1 and 16 DF, p-value: 3.404e-15
ols_plot_diagnostics(modelo4)
\[y =\beta_0 e^{\beta_1 x_1}\] \[log(y)=log(\beta_0)+\beta_1 x_1\]
modelo5<-lm(log.importacion~PBI,data=importacion)
summary(modelo5)
##
## Call:
## lm(formula = log.importacion ~ PBI, data = importacion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.06727 -0.02479 -0.01385 0.02500 0.10534
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.157e+00 4.281e-02 97.09 <2e-16 ***
## PBI 6.204e-04 1.744e-05 35.56 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.04568 on 16 degrees of freedom
## Multiple R-squared: 0.9875, Adjusted R-squared: 0.9867
## F-statistic: 1265 on 1 and 16 DF, p-value: < 2.2e-16
\[log(y)=4.157+0.0006204 x_1\]
\[y =63.8796 e^{0.00006204 x_1}\]
ols_plot_diagnostics(modelo5)