# Abriendo librerias
library(readxl)
library(sqldf)
## Loading required package: gsubfn
## Loading required package: proto
## Loading required package: RSQLite
library(moments)
library(tseries)
library(forecast)
library(ggplot2)
library(zoo)
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(lmtest)

# Asignando opciones al Script
options(digits = 2)
options(OutDec= ",")
#options(OutDec= ",")  # restore default value
sep.miles <- function(x){
  format(x,big.mark=".")}
fmt.porcen <- function(x){
  paste(format(round(x,2),decimal.mark = ","),'%')}

# Descargando la Base de Datos
BBDD <- read_excel("C:/Users/samora/OneDrive/Estudios/universidad/Desarrollo económico/Taller/BBDD.xls", 
                   sheet = "pwt71_wo_country_names_wo_g_var")
DEF <- read_excel("C:/Users/samora/OneDrive/Estudios/universidad/Desarrollo económico/Taller/BBDD.xls", 
                  sheet = "pwt70_vars")
COLDATA <- sqldf("SELECT * FROM BBDD WHERE isocode in ('COL')")
ARGDATA <- sqldf("SELECT * FROM BBDD WHERE isocode in ('ARG')")
BRADATA <- sqldf("SELECT * FROM BBDD WHERE isocode in ('BRA')")

# Sustrayendo inofmración necesaria de la Base de datos, lenguaje usado en SQL
COL <- sqldf("SELECT year, POP, rgdpch, rgdpwok, ki FROM COLDATA WHERE isocode in ('COL')")
View(sep.miles(COL)) # separando valores en miles

ARG <- sqldf("SELECT year, POP, rgdpch, rgdpwok, ki FROM ARGDATA WHERE isocode in ('ARG')")
View(sep.miles(ARG)) # separando valores en miles

BRA <- sqldf("SELECT year, POP, rgdpch, rgdpwok, ki FROM BRADATA WHERE isocode in ('BRA')")
View(sep.miles(BRA)) # separando valores en miles

# Valores faltantes en el Data COL
COL$Y <- c(COL$POP * COL$rgdpwok)
COL$Inversion <- c(COL$Y * COL$ki)
lim <- NROW(COL$ki)
COL$mean.ki <- mean(COL$ki[2:lim])
COL$K <- c(c(COL$mean.ki * COL$Y * 0.01) / 0.1)
COL$PIBperCapita <- c(COL$Y / COL$POP)
COL$L <- c(COL$Y / c(COL$rgdpch * COL$rgdpwok))
COL$A <- c(COL$Y / c((COL$K ^ 0.36) * c(COL$L ^ c(1 - 0.36))))

# Valores faltantes en el Data ARG
ARG$Y <- c(ARG$POP * ARG$rgdpwok)
ARG$Inversion <- c(ARG$Y * ARG$ki)
lim <- NROW(ARG$ki)
ARG$mean.ki <- mean(ARG$ki[2:lim])
ARG$K <- c(c(ARG$mean.ki * ARG$Y * 0.01) / 0.1)
ARG$PIBperCapita <- c(ARG$Y / ARG$POP)
ARG$L <- c(ARG$Y / c(ARG$rgdpch * ARG$rgdpwok))
ARG$A <- c(ARG$Y / c((ARG$K ^ 0.36) * c(ARG$L ^ c(1 - 0.36))))

# Valores faltantes en el Data BRA
BRA$Y <- c(BRA$POP * BRA$rgdpwok)
BRA$Inversion <- c(BRA$Y * BRA$ki)
lim <- NROW(BRA$ki)
BRA$mean.ki <- mean(BRA$ki[2:lim])
BRA$K <- c(c(BRA$mean.ki * BRA$Y * 0.01) / 0.1)
BRA$PIBperCapita <- c(BRA$Y / BRA$POP)
BRA$L <- c(BRA$Y / c(BRA$rgdpch * BRA$rgdpwok))
BRA$A <- c(BRA$Y / c((BRA$K ^ 0.36) * c(BRA$L ^ c(1 - 0.36))))

#COMPARANDO VARIABLES ENTRE PAISES
Y.PLOT <- ggplot(data = COL,
                 aes(x=COL$year, y=COL$Y, colour="PIB de COL")
                 )+geom_point()+geom_point(
                   data = ARG, aes(x=ARG$year, y=ARG$Y, colour="PIB de ARG")
                 )+geom_point(
                   data = BRA, aes(x=BRA$year, y=BRA$Y, colour="PIB de BRA")
                 )+ggtitle("Comparación de PIB de Colombia contra Argentina y Brazil"
                           )+xlab("Year")+ylab("PIB")
Y.PLOT

Inversion.PLOT <- ggplot(data = COL,
                         aes(x=COL$year, y=COL$Inversion, colour="PIB de COL")
)+geom_point()+geom_point(
  data = ARG, aes(x=ARG$year, y=ARG$Inversion, colour="PIB de ARG")
)+geom_point(
  data = BRA, aes(x=BRA$year, y=BRA$Inversion, colour="PIB de BRA")
)+ggtitle("Comparación de Inversion de Colombia contra Argentina y Brazil"
)+xlab("year")+ylab("Inversion")
Inversion.PLOT

L.PLOT <- ggplot(data = COL,
                 aes(x=COL$year, y=COL$L, colour="PIB de COL")
)+geom_point()+geom_point(
  data = ARG, aes(x=ARG$year, y=ARG$L, colour="PIB de ARG")
)+geom_point(
  data = BRA, aes(x=BRA$year, y=BRA$L, colour="PIB de BRA")
)+ggtitle("Comparación de L de Colombia contra Argentina y Brazil"
)+xlab("Year")+ylab("L")
L.PLOT

K.PLOT <- ggplot(data = COL,
                 aes(x=COL$year, y=COL$K, colour="PIB de COL")
)+geom_point()+geom_point(
  data = ARG, aes(x=ARG$year, y=ARG$K, colour="PIB de ARG")
)+geom_point(
  data = BRA, aes(x=BRA$year, y=BRA$K, colour="PIB de BRA")
)+ggtitle("Comparación de K de Colombia contra Argentina y Brazil"
)+xlab("Year")+ylab("K")
K.PLOT

# Comparando Ciclos de Inversion y K entre Brazil y Colombia
PrimeraDiff.col <- diff(COL$Inversion, 2)
PrimeraDiff.arg <- diff(ARG$Inversion, 2)
PrimeraDiff.bra <- diff(BRA$Inversion, 2)
PrimeraDiffK.col <- diff(COL$K, 2)
PrimeraDiffK.arg <- diff(ARG$K, 2)
PrimeraDiffK.bra <- diff(BRA$K, 2)
trend <- c(1:59)
Differencies.col <- data.frame(PrimeraDiff.col, trend)
Differencies.arg <- data.frame(PrimeraDiff.arg, trend)
Differencies.bra <- data.frame(PrimeraDiff.bra, trend)
DifferenciesK.col <- data.frame(PrimeraDiffK.col, trend)
DifferenciesK.arg <- data.frame(PrimeraDiffK.arg, trend)
DifferenciesK.bra <- data.frame(PrimeraDiffK.bra, trend)


Inversion.PLOT.diff <- ggplot(data = Differencies.col,
                              aes(x=Differencies.col$trend,
                                  y=Differencies.col$PrimeraDiff.col, colour="PIB de COL")
)+geom_line()+geom_line(
  data = Differencies.arg,
  aes(x=Differencies.arg$trend,
      y=Differencies.arg$PrimeraDiff.arg, colour="PIB de ARG")
)+geom_line(
  data = Differencies.bra, aes(x=Differencies.bra$trend, y=Differencies.bra$PrimeraDiff.bra, colour="PIB de BRA")
)+ggtitle("Primeras diferencias Inversion de Colombia contra Argentina y Brazil"
)+xlab("year")+ylab("Inversion")
Inversion.PLOT.diff

K.PLOT.diff <- ggplot(data = DifferenciesK.col,
                      aes(x=DifferenciesK.col$trend,
                          y=DifferenciesK.col$PrimeraDiffK.col, colour="PIB de COL")
)+geom_line()+geom_line(
  data = DifferenciesK.arg,
  aes(x=DifferenciesK.arg$trend,
      y=DifferenciesK.arg$PrimeraDiffK.arg, colour="PIB de ARG")
)+geom_line(
  data = DifferenciesK.bra, aes(x=DifferenciesK.bra$trend, y=DifferenciesK.bra$PrimeraDiffK.bra, colour="PIB de BRA")
)+ggtitle("Primeras diferencias K de Colombia contra Argentina y Brazil"
)+xlab("year")+ylab("K")
K.PLOT.diff

# Crendo metodo para hacer vectores
Vectores <- function(x,y){
  X <- data.frame(x, check.names = TRUE)
  names(X)[1] <- y
  return(X)
}

# Asignando nombres a los vectores
POP <- Vectores(COL$POP,"POP")
rgdpch <- Vectores(COL$rgdpch, "rgdpch")
rgdpwok <- Vectores(COL$rgdpwok, "rgdpwok")
ki <- Vectores(COL$ki, "ki")
year <- Vectores(COL$year, "Year")
Y <- Vectores(COL$Y, "Y")
Inversion <- Vectores(COL$Inversion, "Inversion")
K <- Vectores(COL$K, "K")
PIBprCapita <- Vectores(COL$PIBperCapita, "Pib per Capita")
L <- Vectores(COL$L, "L")
A <- Vectores(COL$A, "A")


#Analsis descreiptivo por variable, creando un metodo
Descriptivo <- function(x){
  numeroFilas <- NROW(x)
  X <- x[2:numeroFilas,]
  as.numeric(X)
  library(moments)
  medianx <- median(X)
  meanx <- mean(X)
  sdx <- sd(X)
  kurtosisx <- kurtosis(X)
  skewnessx <- skewness(X)
  minx <- min(X)
  maxx <- max(X)
  #quantilex <- quantile(x)
  Descriptivox <- data.frame(medianx,
                             meanx,
                             sdx,
                             kurtosisx,
                             skewnessx,
                             minx,maxx)
  return(Descriptivox)
}

# Aplicando metodo a variables
POP.Descriptivo <- Descriptivo(POP)
rgdpch.Descriptivo <- Descriptivo(rgdpch)
rgdpwok.Descriptivo <- Descriptivo(rgdpwok)
ki.Descriptivo <- Descriptivo(ki)
Y.Descriptivo <- Descriptivo(Y)
Inversion.Descriptivo <- Descriptivo(Inversion)
K.Descriptivo <- Descriptivo(K)
PIBprCapita.Descriptivo <- Descriptivo(PIBprCapita)
L.Descriptivo <- Descriptivo(L)
A.Descriptivo <- Descriptivo(A)


#Creando matriz con anƔlisis descriptivo
matrix.desciptivo <- rbind(sep.miles(POP.Descriptivo),
                           sep.miles(rgdpch.Descriptivo),
                           sep.miles(rgdpwok.Descriptivo),
                           sep.miles(ki.Descriptivo),
                           format(Y.Descriptivo, scientific=FALSE, big.mark="."),
                           format(Inversion.Descriptivo, scientific=FALSE, big.mark="."),
                           format(K.Descriptivo, scientific=FALSE, big.mark="."),
                           sep.miles(PIBprCapita.Descriptivo),
                           sep.miles(L.Descriptivo),
                           sep.miles(A.Descriptivo))
variables <- c("POP", "rgdpch", "rgdpwok", "ki",
               "Y", "Inversion", "K", "PIB per Capita", "L", "A")
row.names(matrix.desciptivo) <- variables
View(matrix.desciptivo)

# Aplicando descriptivo por Cuantiles
summary(COL)
##       year           POP            rgdpch        rgdpwok     
##  Min.   :1950   Min.   :11592   Min.   :2583   Min.   : 8107  
##  1st Qu.:1965   1st Qu.:18646   1st Qu.:3234   1st Qu.:11434  
##  Median :1980   Median :26631   Median :4959   Median :14555  
##  Mean   :1980   Mean   :27345   Mean   :4662   Mean   :13607  
##  3rd Qu.:1995   3rd Qu.:36532   3rd Qu.:5797   3rd Qu.:15817  
##  Max.   :2010   Max.   :44205   Max.   :7536   Max.   :16949  
##        ki             Y              Inversion           mean.ki  
##  Min.   :12,9   Min.   :9,46e+07   Min.   :1,82e+09   Min.   :19  
##  1st Qu.:17,2   1st Qu.:2,09e+08   1st Qu.:3,55e+09   1st Qu.:19  
##  Median :18,6   Median :4,51e+08   Median :7,34e+09   Median :19  
##  Mean   :19,0   Mean   :3,91e+08   Mean   :7,53e+09   Mean   :19  
##  3rd Qu.:20,3   3rd Qu.:5,24e+08   3rd Qu.:9,34e+09   3rd Qu.:19  
##  Max.   :25,0   Max.   :7,00e+08   Max.   :1,74e+10   Max.   :19  
##        K             PIBperCapita         L             A         
##  Min.   :1,79e+08   Min.   : 8107   Min.   :4,4   Min.   : 38488  
##  1st Qu.:3,96e+08   1st Qu.:11434   1st Qu.:5,4   1st Qu.: 55382  
##  Median :8,56e+08   Median :14555   Median :5,9   Median : 88107  
##  Mean   :7,43e+08   Mean   :13607   Mean   :5,8   Mean   : 78606  
##  3rd Qu.:9,94e+08   3rd Qu.:15817   3rd Qu.:6,1   3rd Qu.: 94758  
##  Max.   :1,33e+09   Max.   :16949   Max.   :6,8   Max.   :117271
# Creando Metodo para graficar Serie de Tiempo
grafico <- function(X){
  tittle <- paste("variable", names(X))
  color <- paste("",names(X),"")
  
  plot.X <- ggplot(data = COL,
                   aes(y = X,
                       x = year,
                       colour=color))+geom_line(
                         
                       )+geom_point(
                         
                       )+ggtitle(
                         tittle
                       )+xlab(
                         "Year"
                       )+ylab(
                         color)
  return(plot.X)
}

# Grafico de Serie de tiempo
POP.grafico <- grafico(POP)
rgdpch.grafico <- grafico(rgdpch)
rgdpwok.grafico <- grafico(rgdpwok)
ki.grafico <- grafico(ki)
Y.grafico <- grafico(Y)
Inversion.grafico <- grafico(Inversion)
K.grafico <- grafico(K)
PIBprCapita.grafico <- grafico(PIBprCapita)
L.grafico <- grafico(L)
A.grafico <- grafico(A)

# Creando Metodo para graficar Histograma
histograma <- function(x){
  tittle <- paste("variable", names(x))
  color <- paste("",names(x),"")
  
  plot.histo <- ggplot(data = COL,
                       aes(x),
                       colour=color
                       )+geom_freqpoly(
                         binwidth = 500
                       )+geom_histogram(
                         binwidth = 500
                       )+scale_y_sqrt(
                       )+ggtitle(
                         tittle
                       )+xlab(
                         "Year"
                       )+ylab(
                         color)
  #Plot.histox <- hist(x[2:61,])
  return(plot.histo)
}

# Finalmente el loop es
# for(var in seq_along(variables.list)) {
#   # Graficando Histogramas
#   POP$Type <- c("POP")
#   names(POP)[1] <- "Variable"
#   rgdpch$Type <- c("rgdpch")
#   names(rgdpch)[1] <- "Variable"
#   rgdpwok$Type <- c("rgdpwok")
#   names(rgdpwok)[1] <- "Variable"
#   ki$Type <- c("ki")
#   names(ki)[1] <- "Variable"
#   COLvar <- as.data.frame(rbind(POP, rgdpch, rgdpwok, ki))
#   variables.list <- unique(COLvar$Type)
#   
#   C = 1 # Contadora dentro del loop
#  var <- variables.list[C]
#  histo <- subset(COLvar, Type == var)
#  histogr <- histograma(histo$Variable)
#  print(histogr)
#  C = C + 1
#}
# Formateando valores grandes
Y <- format(Y, scientific=FALSE, big.mark=".")
K <- format(K, scientific=FALSE, big.mark=".")
Inversion <- format(Inversion, scientific=FALSE, big.mark=".")


POP.histograma <- histograma(POP)
rgdpch.histograma <- histograma(rgdpch)
rgdpwok.histograma <- histograma(rgdpwok)
ki.histograma <- histograma(ki)
Y.histograma <- histograma(Y)
Inversion.histograma <- histograma(Inversion)
K.histograma <- histograma(K)
PIBprCapita.histograma <- histograma(PIBprCapita)
L.histograma <- histograma(L)
A.histograma <- histograma(A)

# Creando metodo para graficar relaciones individuales
relacion <- function(X,Y){
  tittle <- paste("Relación entre ", names(X), "-",names(Y))
  colorUno <- paste("",names(X),"")
  colorDos <- paste("",names(Y),"")
  color <- paste(names(X),"-",names(Y))
  
  Relacion <- ggplot(data = COL,
                   aes(y = X,
                       x = Y,
                       colour=color))+geom_point(
                         
                       )+ggtitle(
                         tittle
                       )+xlab(
                         colorDos
                       )+ylab(
                         colorUno)
  
  return(Relacion)
}

# Relaciones Globales
pairs(COL)

cov(COL)
##                 year     POP  rgdpch rgdpwok       ki       Y Inversion
## year         3,2e+02 1,8e+05 2,5e+04 3,6e+04  5,2e+00 3,2e+09   6,6e+10
## POP          1,8e+05 1,0e+08 1,4e+07 2,0e+07  3,2e+03 1,8e+12   3,7e+13
## rgdpch       2,5e+04 1,4e+07 2,1e+06 3,0e+06  9,5e+02 2,6e+11   5,7e+12
## rgdpwok      3,6e+04 2,0e+07 3,0e+06 7,2e+06  9,3e+02 4,2e+11   8,9e+12
## ki           5,2e+00 3,2e+03 9,5e+02 9,3e+02  7,8e+00 9,8e+07   5,8e+09
## Y            3,2e+09 1,8e+12 2,6e+11 4,2e+11  9,8e+07 3,4e+16   7,2e+17
## Inversion    6,6e+10 3,7e+13 5,7e+12 8,9e+12  5,8e+09 7,2e+17   1,8e+19
## mean.ki      0,0e+00 0,0e+00 0,0e+00 0,0e+00  0,0e+00 0,0e+00   0,0e+00
## K            6,0e+09 3,4e+12 4,9e+11 8,0e+11  1,9e+08 6,4e+16   1,4e+18
## PIBperCapita 3,6e+04 2,0e+07 3,0e+06 7,2e+06  9,3e+02 4,2e+11   8,9e+12
## L            7,9e+00 4,4e+03 5,4e+02 8,0e+02 -5,5e-01 7,3e+07   1,2e+09
## A            3,9e+05 2,2e+08 3,2e+07 5,7e+07  1,4e+04 4,2e+12   9,2e+13
##              mean.ki       K PIBperCapita        L       A
## year               0 6,0e+09      3,6e+04  7,9e+00 3,9e+05
## POP                0 3,4e+12      2,0e+07  4,4e+03 2,2e+08
## rgdpch             0 4,9e+11      3,0e+06  5,4e+02 3,2e+07
## rgdpwok            0 8,0e+11      7,2e+06  8,0e+02 5,7e+07
## ki                 0 1,9e+08      9,3e+02 -5,5e-01 1,4e+04
## Y                  0 6,4e+16      4,2e+11  7,3e+07 4,2e+12
## Inversion          0 1,4e+18      8,9e+12  1,2e+09 9,2e+13
## mean.ki            0 0,0e+00      0,0e+00  0,0e+00 0,0e+00
## K                  0 1,2e+17      8,0e+11  1,4e+08 8,0e+12
## PIBperCapita       0 8,0e+11      7,2e+06  8,0e+02 5,7e+07
## L                  0 1,4e+08      8,0e+02  3,2e-01 8,3e+03
## A                  0 8,0e+12      5,7e+07  8,3e+03 5,4e+08
cor(COL)
## Warning in cor(COL): the standard deviation is zero
##              year  POP rgdpch rgdpwok    ki    Y Inversion mean.ki    K
## year         1,00 1,00   0,98    0,75  0,10 0,98      0,89      NA 0,98
## POP          1,00 1,00   0,98    0,73  0,12 0,97      0,89      NA 0,97
## rgdpch       0,98 0,98   1,00    0,78  0,24 0,99      0,94      NA 0,99
## rgdpwok      0,75 0,73   0,78    1,00  0,12 0,86      0,79      NA 0,86
## ki           0,10 0,12   0,24    0,12  1,00 0,19      0,49      NA 0,19
## Y            0,98 0,97   0,99    0,86  0,19 1,00      0,94      NA 1,00
## Inversion    0,89 0,89   0,94    0,79  0,49 0,94      1,00      NA 0,94
## mean.ki        NA   NA     NA      NA    NA   NA        NA       1   NA
## K            0,98 0,97   0,99    0,86  0,19 1,00      0,94      NA 1,00
## PIBperCapita 0,75 0,73   0,78    1,00  0,12 0,86      0,79      NA 0,86
## L            0,79 0,78   0,67    0,52 -0,35 0,70      0,51      NA 0,70
## A            0,94 0,93   0,97    0,91  0,22 0,99      0,94      NA 0,99
##              PIBperCapita     L    A
## year                 0,75  0,79 0,94
## POP                  0,73  0,78 0,93
## rgdpch               0,78  0,67 0,97
## rgdpwok              1,00  0,52 0,91
## ki                   0,12 -0,35 0,22
## Y                    0,86  0,70 0,99
## Inversion            0,79  0,51 0,94
## mean.ki                NA    NA   NA
## K                    0,86  0,70 0,99
## PIBperCapita         1,00  0,52 0,91
## L                    0,52  1,00 0,63
## A                    0,91  0,63 1,00
subCOL <- sqldf("SELECT Y,Inversion,K,PIBperCapita,L,A FROM COL")
pairs(subCOL)

cov(subCOL)
##                    Y Inversion       K PIBperCapita       L       A
## Y            3,4e+16   7,2e+17 6,4e+16      4,2e+11 7,3e+07 4,2e+12
## Inversion    7,2e+17   1,8e+19 1,4e+18      8,9e+12 1,2e+09 9,2e+13
## K            6,4e+16   1,4e+18 1,2e+17      8,0e+11 1,4e+08 8,0e+12
## PIBperCapita 4,2e+11   8,9e+12 8,0e+11      7,2e+06 8,0e+02 5,7e+07
## L            7,3e+07   1,2e+09 1,4e+08      8,0e+02 3,2e-01 8,3e+03
## A            4,2e+12   9,2e+13 8,0e+12      5,7e+07 8,3e+03 5,4e+08
cor(subCOL)
##                 Y Inversion    K PIBperCapita    L    A
## Y            1,00      0,94 1,00         0,86 0,70 0,99
## Inversion    0,94      1,00 0,94         0,79 0,51 0,94
## K            1,00      0,94 1,00         0,86 0,70 0,99
## PIBperCapita 0,86      0,79 0,86         1,00 0,52 0,91
## L            0,70      0,51 0,70         0,52 1,00 0,63
## A            0,99      0,94 0,99         0,91 0,63 1,00
# Aplicando relaciones a POP
relacion(POP,rgdpch)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(POP,rgdpwok)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(POP,ki)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

#Aplicandorelacionesargdpch
relacion(rgdpch,POP)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(rgdpch,rgdpwok)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(rgdpch,ki)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

#Aplicandorelacionesargdwok
relacion(rgdpwok,POP)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(rgdpwok,rgdpch)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(rgdpwok,ki)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

#Aplicandorelacionesaki
relacion(ki,POP)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(ki,rgdpch)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

relacion(ki,rgdpwok)
## Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

# Haciendo regresión
model <- lm(COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + COL$L + COL$A)
summary(model)
## Warning in summary.lm(model): essentially perfect fit: summary may be
## unreliable
## 
## Call:
## lm(formula = COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + 
##     COL$L + COL$A)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -4,56e-07 -2,39e-08  1,00e-10  2,23e-08  5,97e-07 
## 
## Coefficients:
##                   Estimate Std. Error   t value Pr(>|t|)    
## (Intercept)       4,65e-07   5,58e-07  8,30e-01    0,408    
## COL$Inversion    -2,94e-17   1,30e-17 -2,26e+00    0,028 *  
## COL$K             5,27e-01   9,95e-16  5,30e+14   <2e-16 ***
## COL$PIBperCapita -3,30e-12   3,59e-11 -9,00e-02    0,927    
## COL$L            -3,54e-08   7,36e-08 -4,80e-01    0,633    
## COL$A            -5,20e-12   1,72e-11 -3,00e-01    0,764    
## ---
## Signif. codes:  0 '***' 0,001 '**' 0,01 '*' 0,05 '.' 0,1 ' ' 1
## 
## Residual standard error: 1,1e-07 on 55 degrees of freedom
## Multiple R-squared:     1,   Adjusted R-squared:     1 
## F-statistic: 3,37e+31 on 5 and 55 DF,  p-value: <2e-16
hist(model$residuals)

#Aplicando test el LM
Durbin.Watson <- dwtest(COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + COL$L + COL$A)
Durbin.Watson
## 
##  Durbin-Watson test
## 
## data:  COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + COL$L + COL$A
## DW = 3, p-value = 0,9
## alternative hypothesis: true autocorrelation is greater than 0
Breusch.Godfrey <- bgtest(COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + COL$L + COL$A)
Breusch.Godfrey
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + COL$L + COL$A
## LM test = 10, df = 1, p-value = 8e-04
Breusch.Pagan <- bptest(COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + COL$L + COL$A)
Breusch.Pagan
## 
##  studentized Breusch-Pagan test
## 
## data:  COL$Y ~ COL$Inversion + COL$K + COL$PIBperCapita + COL$L + COL$A
## BP = 20, df = 5, p-value = 0,002
# Haciendo regresión LOG10
model.lo10 <- lm(log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + log10(COL$PIBperCapita) + log10(COL$L) + log10(COL$A))
summary(model.lo10)
## Warning in summary.lm(model.lo10): essentially perfect fit: summary may be
## unreliable
## 
## Call:
## lm(formula = log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + 
##     log10(COL$PIBperCapita) + log10(COL$L) + log10(COL$A))
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -3,16e-14 -8,70e-16  3,10e-16  1,12e-15  6,33e-15 
## 
## Coefficients: (1 not defined because of singularities)
##                          Estimate Std. Error   t value Pr(>|t|)    
## (Intercept)             -2,78e-01   3,05e-14 -9,10e+12   <2e-16 ***
## log10(COL$Inversion)     1,26e-14   1,29e-14  9,70e-01    0,334    
## log10(COL$K)             1,00e+00   2,03e-14  4,92e+13   <2e-16 ***
## log10(COL$PIBperCapita)  3,32e-14   2,10e-14  1,58e+00    0,120    
## log10(COL$L)             7,23e-14   3,35e-14  2,16e+00    0,035 *  
## log10(COL$A)                   NA         NA        NA       NA    
## ---
## Signif. codes:  0 '***' 0,001 '**' 0,01 '*' 0,05 '.' 0,1 ' ' 1
## 
## Residual standard error: 4,7e-15 on 56 degrees of freedom
## Multiple R-squared:     1,   Adjusted R-squared:     1 
## F-statistic: 4,41e+28 on 4 and 56 DF,  p-value: <2e-16
hist(model$residuals)

#Aplicando test el LM
Durbin.Watson <- dwtest(log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + log10(COL$PIBperCapita) + log10(COL$L) + log10(COL$A))
## Warning in dwtest(log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) +
## log10(COL$PIBperCapita) + : imaginary parts of eigenvalues discarded
Durbin.Watson
## 
##  Durbin-Watson test
## 
## data:  log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + log10(COL$PIBperCapita) +     log10(COL$L) + log10(COL$A)
## DW = 1, p-value = 2e-10
## alternative hypothesis: true autocorrelation is greater than 0
Breusch.Godfrey <- bgtest(log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + log10(COL$PIBperCapita) + log10(COL$L) + log10(COL$A))
Breusch.Godfrey
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + log10(COL$PIBperCapita) +     log10(COL$L) + log10(COL$A)
## LM test = 5e-04, df = 1, p-value = 1
Breusch.Pagan <- bptest(log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + log10(COL$PIBperCapita) + log10(COL$L) + log10(COL$A))
Breusch.Pagan
## 
##  studentized Breusch-Pagan test
## 
## data:  log10(COL$Y) ~ log10(COL$Inversion) + log10(COL$K) + log10(COL$PIBperCapita) +     log10(COL$L) + log10(COL$A)
## BP = 10, df = 4, p-value = 0,01