Introducción

El modelo estándar IS-LM se expresa teóricamente como

Mercado de Bienes y Servicios \[\begin{align} Y&=C+I+G \\ C&=C_0+cYd\equiv C_0+c(Y-Tx_0) \\ I&=I_0-bi \\ G&=G_0 \end{align}\]

Mercado Monetario \[\begin{align} M_d&=kY-hi\\ \frac{M_s}{P}&=M_0\\ \end{align}\]

library(ggplot2)
library(readxl)
library(corrplot)
library(dplyr)
library(fBasics)
library(ggthemes)
library(zoo)
library(xts)
library(PerformanceAnalytics)
# base <- read_excel('') Llama la base de datos ajustando la dirección de ubicación dentro de ''
# En este caso ajustado en R se ha asignado a  "base"

class(base)
## [1] "tbl_df"     "tbl"        "data.frame"
options(scipen = 999) # Amplitud de cifras
head(base)
## # A tibble: 6 x 15
##   TIME     PIB     CP      I     CG     DM    IVA     YD   TIN     M4
##   <chr>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl>  <dbl>
## 1 1999~ 1.26e7 8.19e6 2.72e6 1.62e6 1.54e8 13790. 1.25e7  22.2 2.09e9
## 2 2000~ 1.27e7 8.00e6 2.93e6 1.67e6 1.53e8 14857. 1.27e7  18.6 2.18e9
## 3 2000~ 1.30e7 8.33e6 2.78e6 1.68e6 1.61e8 15162. 1.30e7  18.2 2.27e9
## 4 2000~ 1.30e7 8.46e6 2.87e6 1.63e6 1.60e8 15755. 1.30e7  15.6 2.35e9
## 5 2000~ 1.30e7 8.80e6 2.70e6 1.65e6 1.82e8 17428. 1.30e7  14.5 2.43e9
## 6 2001~ 1.28e7 8.33e6 2.71e6 1.61e6 1.78e8 17740. 1.28e7  18.5 2.50e9
## # ... with 5 more variables: OM <dbl>, M3 <dbl>, M2 <dbl>, M1 <dbl>,
## #   IM <dbl>
tail(base)
## # A tibble: 6 x 15
##   TIME     PIB     CP      I     CG     DM    IVA     YD   TIN       M4
##   <chr>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl>    <dbl>
## 1 2017~ 1.78e7 1.17e7 3.87e6 2.12e6 1.37e9 66878. 1.77e7  6.63  1.50e10
## 2 2017~ 1.81e7 1.20e7 3.83e6 2.13e6 1.37e9 66440. 1.81e7  7.04  1.52e10
## 3 2017~ 1.79e7 1.22e7 3.82e6 2.08e6 1.36e9 79219. 1.79e7  7.2   1.56e10
## 4 2017~ 1.87e7 1.26e7 3.97e6 2.17e6 1.44e9 59479. 1.87e7  7.27  1.60e10
## 5 2018~ 1.80e7 1.20e7 3.96e6 2.14e6 1.49e9 78183. 1.79e7  7.65 NA      
## 6 2018~ 1.86e7 1.23e7 3.93e6 2.20e6 1.51e9 75472. 1.85e7  7.76 NA      
## # ... with 5 more variables: OM <dbl>, M3 <dbl>, M2 <dbl>, M1 <dbl>,
## #   IM <dbl>

Los datos son de temporalidad trimestral.

DF<-data.frame(base)
class(DF)
## [1] "data.frame"
dim(DF)
## [1] 75 15
# Expresamos como temporalidad expresado en R
DF$TIME=as.yearqtr(DF$TIME, format = "%Y/%q") #ZOO LIBRARY
ggplot(DF,aes(DF$TIME,DF$PIB))+geom_line(colour="blue")+
  geom_point(colour="#53005E",size=0.9)+xlab("")+ylab("PIB")+
  scale_x_yearqtr(format="%YQ%q", n=12)

  ggplot(DF,aes(DF$TIME,DF$CP))+
  geom_line(colour="red")+geom_point(colour="red",size=0.9)+
  xlab("")+
  ylab("CONSUMO")+
  scale_x_yearqtr(format="%YQ%q", n=12)

par(mfrow=c(1,2))       #1 FILA Y 2 COLUMNA

#PerformanceAnalytics
chart.TimeSeries(ts(DF$TIN,frequency = 4,start = c(1999,04)) , colorset= "gray",lwd=3,main="TASA DE INTERÉS",
                 auto.grid = FALSE)
chart.TimeSeries(ts(DF$I,frequency = 4,start = c(1999,04)) , colorset= "black",lwd=2,main="INVERSIÓN",
                 auto.grid = FALSE)

Statistical Analysis

#Extraer una base que solo se necesita con determinadas variables
DF1<-select(DF,-TIME,-M4,-M2,-M3,-IM,-M1,-OM)     #dplyr LIBRARY
summary(DF1)
PIB CP I CG DM IVA YD TIN
Min. :12415541 Min. : 7995268 Min. :2432988 Min. :1547155 Min. : 153402402 Min. :13790 Min. :12398595 Min. : 3.330
1st Qu.:13396525 1st Qu.: 9318216 1st Qu.:2856725 1st Qu.:1642948 1st Qu.: 278085862 1st Qu.:23674 1st Qu.:13371882 1st Qu.: 4.800
Median :14902786 Median :10250160 Median :3318115 Median :1799998 Median : 531780973 Median :35560 Median :14859079 Median : 7.320
Mean :15084761 Mean :10154762 Mean :3300427 Mean :1827434 Mean : 608659845 Mean :39075 Mean :15045686 Mean : 7.905
3rd Qu.:16500926 3rd Qu.:10880232 3rd Qu.:3748781 3rd Qu.:2005425 3rd Qu.: 814657471 3rd Qu.:51547 3rd Qu.:16454338 3rd Qu.: 8.925
Max. :18749848 Max. :12636577 Max. :4085839 Max. :2196413 Max. :1509249826 Max. :79219 Max. :18690369 Max. :22.230
basicStats(DF1[1:3])  #fBasics LIBRARY, se puede selecionar toda la base
PIB CP I
nobs 75.000000 75.000000 75.000000
NAs 0.000000 0.000000 0.000000
Minimum 12415541.463000 7995267.801000 2432987.678000
Maximum 18749848.412000 12636577.498000 4085838.942000
  1. Quartile
13396524.753500 9318215.766000 2856724.551500
  1. Quartile
16500925.911000 10880232.472000 3748781.486000
Mean 15084761.109213 10154761.693560 3300426.726720
Median 14902786.214000 10250159.968000 3318114.841000
Sum 1131357083.191000 761607127.017000 247532004.504000
SE Mean 206508.605605 131645.174248 56495.304511
LCL Mean 14673283.730417 9892452.957940 3187857.375208
UCL Mean 15496238.488010 10417070.429180 3412996.078232
Variance 3198435314161.397949 1299783892708.273682 239378957387.024353
Stdev 1788416.985538 1140080.651844 489263.689013
Skewness 0.355996 0.131416 -0.167283
Kurtosis -1.052709 -0.771682 -1.339334
#Matriz de Correlación
cor(DF1))
PIB CP I CG DM IVA YD TIN
PIB 1.0000000 0.9809248 0.9494466 0.9583324 0.9648774 0.9619104 0.9999963 -0.6616713
CP 0.9809248 1.0000000 0.9266542 0.8991789 0.9317317 0.9423240 0.9809334 -0.6992078
I 0.9494466 0.9266542 1.0000000 0.9175917 0.8779309 0.9130625 0.9494453 -0.6708750
CG 0.9583324 0.8991789 0.9175917 1.0000000 0.9563233 0.9382772 0.9581663 -0.6072101
DM 0.9648774 0.9317317 0.8779309 0.9563233 1.0000000 0.9708156 0.9644518 -0.5950504
IVA 0.9619104 0.9423240 0.9130625 0.9382772 0.9708156 1.0000000 0.9611681 -0.6674077
YD 0.9999963 0.9809334 0.9494453 0.9581663 0.9644518 0.9611681 1.0000000 -0.6613630
TIN -0.6616713 -0.6992078 -0.6708750 -0.6072101 -0.5950504 -0.6674077 -0.6613630 1.0000000
corrplot(cor(DF1))

Econometric Model

Consumption Estimation

\[C=C_0+c(Y-T)\equiv C=C_0+cY\]

Como ajuste de estimación

\[\widehat{CP}=\widehat{\beta_0}+\widehat{\beta_1} YD+\xi\]

Conociendo mediante MCO

\[\beta=(YD^T YD)^{-1}YD^T CP\]

# Extructura de matriz
YD.M <- as.matrix(cbind(1,DF$YD))
CP.M <- as.matrix(DF$CP)
#Como:  solve(t(YD.M)%*%YD.M)%*%t(YD.M)%*%CP.M indica: sistema es computacionalmente singular: número de condición recíproco = 5.88086e-17

beta <- solve(t(YD.M)%*%YD.M,tol=5.88086e-17)%*%t(YD.M)%*%CP.M
beta                                                  #Parametros de estimacion
##              [,1]
## [1,] 656871.89054
## [2,]      0.63127
REG.C = lm(DF$CP ~ DF$YD, data=DF)
summary(REG.C)
## 
## Call:
## lm(formula = DF$CP ~ DF$YD, data = DF)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -685149 -118608   -1718  138445  401428 
## 
## Coefficients:
##                 Estimate   Std. Error t value             Pr(>|t|)    
## (Intercept) 656871.89054 221741.85484   2.962              0.00412 ** 
## DF$YD            0.63127      0.01464  43.125 < 0.0000000000000002 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 223100 on 73 degrees of freedom
## Multiple R-squared:  0.9622, Adjusted R-squared:  0.9617 
## F-statistic:  1860 on 1 and 73 DF,  p-value: < 0.00000000000000022
# Respecto los parametros

REG.C$coefficients[1]
## (Intercept) 
##    656871.9
REG.C$coefficients[2]
##   DF$YD 
## 0.63127

Invesment Estimation

REG.INV = lm(DF$I ~ DF$TIN, data=DF)
summary(REG.INV)
## 
## Call:
## lm(formula = DF$I ~ DF$TIN, data = DF)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -884948 -145503   -7866  262379  636342 
## 
## Coefficients:
##             Estimate Std. Error t value             Pr(>|t|)    
## (Intercept)  3915028      90010  43.496 < 0.0000000000000002 ***
## DF$TIN        -77746      10058  -7.729      0.0000000000453 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 365300 on 73 degrees of freedom
## Multiple R-squared:  0.4501, Adjusted R-squared:  0.4425 
## F-statistic: 59.74 on 1 and 73 DF,  p-value: 0.00000000004534

Money Demand Estimation

REG.DM = lm(DF$DM ~ DF$PIB+DF$TIN - 1, data=DF)
summary(REG.DM)
## 
## Call:
## lm(formula = DF$DM ~ DF$PIB + DF$TIN - 1, data = DF)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -336300410 -169215579  -82240193  108974542  667646382 
## 
## Coefficients:
##             Estimate    Std. Error t value             Pr(>|t|)    
## DF$PIB        64.497         3.329  19.376 < 0.0000000000000002 ***
## DF$TIN -44044584.593   5649862.998  -7.796      0.0000000000341 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 236800000 on 73 degrees of freedom
## Multiple R-squared:  0.895,  Adjusted R-squared:  0.8922 
## F-statistic: 311.2 on 2 and 73 DF,  p-value: < 0.00000000000000022

Mathematical Adjustment

Numéricamente las ecuaciones se estructuran como \[\begin{align} Y&=C+I+G_0\\ C&=656\,\, 871.891+0.631(Y-Tx)\\ I&=3 \,\,915 \,\,027.957-77 \,\,746.449 \,i\\ G_0&=1\,\,827\,\,433.512\\ Tx_0&=39\,\,074.621\\ Md&=64.497\,Y-44\,\,044\,\,584.593\,i\\ M_0&=608\,\,659\,\,845.209 \end{align}\]

Por lo que: \[\begin{align} Y-C-I&=G_0\\ cY-C&=cTx-C_0\\ I+bi&=I_0\\ kY+hi&=M_0 \end{align}\]

De acuerdo a una estructura matricial

\[\begin{equation} \left[ \begin{array}{crrr} 1&-1&-1&0\\ c&-1&0&0\\ 0&0&1&b\\ k&0&0&-h\\ \end{array}\right] \left[\begin{array}{c} Y\\ C\\ I\\ i \\ \end{array} \right] = \left[\begin{array}{c} G_0\\ cTx-C_0\\ I_0\\ M_0\\\end{array}\right] \equiv {\bf{\Omega\Gamma=A}} \end{equation}\]

Resolviendo para \(\bf{\Gamma}\)

\[\bf{\Gamma=\Omega^{-1}A}\]

Conforme los cálculos necesarios de \(\bf{\Omega}\). El determinante:

\[|{\bf{\Omega}}| = h-ch + bk\]

El cofactor de \({\bf{\Omega}}\) es:

\[\begin{equation} \text{Cof} ({\bf{\Omega}})= \left[ \begin{array}{cccc} h & -h & h & b \\ ch & -h-b k & ch & cb \\ -b k & b k & h-ch & b-cb \\ k & -k & k & c-1 \\ \end{array} \right] \end{equation}\]

Así:

\[\begin{equation} {\bf{\Omega^{-1}}}= \left[ \begin{array}{cccc} \displaystyle\frac{h}{h-ch+bk} & \displaystyle-\frac{h}{h-ch+bk} &\displaystyle \frac{h}{h-ch+bk} & \displaystyle\frac{b}{h-ch+bk} \\ \displaystyle\frac{c h}{h-ch+bk} & \displaystyle\frac{-h-b k}{h-ch+bk} & \displaystyle\frac{c h}{h-ch+bk} & \displaystyle\frac{c b}{h-ch+bk} \\ \displaystyle -\frac{b k}{h-ch+bk} & \displaystyle\frac{b k}{h-ch+bk} & \displaystyle\frac{h-c h}{h-ch+bk} & \displaystyle\frac{b-c b}{h-ch+bk} \\ \displaystyle \frac{k}{h-ch+bk} & \displaystyle-\frac{k}{h-ch+bk} & \displaystyle\frac{k}{h-ch+bk} & \displaystyle\frac{c-1}{h-ch+bk} \\ \end{array} \right] \end{equation}\]

Los resultado de comportamiento general se vinculan en los equilibrios como:

\[\begin{align} Y^*&=\frac{h}{h-ch+bk}G_0-\frac{h}{h-ch+bk}(cTx-C_0)+\frac{h}{h-ch+bk} I_0+\frac{b}{h-ch+bk}M_0\\ C^*&=\frac{c h}{h-ch+bk} G_0+\frac{-h-b k}{h-ch+bk} (cTx-C_0)+\frac{c h}{h-ch+bk} I_0+\frac{c b}{h-ch+bk} M_0\\ I^*&=-\frac{b k}{h-ch+bk} G_0+\frac{b k}{h-ch+bk} (cTx-C_0)+\frac{h-c h}{h-ch+bk} I_0 +\frac{b-c b}{h-ch+bk} M_0\\ i^*&=\frac{k}{h-ch+bk} G_0 -\frac{k}{h-ch+bk} (cTx-C_0) +\frac{k}{h-ch+bk} I_0 +\frac{c-1}{h-ch+bk} M_0 \end{align}\]

La función de demanda agregada es:
\[\begin{align} Y=DA\therefore DA=(C_0-cTx+I_0+G_0-b\,i^*)+[1-(1-c)]Y \end{align}\]

En la función IS, \(Y\) tiene una relación inversa en \(i\), es decir:

\[\begin{equation} Y=\left(1-c\right)^{-1}(C_0-cTx+I_0+G_0-b\,i)\equiv Y=\Theta_0-\Theta_1\,i \end{equation}\]

En la función LM, \(Y\) tiene una relación directa en \(i\), es decir:

\[\begin{equation} Y=(k)^{-1}(M_0+h\,i)\equiv Y=\Pi_0+\Pi_1\,i \end{equation}\]

# Se ajustan los valores
Co=lm(DF$CP ~ DF$YD, data=DF)$coefficients[1]
c=lm(DF$CP ~ DF$YD, data=DF)$coefficients[2]
Io=lm(DF$I ~ DF$TIN, data=DF)$coefficients[1]
b=-(lm(DF$I ~ DF$TIN, data=DF)$coefficients[2])
k=lm(DF$DM ~ DF$PIB+DF$TIN - 1, data=DF)$coefficients[1]
h=-(lm(DF$DM ~ DF$PIB+DF$TIN - 1, data=DF)$coefficients[2])
g=mean(DF$CG)
tx=mean(DF$IVA)
mo=mean(DF$DM)
# Incorporación de la matriz y el vector

# Arreglo inicial
value.omega=c(1,-1,-1,0,c,-1,0,0,0,0,1,b,k,0,0,-h)
value.a=c(g,c*tx-Co,Io,mo)

# Arreglo final
omega <- t(matrix(value.omega,4,4))
a<-matrix(value.a,4,1)
gamma<-inv(omega)%*%a   #Gamma=Inversa(Omega)*A
gamma
##                [,1]
## [1,] 15435968.51685
## [2,] 10376468.37729
## [3,]  3232066.62716
## [4,]        8.78447
Ingreso_Equilibrio=gamma[1]
Consumo_Equilibrio=gamma[2]
Inversion_Equilibrio=gamma[3]
Tasa_Equilibrio=gamma[4]
### Definimos la función consumo
consumo.f=function(Yd){
    Co + c*Yd
}
ggplot(data.frame(Yd = c(-1000, 10000)), aes(x = Yd)) +
        stat_function(fun = consumo.f)+ylab('Consumo')

# Mediante la base directa
ggplot(DF, aes(DF$YD, DF$CP)) +
  geom_point() + geom_smooth(method='lm',col="red") + ggtitle('Función Consumo') + 
  ylab('Consumo')+xlab('Ingreso Disponible')

### Definimos la función Inversión

inversion.f=function(i){
    lm(DF$I ~ DF$TIN, data=DF)$coefficients[1]-(-(lm(DF$I ~ DF$TIN, data=DF)$coefficients[2]))*i   # I=Io-b*i 
}

# Graficamos

ggplot(data.frame(i = c(0, 15)), aes(x = i)) +
    stat_function(fun = inversion.f,color="red",size=0.8)+
          ylab('Inversión') + 
        geom_segment(aes(x = 0, y = gamma[3], xend = gamma[4], yend =gamma[3]),linetype="dotted",   #Nivel I
                size=0.65) +
        geom_segment(aes(x = gamma[4], y = 0, xend = gamma[4], yend = gamma[3]),linetype="dotted",  #Nivel i
                size=0.65) +
        annotate("text", x=gamma[4]+0.55, y=gamma[3]+129990, label="Equilibrio",size=2.8)+          #Equilibrio
        annotate("text", x=0.6, y=gamma[3]+90000, label="3232066.63",size=2.3)  +                   #I*
        annotate("text", x=gamma[4]+0.28, y=60000, label="8.78",size=1.8)  +                        #i*
        labs(title="Función Inversión")+
        geom_point(aes(x=gamma[4], y=gamma[3]), colour="blue")

### Definimos la función DM= k*Y-h*i
demandaM.f=function(i){
    (lm(DF$DM ~ DF$PIB+DF$TIN - 1, data=DF)$coefficients[1])*gamma[1]-  
    (-lm(DF$DM ~ DF$PIB+DF$TIN - 1, data=DF)$coefficients[2])*i
}                                                                      

ggplot(data.frame(i = c(-0.5,23)), aes(x = i)) +
      stat_function(fun = demandaM.f,size=0.8,color="blue")+
        ylab('Demanda monetaria')+
        geom_segment(aes(x = 0, y = mean(DF$DM), xend = gamma[4], yend =mean(DF$DM)),linetype="dotted",  #Nivel DM
                size=0.65) +
        geom_segment(aes(x = gamma[4], y = 0, xend = gamma[4], yend = mean(DF$DM)),linetype="dotted",  #Nivel i
                size=0.65) +
        annotate("text", x=gamma[4]+1, y=mean(DF$DM)+mean(DF$DM)/25, label="Equilibrio",size=2.8)+    #Equilibrio
        annotate("text", x=1.4,y=mean(DF$DM)+mean(DF$DM)/18,label='608659845.209',size=2.3)  +        #DM*
        annotate("text", x=gamma[4]+0.5, y=10000000,label="8.78",size=1.8) +                          #i*
        labs(title="Demanda Monetaria")+
        geom_point(aes(x=gamma[4], y=mean(DF$DM)), colour="red")

La función de demanda agregaga se establece que: \(DA=Y\), por lo que:

\[DA=(C_0-cTx+I_0+G_0-b\,i^*)+[1-(1-c)]Y\]

es decir \(DA(Y)\) y como \(OA=DA\), se ajusta la denominada linea de 45° que representa la \(OA\).

### Se definine las funciones DEMANDA Y OFERTA AGREGADA

demanda.f <- function(Y) {
    (Co-c*tx+Io+g-b*gamma[4])+(1-(1-c))*Y
}


oferta.f <- function(Y) {
    Y
}

# Se grafica

ggplot(data.frame(Y = c(10, gamma[1]+gamma[1]/3)), aes(x = Y))+
    stat_function(fun=demanda.f,geom="line",size=0.8,aes(colour = "Demanda Agregada"))+
    stat_function(fun=oferta.f,geom="line",size=0.8,aes(colour = "Oferta Agregada"))+
        ylab("Demanda y Oferta Agregada")+
        geom_segment(aes(x = 0, y = gamma[1], xend = gamma[1],                  #line DM/OM*
                         yend = gamma[1]),linetype="dotted",size=0.65) +
        geom_segment(aes(x = gamma[1], y = 0, xend = gamma[1],                  # line Y*
                         yend = gamma[1]),linetype="dotted",size=0.65) +
        annotate("text", x=gamma[1]+gamma[1]/15, y=gamma[1]-gamma[1]/60, label="Equilibrio",size=2.8)+  # equilibrio
        annotate("text", x=1000000, y=gamma[1]+gamma[1]/29, label="15435968.517",size=2.3)  +           # Text DA-OA
        annotate("text", x=gamma[1]+gamma[1]/14, y=400000, label="15435968.517",size=2.3)     +         # Text Y
        labs(title = "Equilibiro DA/OA")+
        geom_point(aes(x=gamma[1], y=gamma[1]), colour="red")+
        scale_colour_manual('',values = c("purple", "orange"))+
        theme(legend.position = c(0.9,0.4),legend.background=element_rect(fill = NA),
              legend.key = element_rect(fill = NA, color = NA))

Para el gráfico de Equilibrio del Mercado Monetario, la función de Demanda se conoce que

\[M_d=kY-hi\]

como la representación gráfica es tal que \(i(Moneda)\), entonces:

\[i=\frac{kY}{h}-\frac{1}{h}M_d\]

por lo que \(DM=OM\).

# Mercado Monetario: Equilibrio

DEMANDAm.f <- function(Moneda) {
    (k*gamma[1])/h-Moneda/h           #Como Moneda=k*Y-h*i : i=(k*Y)/h-Moneda/h
}


ggplot(data.frame(Moneda = c(0, 1000000000)), aes(x = Moneda)) +
        stat_function(fun = DEMANDAm.f,size=0.8,aes(colour='Demanda Monetaria'))+
            ylab('i') +
            geom_segment(aes(x = 0, y = gamma[4], xend =mean(DF$DM),                                      # i*
                             yend = gamma[4]),linetype="dotted",size=0.65) + 
            geom_vline(xintercept = mean(DF$DM),color = "aquamarine2", size=0.8) + 
            annotate("text", x=mean(DF$DM)+mean(DF$DM)/12, y=gamma[4]+0.3, label="Equilibrio",size=2.8) + # Equilibrio
            annotate("text", x=20000000, y=gamma[4]+0.5, label="8.78",size=2.3) +                         #text i* 
            annotate("text", x=mean(DF$DM)+mean(DF$DM)/7, y=0.3, label="Oferta Monetaria = 608659845.209",size=2.3) +       #texto DM*
            labs(title = "Mercado Monetario: Equilibrio")+
            geom_point(aes(x=mean(DF$DM), y=gamma[4]), colour="red")+
            scale_colour_manual('',values = c("coral4"))+
            theme(legend.position = c(0.9,0.4),legend.background=element_rect(fill = NA),
                  legend.key = element_rect(fill = NA, color = NA))

Como la función simplificada de la IS es

\[\begin{equation} Y=\Theta_0-\Theta_1\,i \end{equation}\]

y la función LM

\[\begin{equation} Y=\Pi_0+\Pi_1\,i \end{equation}\]

La representación gráfica del modelo se expresa tal que \(i(Y)\), por lo tanto:

\[\begin{align} i_{IS}&=\frac{\Theta_0}{\Theta_1}-\frac{1}{\Theta_1}Y\\ i_{LM}&=\frac{\Pi_0}{\Pi_1}+\frac{1}{\Pi_1}Y \end{align}\]

IS.f <- function(Y) {
                     (Co-c*tx+Io+mean(DF$CG))/b-((1-c)/b)*Y
}


LM.f <- function(Y) {
                     (-mean(DF$DM))/h+(k/h)*Y
}
IS_LM.plot <- ggplot(data.frame(Y = c(0, 21000000)), aes(x = Y)) +
    stat_function(fun = IS.f,size=0.8,aes(color="IS"))+                             # Función IS
    stat_function(fun = LM.f,size=0.8,aes(color="LM"))+                     # Función LM
        ylab("Nivel de Interés")+xlab("Nivel de ingreso")+ 
        geom_segment(aes(x = gamma[1], y = 0, xend = gamma[1],                        #linea  Y*
                         yend = gamma[4]),linetype="dotted",size=0.65)+
        geom_segment(aes(x = 0, y = gamma[4], xend =gamma[1],                         #linea i*
                             yend = gamma[4]),linetype="dotted",size=0.65) +
        annotate("text", x=400000, y=gamma[4]+2, label="8.78",size=2.3) +             #Text i*
        annotate("text", x=gamma[1], y=-1, label="15435968.517",size=2.3) +           #Text Y*
        annotate("text", x=gamma[1]+gamma[1]/13, y=gamma[4]-0.7, label="Equilibrio",  #Equilibrio
                 size=2.8) + 
        geom_point(aes(x=gamma[1], y=gamma[4]), colour="red") +
        labs(title="Equilibrio IS-LM") +
        theme(plot.title = element_text(hjust=0.5))+
        scale_colour_manual('',values = c("darkgreen", "salmon2"))+
        theme(legend.position = c(0.9,0.6),legend.background=element_rect(fill = NA),
              legend.key = element_rect(fill = NA, color = NA))

IS_LM.plot

Extensión

ggplot(data = DF, aes(DF$CP, DF$YD)) + 
  geom_point(size=0.8,alpha=0.5) + 
  geom_smooth(method = 'lm', aes(colour="A"),se=F,size=0.58) + 
  geom_smooth(method = 'loess', aes(colour="B"),se=F,size=0.58) +
  scale_colour_manual(name="", values=c("lightcoral", "cyan3"),labels = c("OLS", "LOESS"))+
  labs(title='OLS vs LOESS Consumption Function Estimation')+
  xlab('Ingreso Disponible')+
  ylab('Consumo')

# Create a new theme
theme_bluewhite <- function (base_size = 11, base_family = "") {
    theme_bw() %+replace% 
    theme(
      panel.grid.major  = element_line(color = "white"),
      panel.background = element_rect(fill = "honeydew1"),
      panel.border = element_rect(color = "honeydew1", fill = NA),
      axis.line = element_line(color = "honeydew1"),
      axis.ticks = element_line(color = "honeydew1"),
      axis.text = element_text(color = "lightblue4")
      )
}
OLS <- lm(DF$CP ~ DF$TIME, data = DF)
CP.OLS <- transform(DF$CP, Fitted = fitted(OLS))

UNDER_OVER.OLS <-ggplot(CP.OLS, aes(DF$TIME, DF$CP)) + 
              geom_point(color="cyan3",size=0.8) + 
              geom_smooth(method = "lm",size=0.5,colour="black",se=F) +
              geom_segment(aes(x = DF$TIME, y = DF$CP,xend = DF$TIME, yend = Fitted),colour="lightcoral")+
              scale_x_yearqtr(format="%YQ%q", n=12)+
              xlab("Tiempo")+
              ylab("Consumo")+
              labs(title="Underestimation and Overestimation via OLS Consumption")+
              theme_bluewhite()

UNDER_OVER.OLS

ggplot(data = DF, aes(DF$TIME, DF$CP)) + 
  geom_point(size=0.8,alpha=0.7)  + 
  geom_smooth(method = 'loess',se=T,size=0.6) +
  labs(title='LOESS Consumption Time Estimation')+
  xlab('Tiempo')+
  ylab('Consumo')+
  scale_x_yearqtr(format="%YQ%q", n=12)+
  theme_economist() + scale_fill_economist()+
  theme(plot.title = element_text(hjust=0.5))

Referencias.

Comentario.

Este proyecto fue implementado inicialmente en Eviews y Wolfram M, por lo que se realizó prueba de cambio estructural para encontrar la estimación óptima, método que no se mostró aquí por razones de expansión dado que no se estructuró como series de tiempo. Como sabemos este modelo es un simple diseño estático, para el caso de la estructura matemática se utilizó Wolfram Mathematica. Tal Proyecto inicial fue colaborado por GATICA SOLORIO, LOPEZ CUETO, RUIZ MARTÍNEZ, TREJO TADEO y VILLALOBOS VILLALOBOS.