R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

# 1. Carga de librerías y datos
library(readxl)
datos <- read_excel("Datos_Situacion_Problema.xlsx")

# 2. Transformación a Modelo Log-Log (Visto en S04 Modelos No Lineales)
# La Cobb-Douglas se convierte en una regresión lineal múltiple al aplicar logaritmos
datos$ln_Q <- log(datos$Producción_Q)
datos$ln_K <- log(datos$Capital_K)
datos$ln_L <- log(datos$Mano_Obra_L)

# 3. Estimación por MCO (Visto en S02 Regresión Lineal)
modelo <- lm(ln_Q ~ ln_L + ln_K, data = datos)
summary(modelo)
## 
## Call:
## lm(formula = ln_Q ~ ln_L + ln_K, data = datos)
## 
## Residuals:
##          1          2          3          4          5          6          7 
##  0.0006220  0.0062909 -0.0001398 -0.0063396 -0.0125818 -0.0100704  0.0222187 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.98921    0.01983  150.74 1.16e-08 ***
## ln_L         0.81586    0.02040   39.99 2.34e-06 ***
## ln_K         0.19790    0.01646   12.02 0.000274 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01444 on 4 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9998 
## F-statistic: 1.252e+04 on 2 and 4 DF,  p-value: 2.55e-08
# 4. Prueba de Hipótesis (Visto en S03 Prueba de Hipotesis)
# Para probar Retornos Constantes a Escala (H0: beta + alpha = 1)
library(car)
## Warning: package 'car' was built under R version 4.4.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.4.3
linearHypothesis(modelo, "ln_L + ln_K = 1")
## 
## Linear hypothesis test:
## ln_L  + ln_K = 1
## 
## Model 1: restricted model
## Model 2: ln_Q ~ ln_L + ln_K
## 
##   Res.Df        RSS Df  Sum of Sq      F Pr(>F)
## 1      5 0.00159124                            
## 2      4 0.00083356  1 0.00075768 3.6359 0.1292
A <- exp(coef(modelo)[1])
alpha <- coef(modelo)[3]
beta <- coef(modelo)[2]

A
## (Intercept) 
##    19.87006
alpha
##      ln_K 
## 0.1979024
beta
##      ln_L 
## 0.8158614
# relación óptima L/K
beta/alpha
##     ln_L 
## 4.122545
# producción deseada
Q <- 400

# resolver K usando la función
# Q = A * K^alpha * ( (beta/alpha)*K )^beta

rel <- beta/alpha

K <- (Q / (A * rel^beta))^(1/(alpha + beta))
K
## (Intercept) 
##    6.181344
# obtener L
L <- rel * K
L
##     ln_L 
## 25.48287
# Estimamos la función con el nombre correcto para que los cálculos de abajo funcionen
m_cobb <- lm(ln_Q ~ ln_L + ln_K, data = datos)

# Vemos el resumen
summary(m_cobb)
## 
## Call:
## lm(formula = ln_Q ~ ln_L + ln_K, data = datos)
## 
## Residuals:
##          1          2          3          4          5          6          7 
##  0.0006220  0.0062909 -0.0001398 -0.0063396 -0.0125818 -0.0100704  0.0222187 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.98921    0.01983  150.74 1.16e-08 ***
## ln_L         0.81586    0.02040   39.99 2.34e-06 ***
## ln_K         0.19790    0.01646   12.02 0.000274 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01444 on 4 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9998 
## F-statistic: 1.252e+04 on 2 and 4 DF,  p-value: 2.55e-08
# 1. Extraemos los coeficientes del modelo m_cobb
alfa <- coef(m_cobb)["ln_K"]
beta <- coef(m_cobb)["ln_L"]
A <- exp(coef(m_cobb)["(Intercept)"])

# 2. Datos del problema
w <- 25000     # Salario
r <- 15000     # Renta de capital
Q_meta <- 400  # Producción objetivo

# 3. Relación óptima L/K (Senda de expansión)
rel <- (beta / alfa) * (r / w)

# 4. Cálculo de K óptimo
K_optimo <- ( (Q_meta / A) * (1 / (rel^beta)) )^(1 / (alfa + beta))

# 5. Cálculo de L óptimo
L_optimo <- rel * K_optimo

# 6. Imprimimos resultados
cat("Resultados para el Sr. Stuff:", "\n")
## Resultados para el Sr. Stuff:
cat("Capital óptimo (K):", round(K_optimo, 2), "\n")
## Capital óptimo (K): 9.32
cat("Mano de obra óptima (L):", round(L_optimo, 2), "\n")
## Mano de obra óptima (L): 23.06
# 1. Cargar la librería necesaria
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
# 2. Crear una secuencia de datos para la línea de la senda
# Usamos un rango de 0 a 30 trabajadores para la visualización
L_seq <- seq(0, 30, length.out = 100)
# Recordamos que la relación es K = 0.4043 * L (o la que guardaste en 'rel')
K_senda <- (alfa / beta) * (w / r) * L_seq 

df_senda <- data.frame(Trabajo = L_seq, Capital = K_senda)

# 3. Crear la gráfica
ggplot(df_senda, aes(x = Trabajo, y = Capital)) +
  # Dibujar la Senda de Expansión (línea azul)
  geom_line(color = "blue", linewidth = 1.2) +
  # Punto Real 2012 (Rojo)
  geom_point(aes(x = 20, y = 15), color = "red", size = 4) +
  annotate("text", x = 20, y = 15.8, label = "2012 Real", color = "red", fontface = "bold") +
  # Punto Óptimo calculado (Verde)
  geom_point(aes(x = L_optimo, y = K_optimo), color = "darkgreen", size = 4) +
  annotate("text", x = L_optimo, y = K_optimo - 0.8, label = "Óptimo", color = "darkgreen", fontface = "bold") +
  # Configuración de etiquetas y diseño
  labs(title = "Senda de Expansión: E.Z. Stuff",
       subtitle = "Comparación entre la combinación Real (2012) y la Óptima",
       x = "Mano de Obra (Trabajadores)",
       y = "Capital (Unidades)") +
  coord_cartesian(xlim = c(0, 30), ylim = c(0, 18)) +
  theme_minimal()
## Warning in geom_point(aes(x = 20, y = 15), color = "red", size = 4): All aesthetics have length 1, but the data has 100 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_point(aes(x = L_optimo, y = K_optimo), color = "darkgreen", : All aesthetics have length 1, but the data has 100 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.