Para una empresa se ha estimado un modelo que relaciona las ventas de 200 empresas, con su gasto en tv, radio, periódicos y la interacción entre tv y periódicos
options(scipen = 99999999)
load("C:/Users/DELL/Desktop/Programacion-en-R/Econometria/Guia_1_Ejercicios/modelo_ventas.RData")
Matriz_x_1 <- model.matrix(modelo_ventas)
Matriz_xx_1 <- t(Matriz_x_1)%*%Matriz_x_1
options(scipen = 99999999)
Matriz_a_1 <- solve(Matriz_xx_1)%*%t(Matriz_x_1)
Matriz_a_1[1:4,1:4]
## 1 2 3 4
## (Intercept) -0.01128647020 0.01410377973 0.0350639188 0.0004283381
## tv -0.00006704103 0.00003094914 -0.0006120193 -0.0002120642
## periodico 0.00139818182 -0.00190724690 -0.0025468816 0.0002293243
## radio -0.00058002134 0.00064866654 -0.0001093284 -0.0001899710
Matriz_p_1 <- Matriz_x_1%*%Matriz_a_1
Matriz_p_1[1:4,1:4]
## 1 2 3 4
## 1 0.03181459 0.00370346 0.01758786 0.02250872
## 2 0.00370346 0.02460480 0.03447285 0.01212022
## 3 0.01758786 0.03447285 0.06766822 0.02641047
## 4 0.02250872 0.01212022 0.02641047 0.02031981
n <- nrow(Matriz_x_1)
Matriz_m_1 <- diag(n)- Matriz_p_1
Matriz_m_1[1:4,1:4]
## 1 2 3 4
## 1 0.96818541 -0.00370346 -0.01758786 -0.02250872
## 2 -0.00370346 0.97539520 -0.03447285 -0.01212022
## 3 -0.01758786 -0.03447285 0.93233178 -0.02641047
## 4 -0.02250872 -0.01212022 -0.02641047 0.97968019
library(magrittr)
Reciduos_Medelo_Ventas <- modelo_ventas$residuals
Datos_Modelos <- modelo_ventas$model
Reciduos_Matrices <- Matriz_m_1%*%Datos_Modelos$ventas
Comparacion <- cbind(Reciduos_Matrices, Reciduos_Medelo_Ventas, Reciduos_Medelo_Ventas - Reciduos_Matrices) %>% round(digits = 2) %>% as.data.frame()
names(Comparacion) <- c("Por_Matrices","En_modelo","Diferencias")
head(Comparacion, n= 10)
## Por_Matrices En_modelo Diferencias
## 1 -15.93 -15.93 0
## 2 19.33 19.33 0
## 3 38.02 38.02 0
## 4 -15.43 -15.43 0
## 5 5.16 5.16 0
## 6 80.22 80.22 0
## 7 -16.35 -16.35 0
## 8 -22.89 -22.89 0
## 9 -34.40 -34.40 0
## 10 46.09 46.09 0
Descomposicion <- eigen(x=Matriz_xx_1, symmetric = TRUE)
Auto_Valores <- (Descomposicion$values)
print(Auto_Valores)
## [1] 311421698.6388 70252.5341 40973.4590 3714.3627 12.7735
print(Auto_Valores>0)
## [1] TRUE TRUE TRUE TRUE TRUE
Para una empresa se desea estimar un modelo que relaciona el tiempo (en minutos) en acomodar cajas en una bodega, en función de la distancia (en metros) y del número de cajas nota: las cajas son todas iguales. Los datos se encuentra en “datos_cajas.RData”
options(scipen = 99999999)
load("C:/Users/DELL/Desktop/Programacion-en-R/Econometria/Guia_1_Ejercicios/datos_cajas.RData")
Modelo_cajas <- lm(formula = Tiempo~Distancia+N_cajas,data = datos_cajas)
summary(Modelo_cajas)
##
## Call:
## lm(formula = Tiempo ~ Distancia + N_cajas, data = datos_cajas)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.2716 -0.5405 0.5212 1.4051 2.9381
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.3112 5.8573 0.395 0.70007
## Distancia 0.4559 0.1468 3.107 0.00908 **
## N_cajas 0.8772 0.1530 5.732 0.0000943 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.141 on 12 degrees of freedom
## Multiple R-squared: 0.7368, Adjusted R-squared: 0.6929
## F-statistic: 16.8 on 2 and 12 DF, p-value: 0.0003325
library(magrittr)
Matriz_x_2 <- model.matrix(Modelo_cajas)
Matriz_xx_2 <- t(Matriz_x_2)%*%Matriz_x_2
Matriz_a_2 <- solve(Matriz_xx_2)%*%t(Matriz_x_2)
print(Matriz_a_2)
## 1 2 3 4 5
## (Intercept) 0.459747079 0.505626389 -0.317731768 0.707001469 0.053149816
## Distancia -0.003015297 -0.009318829 0.018819615 -0.019989342 -0.006641453
## N_cajas -0.017147338 -0.009890695 -0.007919488 -0.004479623 0.011082085
## 6 7 8 9 10
## (Intercept) -0.166576988 0.633594572 -0.125532551 0.1260628274 -0.90735239
## Distancia 0.006550474 -0.009903692 0.009409808 0.0003379213 0.02334256
## N_cajas 0.002768355 -0.016090251 -0.003959744 -0.0038254420 0.01780152
## 11 12 13 14 15
## (Intercept) 0.277217608 0.368482344 0.487274665 -0.3674581822 -0.73350489
## Distancia -0.011931220 -0.007473259 -0.006797416 0.0001559637 0.01645417
## N_cajas 0.006862401 -0.005142468 -0.012793352 0.0238754370 0.01885861
Matriz_p_2 <- Matriz_x_2%*%Matriz_a_2
Matriz_p_2
## 1 2 3 4 5 6
## 1 0.19781478 0.127154573 0.16766180 0.062524965 -0.03527291 0.057620774
## 2 0.12715457 0.124295239 0.03396629 0.140073563 0.05334477 0.038710181
## 3 0.16766180 0.033966286 0.35585795 -0.137368460 -0.10168744 0.123125512
## 4 0.06252497 0.140073563 -0.13736846 0.257600846 0.15524536 0.006698639
## 5 -0.03527291 0.053344771 -0.10168744 0.155245361 0.18408997 0.046742309
## 6 0.05762077 0.038710181 0.12312551 0.006698639 0.04674231 0.086318088
## 7 0.17558129 0.144648497 0.07654437 0.133523089 0.01345706 0.036955589
## 8 0.11716423 0.050316476 0.21126231 -0.035350897 -0.01751039 0.094896089
## 9 0.09794605 0.077129229 0.10132526 0.055636570 0.03786105 0.067680430
## 10 -0.02906036 -0.056765574 0.20436525 -0.131155907 0.05122193 0.136694350
## 11 -0.01209498 0.081873124 -0.13140718 0.199703669 0.18629079 0.030873007
## 12 0.09285990 0.104513848 0.01812731 0.131114317 0.07550894 0.044246890
## 13 0.15541865 0.125438973 0.08744449 0.109054124 0.01789770 0.046274418
## 14 -0.12402490 -0.005427535 -0.12246527 0.112857904 0.23285894 0.067134558
## 15 -0.05129385 -0.039271650 0.11324781 -0.060157783 0.09995191 0.116029165
## 7 8 9 10 11 12
## 1 0.17558129 0.11716423 0.09794605 -0.02906036 -0.01209498 0.092859897
## 2 0.14464850 0.05031648 0.07712923 -0.05676557 0.08187312 0.104513848
## 3 0.07654437 0.21126231 0.10132526 0.20436525 -0.13140718 0.018127310
## 4 0.13352309 -0.03535090 0.05563657 -0.13115591 0.19970367 0.131114317
## 5 0.01345706 -0.01751039 0.03786105 0.05122193 0.18629079 0.075508940
## 6 0.03695559 0.09489609 0.06768043 0.13669435 0.03087301 0.044246890
## 7 0.18301556 0.07160552 0.08894348 -0.08682757 0.04935470 0.112467995
## 8 0.07160552 0.13896449 0.08399596 0.13551596 -0.03237026 0.042396988
## 9 0.08894348 0.08399596 0.07465547 0.05440619 0.04101064 0.069478345
## 10 -0.08682757 0.13551596 0.05440619 0.34795579 -0.01326471 -0.021162536
## 11 0.04935470 -0.03237026 0.04101064 -0.01326471 0.20329083 0.095597926
## 12 0.11246799 0.04239699 0.06947834 -0.02116254 0.09559793 0.094228911
## 13 0.15702161 0.07705558 0.08545596 -0.04568349 0.04428588 0.099852268
## 14 -0.07689788 -0.02789930 0.01907176 0.16357209 0.20867158 0.042323339
## 15 -0.07939330 0.08995724 0.04540362 0.29018859 0.04818497 -0.001554438
## 13 14 15
## 1 0.15541865 -0.124024902 -0.051293849
## 2 0.12543897 -0.005427535 -0.039271650
## 3 0.08744449 -0.122465266 0.113247813
## 4 0.10905412 0.112857904 -0.060157783
## 5 0.01789770 0.232858944 0.099951911
## 6 0.04627442 0.067134558 0.116029165
## 7 0.15702161 -0.076897883 -0.079393301
## 8 0.07705558 -0.027899299 0.089957240
## 9 0.08545596 0.019071756 0.045403621
## 10 -0.04568349 0.163572088 0.290188586
## 11 0.04428588 0.208671580 0.048184973
## 12 0.09985227 0.042323339 -0.001554438
## 13 0.13743085 -0.052866482 -0.044080529
## 14 -0.05286648 0.352392093 0.210699107
## 15 -0.04408053 0.210699107 0.262089133
n_2 <- nrow(Matriz_x_2)
Matriz_m_2 <- diag(n_2) - Matriz_p_2
print(Matriz_m_2)
## 1 2 3 4 5 6
## 1 0.80218522 -0.127154573 -0.16766180 -0.062524965 0.03527291 -0.057620774
## 2 -0.12715457 0.875704761 -0.03396629 -0.140073563 -0.05334477 -0.038710181
## 3 -0.16766180 -0.033966286 0.64414205 0.137368460 0.10168744 -0.123125512
## 4 -0.06252497 -0.140073563 0.13736846 0.742399154 -0.15524536 -0.006698639
## 5 0.03527291 -0.053344771 0.10168744 -0.155245361 0.81591003 -0.046742309
## 6 -0.05762077 -0.038710181 -0.12312551 -0.006698639 -0.04674231 0.913681912
## 7 -0.17558129 -0.144648497 -0.07654437 -0.133523089 -0.01345706 -0.036955589
## 8 -0.11716423 -0.050316476 -0.21126231 0.035350897 0.01751039 -0.094896089
## 9 -0.09794605 -0.077129229 -0.10132526 -0.055636570 -0.03786105 -0.067680430
## 10 0.02906036 0.056765574 -0.20436525 0.131155907 -0.05122193 -0.136694350
## 11 0.01209498 -0.081873124 0.13140718 -0.199703669 -0.18629079 -0.030873007
## 12 -0.09285990 -0.104513848 -0.01812731 -0.131114317 -0.07550894 -0.044246890
## 13 -0.15541865 -0.125438973 -0.08744449 -0.109054124 -0.01789770 -0.046274418
## 14 0.12402490 0.005427535 0.12246527 -0.112857904 -0.23285894 -0.067134558
## 15 0.05129385 0.039271650 -0.11324781 0.060157783 -0.09995191 -0.116029165
## 7 8 9 10 11 12
## 1 -0.17558129 -0.11716423 -0.09794605 0.02906036 0.01209498 -0.092859897
## 2 -0.14464850 -0.05031648 -0.07712923 0.05676557 -0.08187312 -0.104513848
## 3 -0.07654437 -0.21126231 -0.10132526 -0.20436525 0.13140718 -0.018127310
## 4 -0.13352309 0.03535090 -0.05563657 0.13115591 -0.19970367 -0.131114317
## 5 -0.01345706 0.01751039 -0.03786105 -0.05122193 -0.18629079 -0.075508940
## 6 -0.03695559 -0.09489609 -0.06768043 -0.13669435 -0.03087301 -0.044246890
## 7 0.81698444 -0.07160552 -0.08894348 0.08682757 -0.04935470 -0.112467995
## 8 -0.07160552 0.86103551 -0.08399596 -0.13551596 0.03237026 -0.042396988
## 9 -0.08894348 -0.08399596 0.92534453 -0.05440619 -0.04101064 -0.069478345
## 10 0.08682757 -0.13551596 -0.05440619 0.65204421 0.01326471 0.021162536
## 11 -0.04935470 0.03237026 -0.04101064 0.01326471 0.79670917 -0.095597926
## 12 -0.11246799 -0.04239699 -0.06947834 0.02116254 -0.09559793 0.905771089
## 13 -0.15702161 -0.07705558 -0.08545596 0.04568349 -0.04428588 -0.099852268
## 14 0.07689788 0.02789930 -0.01907176 -0.16357209 -0.20867158 -0.042323339
## 15 0.07939330 -0.08995724 -0.04540362 -0.29018859 -0.04818497 0.001554438
## 13 14 15
## 1 -0.15541865 0.124024902 0.051293849
## 2 -0.12543897 0.005427535 0.039271650
## 3 -0.08744449 0.122465266 -0.113247813
## 4 -0.10905412 -0.112857904 0.060157783
## 5 -0.01789770 -0.232858944 -0.099951911
## 6 -0.04627442 -0.067134558 -0.116029165
## 7 -0.15702161 0.076897883 0.079393301
## 8 -0.07705558 0.027899299 -0.089957240
## 9 -0.08545596 -0.019071756 -0.045403621
## 10 0.04568349 -0.163572088 -0.290188586
## 11 -0.04428588 -0.208671580 -0.048184973
## 12 -0.09985227 -0.042323339 0.001554438
## 13 0.86256915 0.052866482 0.044080529
## 14 0.05286648 0.647607907 -0.210699107
## 15 0.04408053 -0.210699107 0.737910867
Reciduos_Medelo_Cajas <- Modelo_cajas$residuals
Datos_Modelos <- Modelo_cajas$model
Reciduos_Matrices_2 <- Matriz_m_2%*%datos_cajas$Tiempo
Comparacion_2 <- cbind(Reciduos_Matrices_2,Reciduos_Medelo_Cajas, Reciduos_Medelo_Cajas - Reciduos_Matrices_2) %>% round(digits = 2) %>% as.data.frame()
names(Comparacion_2) <- c("Por_Matrices","En_modelo","Diferencias")
head(Comparacion_2, n= 10)
## Por_Matrices En_modelo Diferencias
## 1 -0.76 -0.76 0
## 2 0.13 0.13 0
## 3 -0.32 -0.32 0
## 4 2.94 2.94 0
## 5 -9.27 -9.27 0
## 6 0.77 0.77 0
## 7 1.31 1.31 0
## 8 -2.09 -2.09 0
## 9 1.43 1.43 0
## 10 0.52 0.52 0
Descomposicion_2 <- eigen(x=Matriz_xx_2, symmetric = TRUE)
Auto_Valores_2 <- (Descomposicion_2$values)
print(Auto_Valores_2)
## [1] 16976.7781334 709.9345923 0.2872743
print(Auto_Valores_2>0)
## [1] TRUE TRUE TRUE
Para los EEUU se ha estimado un modelo que relaciona el “número de crímenes” en un estado con el “Nivel de pobreza” y la cantidad de solteros en el mismo. Dicho modelo se encuentra en “modelo_estimado.RData”
options(scipen = 99999999)
load("C:/Users/DELL/Desktop/Programacion-en-R/Econometria/Guia_1_Ejercicios/modelo_estimado.RData")
Matriz_x_3 <- model.matrix(modelo_estimado_1)
Matriz_xx_3 <- t(Matriz_x_3)%*%Matriz_x_3
Matriz_a_3 <- solve(Matriz_xx_3)%*%t(Matriz_x_3)
Matriz_a_3[,1:4]
## 1 2 3 4
## (Intercept) -0.12023796 0.007496216 0.043732382 -0.019624196
## poverty -0.01182361 0.003994776 0.008825494 0.000303668
## single 0.02723384 -0.003960021 -0.013241432 0.003081729
Matriz_p_3 <- Matriz_x_3%*%Matriz_a_3
Matriz_p_3[1:4,1:4]
## 1 2 3 4
## 1 0.16161108 -0.01277963 -0.06530809 0.02720791
## 2 -0.01277963 0.03146508 0.04501952 0.02109951
## 3 -0.06530809 0.04501952 0.07855895 0.01942366
## 4 0.02720791 0.02109951 0.01942366 0.02234121
n_3 <- nrow(Matriz_x_3)
Matriz_m_3 <- diag(n_3) - Matriz_p_3
Matriz_m_3[1:4,1:4]
## 1 2 3 4
## 1 0.83838892 0.01277963 0.06530809 -0.02720791
## 2 0.01277963 0.96853492 -0.04501952 -0.02109951
## 3 0.06530809 -0.04501952 0.92144105 -0.01942366
## 4 -0.02720791 -0.02109951 -0.01942366 0.97765879
Reciduos_Medelo_Estimado <- modelo_estimado_1$residuals
Datos_Modelo_Estimado <- modelo_estimado_1$model
Reciduos_Matrices_3 <- Matriz_m_3%*%Datos_Modelo_Estimado$crime
Comparacion_3 <- cbind(Reciduos_Matrices_3,Reciduos_Medelo_Estimado, Reciduos_Medelo_Estimado - Reciduos_Matrices_3) %>% round(digits = 2) %>% as.data.frame()
names(Comparacion_3) <- c("Por_Matrices","En_modelo","Diferencias")
head(Comparacion_3, n= 10)
## Por_Matrices En_modelo Diferencias
## 1 -311.71 -311.71 0
## 2 116.80 116.80 0
## 3 45.25 45.25 0
## 4 -34.45 -34.45 0
## 5 243.00 243.00 0
## 6 -145.12 -145.12 0
## 7 86.13 86.13 0
## 8 88.31 88.31 0
## 9 689.82 689.82 0
## 10 -163.29 -163.29 0
Descomposicion_3 <- eigen(x=Matriz_xx_3, symmetric = TRUE)
Auto_Valores_3 <- (Descomposicion_3$values)
print(Auto_Valores_3)
## [1] 17956.580914 279.157317 1.681762
print(Auto_Valores_3>0)
## [1] TRUE TRUE TRUE
Dentro del archivo “Investiment_Equation.xlsx” se encuentran datos para estimar una función de inversión, para un país, y contiene las siguientes variables:
library(readxl)
library(stargazer)
Investiment_Equation <- read_excel("C:/Users/DELL/Desktop/Programacion-en-R/Econometria/Guia_1_Ejercicios/Data/Investiment_Equation.xlsx")
Ecuacion_Inversion <- lm(formula = InvReal~Trend-Inflation+PNBr+Interest, data = Investiment_Equation)
stargazer(Ecuacion_Inversion, title = "Ecuación de Inversión", type = "html")
| Dependent variable: | |
| InvReal | |
| Trend | -0.016*** |
| (0.002) | |
| PNBr | 0.665*** |
| (0.052) | |
| Interest | -0.239** |
| (0.102) | |
| Constant | -0.503*** |
| (0.052) | |
| Observations | 15 |
| R2 | 0.973 |
| Adjusted R2 | 0.966 |
| Residual Std. Error | 0.006 (df = 11) |
| F Statistic | 132.127*** (df = 3; 11) |
| Note: | p<0.1; p<0.05; p<0.01 |
Matriz_x_4 <- model.matrix(Ecuacion_Inversion)
n <- nrow(Matriz_x_4)
Matriz_m_4 <- diag(n) - Matriz_x_4 %*% solve(t(Matriz_x_4)%*%Matriz_x_4) %*% t(Matriz_x_4)
Y <- Investiment_Equation$InvReal
Residuos <- Matriz_m_4%*%Y
print(Residuos)
## [,1]
## 1 -0.0100797395
## 2 -0.0009395423
## 3 0.0029590400
## 4 0.0078509093
## 5 0.0027863240
## 6 0.0006169256
## 7 0.0076387748
## 8 -0.0054613455
## 9 -0.0037407700
## 10 0.0006919072
## 11 0.0020015571
## 12 -0.0001177806
## 13 -0.0101857096
## 14 0.0068691861
## 15 -0.0008897366
confint(object = Ecuacion_Inversion, parm = "PNBr", level = .93)
## 3.5 % 96.5 %
## PNBr 0.5610827 0.7680701
Dentro del archivo “consumption_equation.RData” se encuentran objetos relacionados a una función de consumo, que se construyó usando las variables:
options(scipen = 99999999)
load("C:/Users/DELL/Desktop/Programacion-en-R/Econometria/Guia_1_Ejercicios/consumption_equation.RData")
n_5 <- nrow(P)
Matriz_m_5 <- diag(n_5) - P
Residuos_5 <- Matriz_m_5%*%C
print(Residuos_5)
## [,1]
## 1 -5.859103
## 2 2.605057
## 3 45.765735
## 4 31.102448
## 5 -21.037889
## 6 7.008120
## 7 17.859663
## 8 10.705631
## 9 22.002328
## 10 -2.689665
## 11 7.784083
## 12 -13.127696
## 13 17.521565
## 14 17.304695
## 15 -16.308260
## 16 -5.255508
## 17 2.788211
## 18 -16.379339
## 19 -14.327554
## 20 11.749135
## 21 -31.424669
## 22 -23.329596
## 23 22.171806
## 24 -5.040038
## 25 -36.191398
## 26 -25.211753
## 27 -21.411271
## 28 1.410519
## 29 -24.229564
## 30 20.971808
## 31 43.342653
## 32 36.808458
## 33 17.882297
## 34 -33.100273
## 35 -37.819995
## 36 -49.370820
## 37 23.456143
## 38 -25.510341
## 39 -11.960629
## 40 -9.234201
## 41 21.949616
## 42 3.211123
## 43 -14.511436
## 44 3.197576
## 45 -62.396763
## 46 -66.854500
## 47 8.330745
## 48 91.963380
## 49 61.620735
## 50 48.148861
## 51 -10.717721
## 52 -84.069717
## 53 -56.426627
## 54 125.113605
k <- 4
Varianza_Error <- t(Residuos_5)%*%Residuos_5/(n_5-k)
print(Varianza_Error)
## [,1]
## [1,] 1428.746
Varianza_Error <- as.vector(Varianza_Error)
Varianza_Covarianza <- Varianza_Error*solve(XX)
print(Varianza_Covarianza)
## (Intercept) Yd W I
## (Intercept) 164.522304918 -0.09333539523 0.009670913575 10.5186890800
## Yd -0.093335395 0.00018911268 -0.000032769561 -0.0072901023
## W 0.009670914 -0.00003276956 0.000006165749 0.0004193421
## I 10.518689080 -0.00729010228 0.000419342092 5.3203789879
C_Estimada <- P%*%C
Cuadro <- as.data.frame(cbind(C, C_Estimada, Residuos_5))
names(Cuadro) <- c("C", "C_Estimada", "Residuos")
print(Cuadro)
## C C_Estimada Residuos
## 1 976.4 982.2591 -5.859103
## 2 998.1 995.4949 2.605057
## 3 1025.3 979.5343 45.765735
## 4 1090.9 1059.7976 31.102448
## 5 1107.1 1128.1379 -21.037889
## 6 1142.4 1135.3919 7.008120
## 7 1197.2 1179.3403 17.859663
## 8 1221.9 1211.1944 10.705631
## 9 1310.4 1288.3977 22.002328
## 10 1348.8 1351.4897 -2.689665
## 11 1381.8 1374.0159 7.784083
## 12 1393.0 1406.1277 -13.127696
## 13 1470.7 1453.1784 17.521565
## 14 1510.8 1493.4953 17.304695
## 15 1541.2 1557.5083 -16.308260
## 16 1617.3 1622.5555 -5.255508
## 17 1684.0 1681.2118 2.788211
## 18 1784.8 1801.1793 -16.379339
## 19 1897.6 1911.9276 -14.327554
## 20 2006.1 1994.3509 11.749135
## 21 2066.2 2097.6247 -31.424669
## 22 2184.2 2207.5296 -23.329596
## 23 2264.8 2242.6282 22.171806
## 24 2317.5 2322.5400 -5.040038
## 25 2405.2 2441.3914 -36.191398
## 26 2550.5 2575.7118 -25.211753
## 27 2675.9 2697.3113 -21.411271
## 28 2653.7 2652.2895 1.410519
## 29 2710.9 2735.1296 -24.229564
## 30 2868.9 2847.9282 20.971808
## 31 2992.1 2948.7573 43.342653
## 32 3124.7 3087.8915 36.808458
## 33 3203.2 3185.3177 17.882297
## 34 3193.0 3226.1003 -33.100273
## 35 3236.0 3273.8200 -37.819995
## 36 3275.5 3324.8708 -49.370820
## 37 3454.3 3430.8439 23.456143
## 38 3640.6 3666.1103 -25.510341
## 39 3820.9 3832.8606 -11.960629
## 40 3981.2 3990.4342 -9.234201
## 41 4113.4 4091.4504 21.949616
## 42 4279.5 4276.2889 3.211123
## 43 4393.7 4408.2114 -14.511436
## 44 4474.5 4471.3024 3.197576
## 45 4466.6 4528.9968 -62.396763
## 46 4594.5 4661.3545 -66.854500
## 47 4748.9 4740.5693 8.330745
## 48 4928.1 4836.1366 91.963380
## 49 5075.6 5013.9793 61.620735
## 50 5237.5 5189.3511 48.148861
## 51 5423.9 5434.6177 -10.717721
## 52 5683.7 5767.7697 -84.069717
## 53 5968.4 6024.8266 -56.426627
## 54 6257.8 6132.6864 125.113605
Dentro del archivo “datos_ventas.RData” se encuentran los datos para estimar una función de ventas, para una empresa, y contiene las siguientes variables:
options(scipen = 99999999)
load("C:/Users/DELL/Desktop/Programacion-en-R/Econometria/Guia_1_Ejercicios/datos_ventas.RData")
Ecuacion_Ventas <- lm(formula = ventas~tv+radio+periodico, data = datos_ventas)
stargazer(Ecuacion_Ventas, title = "Ecuación de Ventas", type = "html")
| Dependent variable: | |
| ventas | |
| tv | 0.045 |
| (0.118) | |
| radio | -3.450*** |
| (0.206) | |
| periodico | 18.485*** |
| (0.563) | |
| Constant | -33.289*** |
| (7.172) | |
| Observations | 200 |
| R2 | 0.847 |
| Adjusted R2 | 0.844 |
| Residual Std. Error | 33.875 (df = 196) |
| F Statistic | 360.758*** (df = 3; 196) |
| Note: | p<0.1; p<0.05; p<0.01 |
Matriz_x_6 <- model.matrix(Ecuacion_Ventas)
Matriz_a_6 <- t(Matriz_x_6)%*%Matriz_x_6 %>%
solve()%*%t(Matriz_x_6)
n_6 <- nrow(Matriz_x_6)
Matriz_m_6 <- diag(n_6) - Matriz_x_6%*%Matriz_a_6
head(Matriz_m_6%*%modelo_ventas$model$ventas, n=10)
## [,1]
## 1 -17.85246
## 2 19.08216
## 3 33.79319
## 4 -17.35090
## 5 10.25721
## 6 74.20385
## 7 -15.24652
## 8 -23.42430
## 9 -39.64052
## 10 45.16139
confint(object = Ecuacion_Ventas, parm = "tv", level = .968)
## 1.6 % 98.4 %
## tv -0.2097376 0.2998052
Indica que el gasto en de publicidad en tv no es significativo, es decir, no hay relación lenal ya que su intervalo incluye el cero.