# El Servicio Interno de Contribuciones (IRS) de EE.UU. está tratando de estimar la cantidad mensual de impuestos no pagados descubiertos por su departamento de auditorías. En el pasado, el IRS estimaba esta cantidad con base en el número esperado de horas de trabajo de auditorías de campo. En los últimos años, sin embargo, las horas de trabajo de auditorías de campo se han convertido en un pronosticador errático de los impuestos no pagados reales. Como resultado, la dependencia está buscando otro factor para mejorar la ecuación de estimación.
# El departamento de auditorías tiene un registro del número de horas que usa sus computadoras para detectar impuestos no pagados. ¿Podríamos combinar esta información con los datos referentes a las horas de trabajo de auditorías de campo y obtener una ecuación de estimación más precisa para los impuestos no pagados descubiertos por cada mes?
library(readr)
library(dplyr)
ruta_archivo<-"C:/Users/74/Desktop/BASES PARA R/R. Múltiple Ejercicicio.csv"
datos<-read_csv(file = ruta_archivo)
datos
datos1<-select(datos, Y = "Impuestos reales", X1 = "Horas en Computadora", X2 = "Horas de trabajo")
datos1
datos1 %>% select("Y") %>% as.matrix()->Yregresada
Yregresada
Y
[1,] 29
[2,] 24
[3,] 27
[4,] 25
[5,] 26
[6,] 28
[7,] 30
[8,] 28
[9,] 28
[10,] 27
datos1 %>% mutate(Cte=1) %>% select("Cte","X1","X2") %>% as.matrix()->Xregresor
Xregresor
Cte X1 X2
[1,] 1 16 45
[2,] 1 14 42
[3,] 1 15 44
[4,] 1 13 45
[5,] 1 13 43
[6,] 1 14 46
[7,] 1 16 44
[8,] 1 16 45
[9,] 1 15 44
[10,] 1 15 43
columna_1<-as.matrix(Xregresor[,1])
columna_2<-as.matrix(Xregresor[,2])
Transpuesta<-t(columna_1)
productoescalar<-((t(columna_1)%*%columna_2))
productoescalar
[,1]
[1,] 147
Xtranspuesta<-t(Xregresor)
sigmamatriz<-(Xtranspuesta%*%Xregresor)
sigmamatriz
Cte X1 X2
Cte 10 147 441
X1 147 2173 6485
X2 441 6485 19461
cruzada<-(Xtranspuesta%*%Yregresada)
cruzada
Y
Cte 272
X1 4013
X2 12005
inversigma<-solve(sigmamatriz)
inversigma
Cte X1 X2
Cte 154.8594164 -0.58488064 -3.31432361
X1 -0.5848806 0.08554377 -0.01525199
X2 -3.3143236 -0.01525199 0.08023873
Betas_Estimados<-(inversigma%*%cruzada)
Betas_Estimados
Y
Cte -13.8196286
X1 1.0994695
X2 0.5636605
Matriz_P<-(Xregresor%*%inversigma%*%Xtranspuesta)
Matriz_P
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[2,] -0.07824934 0.45092838 0.10742706 0.00530504 0.32095491 -0.18037135
[3,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[4,] -0.01856764 0.00530504 0.04244032 0.45888594 0.26259947 0.39787798
[5,] -0.12334218 0.32095491 0.06763926 0.26259947 0.38726790 0.07161804
[6,] 0.13129973 -0.18037135 0.05702918 0.39787798 0.07161804 0.47214854
[7,] 0.22148541 0.07957560 0.13660477 -0.11671088 -0.06100796 -0.03183024
[8,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[9,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[10,] 0.07161804 0.26525199 0.12201592 -0.05570292 0.12997347 -0.10610080
[,7] [,8] [,9] [,10]
[1,] 0.22148541 0.27387268 0.12400531 0.07161804
[2,] 0.07957560 -0.07824934 0.10742706 0.26525199
[3,] 0.13660477 0.12400531 0.10941645 0.12201592
[4,] -0.11671088 -0.01856764 0.04244032 -0.05570292
[5,] -0.06100796 -0.12334218 0.06763926 0.12997347
[6,] -0.03183024 0.13129973 0.05702918 -0.10610080
[7,] 0.24933687 0.22148541 0.13660477 0.16445623
[8,] 0.22148541 0.27387268 0.12400531 0.07161804
[9,] 0.13660477 0.12400531 0.10941645 0.12201592
[10,] 0.16445623 0.07161804 0.12201592 0.21485411
Y_Proyectada<-(Matriz_P%*%Yregresada)
Y_Proyectada
Y
[1,] 29.13660
[2,] 25.24668
[3,] 27.47347
[4,] 25.83820
[5,] 24.71088
[6,] 27.50133
[7,] 28.57294
[8,] 29.13660
[9,] 27.47347
[10,] 26.90981
Errores<-(Yregresada-Y_Proyectada)
Errores
Y
[1,] -0.13660477
[2,] -1.24668435
[3,] -0.47347480
[4,] -0.83819629
[5,] 1.28912467
[6,] 0.49867374
[7,] 1.42705570
[8,] -1.13660477
[9,] 0.52652520
[10,] 0.09018568
Autovalor<-eigen(sigmamatriz)
Autovalor
eigen() decomposition
$values
[1] 21633.193554354 10.799991225 0.006454421
$vectors
[,1] [,2] [,3]
[1,] -0.02149301 0.003186926 0.999763919
[2,] -0.31622490 -0.948676746 -0.003774152
[3,] -0.94844075 0.316231363 -0.021397701
Matriz_A<-inversigma%*%Xtranspuesta
Matriz_A
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
Cte -3.64323607 7.46949602 0.25596817 -1.88859416 4.74005305 -5.78779841 -0.32891247
X1 0.09748011 -0.02785146 0.02718833 -0.15915119 -0.12864721 -0.08885942 0.11273210
X2 0.05238727 -0.15782493 -0.01259947 0.09814324 -0.06233422 0.16312997 -0.02785146
[,8] [,9] [,10]
Cte -3.64323607 0.25596817 3.57029178
X1 0.09748011 0.02718833 0.04244032
X2 0.05238727 -0.01259947 -0.09283820
Estimadores<-Matriz_A%*%Yregresada
Estimadores
Y
Cte -13.8196286
X1 1.0994695
X2 0.5636605
# Los parámetros son una combinación lineal de "Y"
Matriz_P<-Xregresor%*%inversigma%*%Xtranspuesta
Matriz_P
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[2,] -0.07824934 0.45092838 0.10742706 0.00530504 0.32095491 -0.18037135
[3,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[4,] -0.01856764 0.00530504 0.04244032 0.45888594 0.26259947 0.39787798
[5,] -0.12334218 0.32095491 0.06763926 0.26259947 0.38726790 0.07161804
[6,] 0.13129973 -0.18037135 0.05702918 0.39787798 0.07161804 0.47214854
[7,] 0.22148541 0.07957560 0.13660477 -0.11671088 -0.06100796 -0.03183024
[8,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[9,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[10,] 0.07161804 0.26525199 0.12201592 -0.05570292 0.12997347 -0.10610080
[,7] [,8] [,9] [,10]
[1,] 0.22148541 0.27387268 0.12400531 0.07161804
[2,] 0.07957560 -0.07824934 0.10742706 0.26525199
[3,] 0.13660477 0.12400531 0.10941645 0.12201592
[4,] -0.11671088 -0.01856764 0.04244032 -0.05570292
[5,] -0.06100796 -0.12334218 0.06763926 0.12997347
[6,] -0.03183024 0.13129973 0.05702918 -0.10610080
[7,] 0.24933687 0.22148541 0.13660477 0.16445623
[8,] 0.22148541 0.27387268 0.12400531 0.07161804
[9,] 0.13660477 0.12400531 0.10941645 0.12201592
[10,] 0.16445623 0.07161804 0.12201592 0.21485411
Matriz_PY<-Matriz_P%*%Yregresada
Matriz_PY
Y
[1,] 29.13660
[2,] 25.24668
[3,] 27.47347
[4,] 25.83820
[5,] 24.71088
[6,] 27.50133
[7,] 28.57294
[8,] 29.13660
[9,] 27.47347
[10,] 26.90981
# Las estimaciones de "Y" también son una combinación lineal de "Y"
Matriz_Identidad<-diag(10)
Matriz_Identidad
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 0 0 0 0 0 0 0 0 0
[2,] 0 1 0 0 0 0 0 0 0 0
[3,] 0 0 1 0 0 0 0 0 0 0
[4,] 0 0 0 1 0 0 0 0 0 0
[5,] 0 0 0 0 1 0 0 0 0 0
[6,] 0 0 0 0 0 1 0 0 0 0
[7,] 0 0 0 0 0 0 1 0 0 0
[8,] 0 0 0 0 0 0 0 1 0 0
[9,] 0 0 0 0 0 0 0 0 1 0
[10,] 0 0 0 0 0 0 0 0 0 1
Matriz_M<-(Matriz_Identidad-Matriz_P)
Matriz_M
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.72612732 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[2,] 0.07824934 0.54907162 -0.10742706 -0.00530504 -0.32095491 0.18037135
[3,] -0.12400531 -0.10742706 0.89058355 -0.04244032 -0.06763926 -0.05702918
[4,] 0.01856764 -0.00530504 -0.04244032 0.54111406 -0.26259947 -0.39787798
[5,] 0.12334218 -0.32095491 -0.06763926 -0.26259947 0.61273210 -0.07161804
[6,] -0.13129973 0.18037135 -0.05702918 -0.39787798 -0.07161804 0.52785146
[7,] -0.22148541 -0.07957560 -0.13660477 0.11671088 0.06100796 0.03183024
[8,] -0.27387268 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[9,] -0.12400531 -0.10742706 -0.10941645 -0.04244032 -0.06763926 -0.05702918
[10,] -0.07161804 -0.26525199 -0.12201592 0.05570292 -0.12997347 0.10610080
[,7] [,8] [,9] [,10]
[1,] -0.22148541 -0.27387268 -0.12400531 -0.07161804
[2,] -0.07957560 0.07824934 -0.10742706 -0.26525199
[3,] -0.13660477 -0.12400531 -0.10941645 -0.12201592
[4,] 0.11671088 0.01856764 -0.04244032 0.05570292
[5,] 0.06100796 0.12334218 -0.06763926 -0.12997347
[6,] 0.03183024 -0.13129973 -0.05702918 0.10610080
[7,] 0.75066313 -0.22148541 -0.13660477 -0.16445623
[8,] -0.22148541 0.72612732 -0.12400531 -0.07161804
[9,] -0.13660477 -0.12400531 0.89058355 -0.12201592
[10,] -0.16445623 -0.07161804 -0.12201592 0.78514589
Errores_2<-Matriz_M%*%Yregresada
Errores_2
Y
[1,] -0.13660477
[2,] -1.24668435
[3,] -0.47347480
[4,] -0.83819629
[5,] 1.28912467
[6,] 0.49867374
[7,] 1.42705570
[8,] -1.13660477
[9,] 0.52652520
[10,] 0.09018568
# Los residuos del modelo también son una combinación lineal de "Y"
# Una matriz idempotente es una matriz que es igual a su cuadrado, es decir:
#A es idempotente si A × A = A
#Si representamos el producto A*A por A^2, entonces es idempotente sólo si: A^2=A.
#En general, la idempotencia hace referencia a una operación que, si se repite, produce el mismo resultado que si se llevara a cabo una sola vez. Un caso particular de matriz idempotente es una matriz de proyección.
Matriz_M
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.72612732 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[2,] 0.07824934 0.54907162 -0.10742706 -0.00530504 -0.32095491 0.18037135
[3,] -0.12400531 -0.10742706 0.89058355 -0.04244032 -0.06763926 -0.05702918
[4,] 0.01856764 -0.00530504 -0.04244032 0.54111406 -0.26259947 -0.39787798
[5,] 0.12334218 -0.32095491 -0.06763926 -0.26259947 0.61273210 -0.07161804
[6,] -0.13129973 0.18037135 -0.05702918 -0.39787798 -0.07161804 0.52785146
[7,] -0.22148541 -0.07957560 -0.13660477 0.11671088 0.06100796 0.03183024
[8,] -0.27387268 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[9,] -0.12400531 -0.10742706 -0.10941645 -0.04244032 -0.06763926 -0.05702918
[10,] -0.07161804 -0.26525199 -0.12201592 0.05570292 -0.12997347 0.10610080
[,7] [,8] [,9] [,10]
[1,] -0.22148541 -0.27387268 -0.12400531 -0.07161804
[2,] -0.07957560 0.07824934 -0.10742706 -0.26525199
[3,] -0.13660477 -0.12400531 -0.10941645 -0.12201592
[4,] 0.11671088 0.01856764 -0.04244032 0.05570292
[5,] 0.06100796 0.12334218 -0.06763926 -0.12997347
[6,] 0.03183024 -0.13129973 -0.05702918 0.10610080
[7,] 0.75066313 -0.22148541 -0.13660477 -0.16445623
[8,] -0.22148541 0.72612732 -0.12400531 -0.07161804
[9,] -0.13660477 -0.12400531 0.89058355 -0.12201592
[10,] -0.16445623 -0.07161804 -0.12201592 0.78514589
M_Idem<-Matriz_M%*%Matriz_M
M_Idem
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.72612732 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[2,] 0.07824934 0.54907162 -0.10742706 -0.00530504 -0.32095491 0.18037135
[3,] -0.12400531 -0.10742706 0.89058355 -0.04244032 -0.06763926 -0.05702918
[4,] 0.01856764 -0.00530504 -0.04244032 0.54111406 -0.26259947 -0.39787798
[5,] 0.12334218 -0.32095491 -0.06763926 -0.26259947 0.61273210 -0.07161804
[6,] -0.13129973 0.18037135 -0.05702918 -0.39787798 -0.07161804 0.52785146
[7,] -0.22148541 -0.07957560 -0.13660477 0.11671088 0.06100796 0.03183024
[8,] -0.27387268 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[9,] -0.12400531 -0.10742706 -0.10941645 -0.04244032 -0.06763926 -0.05702918
[10,] -0.07161804 -0.26525199 -0.12201592 0.05570292 -0.12997347 0.10610080
[,7] [,8] [,9] [,10]
[1,] -0.22148541 -0.27387268 -0.12400531 -0.07161804
[2,] -0.07957560 0.07824934 -0.10742706 -0.26525199
[3,] -0.13660477 -0.12400531 -0.10941645 -0.12201592
[4,] 0.11671088 0.01856764 -0.04244032 0.05570292
[5,] 0.06100796 0.12334218 -0.06763926 -0.12997347
[6,] 0.03183024 -0.13129973 -0.05702918 0.10610080
[7,] 0.75066313 -0.22148541 -0.13660477 -0.16445623
[8,] -0.22148541 0.72612732 -0.12400531 -0.07161804
[9,] -0.13660477 -0.12400531 0.89058355 -0.12201592
[10,] -0.16445623 -0.07161804 -0.12201592 0.78514589
Matriz_P
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[2,] -0.07824934 0.45092838 0.10742706 0.00530504 0.32095491 -0.18037135
[3,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[4,] -0.01856764 0.00530504 0.04244032 0.45888594 0.26259947 0.39787798
[5,] -0.12334218 0.32095491 0.06763926 0.26259947 0.38726790 0.07161804
[6,] 0.13129973 -0.18037135 0.05702918 0.39787798 0.07161804 0.47214854
[7,] 0.22148541 0.07957560 0.13660477 -0.11671088 -0.06100796 -0.03183024
[8,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[9,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[10,] 0.07161804 0.26525199 0.12201592 -0.05570292 0.12997347 -0.10610080
[,7] [,8] [,9] [,10]
[1,] 0.22148541 0.27387268 0.12400531 0.07161804
[2,] 0.07957560 -0.07824934 0.10742706 0.26525199
[3,] 0.13660477 0.12400531 0.10941645 0.12201592
[4,] -0.11671088 -0.01856764 0.04244032 -0.05570292
[5,] -0.06100796 -0.12334218 0.06763926 0.12997347
[6,] -0.03183024 0.13129973 0.05702918 -0.10610080
[7,] 0.24933687 0.22148541 0.13660477 0.16445623
[8,] 0.22148541 0.27387268 0.12400531 0.07161804
[9,] 0.13660477 0.12400531 0.10941645 0.12201592
[10,] 0.16445623 0.07161804 0.12201592 0.21485411
P_Idem<-Matriz_P%*%Matriz_P
P_Idem
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[2,] -0.07824934 0.45092838 0.10742706 0.00530504 0.32095491 -0.18037135
[3,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[4,] -0.01856764 0.00530504 0.04244032 0.45888594 0.26259947 0.39787798
[5,] -0.12334218 0.32095491 0.06763926 0.26259947 0.38726790 0.07161804
[6,] 0.13129973 -0.18037135 0.05702918 0.39787798 0.07161804 0.47214854
[7,] 0.22148541 0.07957560 0.13660477 -0.11671088 -0.06100796 -0.03183024
[8,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[9,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[10,] 0.07161804 0.26525199 0.12201592 -0.05570292 0.12997347 -0.10610080
[,7] [,8] [,9] [,10]
[1,] 0.22148541 0.27387268 0.12400531 0.07161804
[2,] 0.07957560 -0.07824934 0.10742706 0.26525199
[3,] 0.13660477 0.12400531 0.10941645 0.12201592
[4,] -0.11671088 -0.01856764 0.04244032 -0.05570292
[5,] -0.06100796 -0.12334218 0.06763926 0.12997347
[6,] -0.03183024 0.13129973 0.05702918 -0.10610080
[7,] 0.24933687 0.22148541 0.13660477 0.16445623
[8,] 0.22148541 0.27387268 0.12400531 0.07161804
[9,] 0.13660477 0.12400531 0.10941645 0.12201592
[10,] 0.16445623 0.07161804 0.12201592 0.21485411
Orto_1<-Matriz_M%*%Matriz_P
Orto_1
[,1] [,2] [,3]
[1,] 0.00000000000001889599 0.000000000000014420236 0.00000000000001721228
[2,] 0.00000000000002962568 0.000000000000022007637 0.00000000000002701881
[3,] 0.00000000000002380546 0.000000000000020745070 0.00000000000002281771
[4,] 0.00000000000003159331 0.000000000000048546486 0.00000000000003701141
[5,] 0.00000000000003294601 0.000000000000038341787 0.00000000000003505414
[6,] 0.00000000000002637115 0.000000000000041658737 0.00000000000003213025
[7,] 0.00000000000001960597 0.000000000000009380148 0.00000000000001616231
[8,] 0.00000000000001888212 0.000000000000014420236 0.00000000000001723310
[9,] 0.00000000000002379852 0.000000000000020758948 0.00000000000002282812
[10,] 0.00000000000002463684 0.000000000000016216724 0.00000000000002139135
[,4] [,5] [,6]
[1,] 0.00000000000001824000 0.00000000000001559433 0.00000000000001972595
[2,] 0.00000000000002850278 0.00000000000002414041 0.00000000000003076444
[3,] 0.00000000000002333931 0.00000000000002148492 0.00000000000002444848
[4,] 0.00000000000003390295 0.00000000000004414451 0.00000000000002814613
[5,] 0.00000000000003374224 0.00000000000003697001 0.00000000000003185529
[6,] 0.00000000000002884460 0.00000000000003798125 0.00000000000002333443
[7,] 0.00000000000001812185 0.00000000000001201032 0.00000000000002162275
[8,] 0.00000000000001824000 0.00000000000001558739 0.00000000000001971207
[9,] 0.00000000000002332630 0.00000000000002147798 0.00000000000002444328
[10,] 0.00000000000002309146 0.00000000000001786037 0.00000000000002660757
[,7] [,8] [,9]
[1,] 0.00000000000001757744 0.00000000000001889599 0.00000000000001721228
[2,] 0.00000000000002744353 0.00000000000002962568 0.00000000000002701881
[3,] 0.00000000000002287741 0.00000000000002380546 0.00000000000002281771
[4,] 0.00000000000003669301 0.00000000000003159331 0.00000000000003701141
[5,] 0.00000000000003456724 0.00000000000003294601 0.00000000000003505414
[6,] 0.00000000000003093328 0.00000000000002637115 0.00000000000003213025
[7,] 0.00000000000001652911 0.00000000000001960597 0.00000000000001616231
[8,] 0.00000000000001759131 0.00000000000001888212 0.00000000000001723310
[9,] 0.00000000000002287741 0.00000000000002379852 0.00000000000002282812
[10,] 0.00000000000002201634 0.00000000000002463684 0.00000000000002139135
[,10]
[1,] 0.00000000000001589038
[2,] 0.00000000000002487849
[3,] 0.00000000000002191045
[4,] 0.00000000000004211295
[5,] 0.00000000000003663554
[6,] 0.00000000000003670912
[7,] 0.00000000000001310508
[8,] 0.00000000000001589385
[9,] 0.00000000000002189657
[10,] 0.00000000000001880158
Orto_2<-Matriz_M%*%Xregresor
Orto_2
Cte X1 X2
[1,] 0.0000000000002020745 0.000000000002975495 0.000000000008936449
[2,] 0.0000000000003875789 0.000000000005707435 0.000000000017117863
[3,] 0.0000000000001437739 0.000000000002118028 0.000000000006357082
[4,] 0.0000000000003383960 0.000000000004953690 0.000000000014856602
[5,] 0.0000000000003389511 0.000000000004974909 0.000000000014923840
[6,] 0.0000000000003813616 0.000000000005584561 0.000000000016753959
[7,] 0.0000000000002036149 0.000000000003007872 0.000000000009019285
[8,] 0.0000000000002020190 0.000000000002978159 0.000000000008932896
[9,] 0.0000000000001438294 0.000000000002118028 0.000000000006357082
[10,] 0.0000000000001469935 0.000000000002175371 0.000000000006519452
# Una matriz es simétrica si es una matriz cuadrada, la cual tiene la característica de ser igual a su traspuesta.Las matrices simétricas son un caso particular de las matrices hermíticas.
Matriz_P
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[2,] -0.07824934 0.45092838 0.10742706 0.00530504 0.32095491 -0.18037135
[3,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[4,] -0.01856764 0.00530504 0.04244032 0.45888594 0.26259947 0.39787798
[5,] -0.12334218 0.32095491 0.06763926 0.26259947 0.38726790 0.07161804
[6,] 0.13129973 -0.18037135 0.05702918 0.39787798 0.07161804 0.47214854
[7,] 0.22148541 0.07957560 0.13660477 -0.11671088 -0.06100796 -0.03183024
[8,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[9,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[10,] 0.07161804 0.26525199 0.12201592 -0.05570292 0.12997347 -0.10610080
[,7] [,8] [,9] [,10]
[1,] 0.22148541 0.27387268 0.12400531 0.07161804
[2,] 0.07957560 -0.07824934 0.10742706 0.26525199
[3,] 0.13660477 0.12400531 0.10941645 0.12201592
[4,] -0.11671088 -0.01856764 0.04244032 -0.05570292
[5,] -0.06100796 -0.12334218 0.06763926 0.12997347
[6,] -0.03183024 0.13129973 0.05702918 -0.10610080
[7,] 0.24933687 0.22148541 0.13660477 0.16445623
[8,] 0.22148541 0.27387268 0.12400531 0.07161804
[9,] 0.13660477 0.12400531 0.10941645 0.12201592
[10,] 0.16445623 0.07161804 0.12201592 0.21485411
Simetrica_P<-t(Matriz_P)
Simetrica_P
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[2,] -0.07824934 0.45092838 0.10742706 0.00530504 0.32095491 -0.18037135
[3,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[4,] -0.01856764 0.00530504 0.04244032 0.45888594 0.26259947 0.39787798
[5,] -0.12334218 0.32095491 0.06763926 0.26259947 0.38726790 0.07161804
[6,] 0.13129973 -0.18037135 0.05702918 0.39787798 0.07161804 0.47214854
[7,] 0.22148541 0.07957560 0.13660477 -0.11671088 -0.06100796 -0.03183024
[8,] 0.27387268 -0.07824934 0.12400531 -0.01856764 -0.12334218 0.13129973
[9,] 0.12400531 0.10742706 0.10941645 0.04244032 0.06763926 0.05702918
[10,] 0.07161804 0.26525199 0.12201592 -0.05570292 0.12997347 -0.10610080
[,7] [,8] [,9] [,10]
[1,] 0.22148541 0.27387268 0.12400531 0.07161804
[2,] 0.07957560 -0.07824934 0.10742706 0.26525199
[3,] 0.13660477 0.12400531 0.10941645 0.12201592
[4,] -0.11671088 -0.01856764 0.04244032 -0.05570292
[5,] -0.06100796 -0.12334218 0.06763926 0.12997347
[6,] -0.03183024 0.13129973 0.05702918 -0.10610080
[7,] 0.24933687 0.22148541 0.13660477 0.16445623
[8,] 0.22148541 0.27387268 0.12400531 0.07161804
[9,] 0.13660477 0.12400531 0.10941645 0.12201592
[10,] 0.16445623 0.07161804 0.12201592 0.21485411
Matriz_M
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.72612732 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[2,] 0.07824934 0.54907162 -0.10742706 -0.00530504 -0.32095491 0.18037135
[3,] -0.12400531 -0.10742706 0.89058355 -0.04244032 -0.06763926 -0.05702918
[4,] 0.01856764 -0.00530504 -0.04244032 0.54111406 -0.26259947 -0.39787798
[5,] 0.12334218 -0.32095491 -0.06763926 -0.26259947 0.61273210 -0.07161804
[6,] -0.13129973 0.18037135 -0.05702918 -0.39787798 -0.07161804 0.52785146
[7,] -0.22148541 -0.07957560 -0.13660477 0.11671088 0.06100796 0.03183024
[8,] -0.27387268 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[9,] -0.12400531 -0.10742706 -0.10941645 -0.04244032 -0.06763926 -0.05702918
[10,] -0.07161804 -0.26525199 -0.12201592 0.05570292 -0.12997347 0.10610080
[,7] [,8] [,9] [,10]
[1,] -0.22148541 -0.27387268 -0.12400531 -0.07161804
[2,] -0.07957560 0.07824934 -0.10742706 -0.26525199
[3,] -0.13660477 -0.12400531 -0.10941645 -0.12201592
[4,] 0.11671088 0.01856764 -0.04244032 0.05570292
[5,] 0.06100796 0.12334218 -0.06763926 -0.12997347
[6,] 0.03183024 -0.13129973 -0.05702918 0.10610080
[7,] 0.75066313 -0.22148541 -0.13660477 -0.16445623
[8,] -0.22148541 0.72612732 -0.12400531 -0.07161804
[9,] -0.13660477 -0.12400531 0.89058355 -0.12201592
[10,] -0.16445623 -0.07161804 -0.12201592 0.78514589
Simetrica_M<-t(Matriz_M)
Simetrica_M
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.72612732 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[2,] 0.07824934 0.54907162 -0.10742706 -0.00530504 -0.32095491 0.18037135
[3,] -0.12400531 -0.10742706 0.89058355 -0.04244032 -0.06763926 -0.05702918
[4,] 0.01856764 -0.00530504 -0.04244032 0.54111406 -0.26259947 -0.39787798
[5,] 0.12334218 -0.32095491 -0.06763926 -0.26259947 0.61273210 -0.07161804
[6,] -0.13129973 0.18037135 -0.05702918 -0.39787798 -0.07161804 0.52785146
[7,] -0.22148541 -0.07957560 -0.13660477 0.11671088 0.06100796 0.03183024
[8,] -0.27387268 0.07824934 -0.12400531 0.01856764 0.12334218 -0.13129973
[9,] -0.12400531 -0.10742706 -0.10941645 -0.04244032 -0.06763926 -0.05702918
[10,] -0.07161804 -0.26525199 -0.12201592 0.05570292 -0.12997347 0.10610080
[,7] [,8] [,9] [,10]
[1,] -0.22148541 -0.27387268 -0.12400531 -0.07161804
[2,] -0.07957560 0.07824934 -0.10742706 -0.26525199
[3,] -0.13660477 -0.12400531 -0.10941645 -0.12201592
[4,] 0.11671088 0.01856764 -0.04244032 0.05570292
[5,] 0.06100796 0.12334218 -0.06763926 -0.12997347
[6,] 0.03183024 -0.13129973 -0.05702918 0.10610080
[7,] 0.75066313 -0.22148541 -0.13660477 -0.16445623
[8,] -0.22148541 0.72612732 -0.12400531 -0.07161804
[9,] -0.13660477 -0.12400531 0.89058355 -0.12201592
[10,] -0.16445623 -0.07161804 -0.12201592 0.78514589
Xregresor
Cte X1 X2
[1,] 1 16 45
[2,] 1 14 42
[3,] 1 15 44
[4,] 1 13 45
[5,] 1 13 43
[6,] 1 14 46
[7,] 1 16 44
[8,] 1 16 45
[9,] 1 15 44
[10,] 1 15 43
Proyeccion_X<-Matriz_P%*%Xregresor
Proyeccion_X
Cte X1 X2
[1,] 1 16 45
[2,] 1 14 42
[3,] 1 15 44
[4,] 1 13 45
[5,] 1 13 43
[6,] 1 14 46
[7,] 1 16 44
[8,] 1 16 45
[9,] 1 15 44
[10,] 1 15 43
library(readr)
library(stargazer)
ejemplo_regresion <- read_csv("C:/Users/74/Desktop/BASES PARA R/R. Múltiple Ejercicicio.csv")
Parsed with column specification:
cols(
Mes = [31mcol_character()[39m,
`Impuestos reales` = [32mcol_double()[39m,
`Horas en Computadora` = [32mcol_double()[39m,
`Horas de trabajo` = [32mcol_double()[39m
)
modelo_lineal<-lm(Y~X1+X2,data = datos1)
stargazer(modelo_lineal,title = "modelo estimado",type = "text")
length of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changed
modelo estimado
===============================================
Dependent variable:
---------------------------
Y
-----------------------------------------------
X1 1.099***
(0.313)
X2 0.564
(0.303)
Constant -13.820
(13.323)
-----------------------------------------------
Observations 10
R2 0.729
Adjusted R2 0.651
Residual Std. Error 1.071 (df = 7)
F Statistic 9.411** (df = 2; 7)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
options(scipen=999)
modelo_lineal$coefficients
(Intercept) X1 X2
-13.8196286 1.0994695 0.5636605
Var_Covar<-vcov(modelo_lineal)
print(Var_Covar)
(Intercept) X1 X2
(Intercept) 177.5103201 -0.67042968 -3.79910152
X1 -0.6704297 0.09805604 -0.01748286
X2 -3.7991015 -0.01748286 0.09197505
confint(object = modelo_lineal,level = .95)
2.5 % 97.5 %
(Intercept) -45.3242267 17.684969
X1 0.3590134 1.839926
X2 -0.1534683 1.280789
plot(modelo_lineal$fitted.values,main = "Valores Ajustados",
ylab = "Y",xlab = "CASOS")
modelo_lineal$fitted.values %>% as.matrix()
[,1]
1 29.13660
2 25.24668
3 27.47347
4 25.83820
5 24.71088
6 27.50133
7 28.57294
8 29.13660
9 27.47347
10 26.90981
plot(modelo_lineal$residuals,main = "Residuos",
ylab = "RESIDUOS",xlab = "CASOS")
modelo_lineal$residuals %>% as.matrix()
[,1]
1 -0.13660477
2 -1.24668435
3 -0.47347480
4 -0.83819629
5 1.28912467
6 0.49867374
7 1.42705570
8 -1.13660477
9 0.52652520
10 0.09018568