R<-matrix(data = c(1,0.96,
0.96,1),
nrow = 2,
ncol = 2,byrow = TRUE)
print(R)
## [,1] [,2]
## [1,] 1.00 0.96
## [2,] 0.96 1.00
VIF<-diag(solve(R))
print(VIF)
## [1] 12.7551 12.7551
options(scipen = 999999)
Estadistico<-40
n<-60
m<-5
A<--(n-1-(2*m+5)/6)
Deter_R<-exp(Estadistico*solve(A))
print(Deter_R)
## [,1]
## [1,] 0.4926459
VIF2.5<-2.5
R<-(VIF2.5-1)/VIF2.5
print(R)
## [1] 0.6
residuosKS<-matrix(data = c(10,15,-10,-15,4,-4),
nrow = 6,
ncol = 1,byrow = TRUE)
colnames(residuosKS) <-c("Residuos")
print(residuosKS)
## Residuos
## [1,] 10
## [2,] 15
## [3,] -10
## [4,] -15
## [5,] 4
## [6,] -4
## Prueba de KS (lilliefore)
library(nortest)
lillie.test(residuosKS)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: residuosKS
## D = 0.1374, p-value = 0.9763
# Calcular el valor critico
#m es igualo al numero de variables explicativas
m<-5 #cantidad de variables explicativas K-1 pero en este caso nos da los regresores
gl<-m*(m-1)/2
VC<-qchisq(0.043,gl,lower.tail = FALSE)
print(VC)
## [1] 18.79093
residuosJB<-matrix(data = c(10,15,-10,-15,4,-4),
nrow = 6,
ncol = 1,byrow = TRUE)
colnames(residuosJB) <-c("Residuos_JB")
print(residuosJB)
## Residuos_JB
## [1,] 10
## [2,] 15
## [3,] -10
## [4,] -15
## [5,] 4
## [6,] -4
## Prueba de JB
library(normtest)
jb.norm.test(residuosJB)
##
## Jarque-Bera test for normality
##
## data: residuosJB
## JB = 0.51072, p-value = 0.59
Tolerancia<-0.05
VIF<-1/Tolerancia
print(VIF)
## [1] 20
residuosSW<-matrix(data = c(10,15,-10,-15,4,-4),
nrow = 6,
ncol = 1,byrow = TRUE)
colnames(residuosSW) <-c("Residuos_SW")
print(residuosSW)
## Residuos_SW
## [1,] 10
## [2,] 15
## [3,] -10
## [4,] -15
## [5,] 4
## [6,] -4
## Prueba de shapiro wilk
shapiro.test(residuosSW)
##
## Shapiro-Wilk normality test
##
## data: residuosSW
## W = 0.96164, p-value = 0.8323
Vif1<-2.5
tolerancia1<-1/Vif1
print(tolerancia1)
## [1] 0.4
library(dplyr)
load("C:/Users/Admin/Downloads/LAWSCH85.RData")
modelo_regresion<-lm(lsalary~LSAT+GPA+llibvol+lcost+rank,data = LAWSCH85)
summary(modelo_regresion)
##
## Call:
## lm(formula = lsalary ~ LSAT + GPA + llibvol + lcost + rank, data = LAWSCH85)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.301356 -0.084982 -0.004359 0.077935 0.288614
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.3432260 0.5325192 15.667 < 0.0000000000000002 ***
## LSAT 0.0046965 0.0040105 1.171 0.24372
## GPA 0.2475239 0.0900370 2.749 0.00683 **
## llibvol 0.0949932 0.0332543 2.857 0.00499 **
## lcost 0.0375538 0.0321061 1.170 0.24427
## rank -0.0033246 0.0003485 -9.541 < 0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1124 on 130 degrees of freedom
## (20 observations deleted due to missingness)
## Multiple R-squared: 0.8417, Adjusted R-squared: 0.8356
## F-statistic: 138.2 on 5 and 130 DF, p-value: < 0.00000000000000022
library(normtest)
jb.norm.test(modelo_regresion$residuals)
##
## Jarque-Bera test for normality
##
## data: modelo_regresion$residuals
## JB = 0.36511, p-value = 0.8105
library(nortest)
lillie.test(modelo_regresion$residuals)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: modelo_regresion$residuals
## D = 0.054571, p-value = 0.4123
shapiro.test(modelo_regresion$residuals)
##
## Shapiro-Wilk normality test
##
## data: modelo_regresion$residuals
## W = 0.99282, p-value = 0.7235
miu <- 0.0038915*((log(156))^3)-0.083751*((log(156))^2)-0.31082*(log(156))-1.5861
sigma <- exp(1)^((0.0030302*(log(156)^2))-0.082676*(log(156))-0.4803)
Wn <- (log(1-0.992821)-miu)/sigma
print(Wn)
## [1] -0.3323385
library(mctest)
source(file = "C:/Users/Admin/Downloads/correccion_eigprop (1).R")
my_eigprop(mod = modelo_regresion)
##
## Call:
## my_eigprop(mod = modelo_regresion)
##
## Eigenvalues CI (Intercept) LSAT GPA llibvol lcost rank
## 1 5.7351 1.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0021
## 2 0.2604 4.6930 0.0000 0.0000 0.0002 0.0004 0.0001 0.2884
## 3 0.0021 52.4800 0.0058 0.0030 0.0007 0.8411 0.1155 0.1357
## 4 0.0018 55.7648 0.0002 0.0010 0.3355 0.1095 0.1756 0.0161
## 5 0.0004 123.2068 0.4254 0.0588 0.4407 0.0423 0.6610 0.4700
## 6 0.0002 186.7153 0.5686 0.9371 0.2229 0.0066 0.0478 0.0877
##
## ===============================
## Row 6==> LSAT, proportion 0.937119 >= 0.50
## Row 3==> llibvol, proportion 0.841136 >= 0.50
## Row 5==> lcost, proportion 0.661004 >= 0.50
options(scipen = 999999)
# calcular Mat_x
matriz_x<-model.matrix(modelo_regresion)
m_1<-ncol(matriz_x[,-1])
n_1<-nrow(matriz_x[,-1])
# determinante de R forma fácil
determinante_R_1<-det(cor(matriz_x[,-1]))
# estadistico FG
Chi_FG_1<--(n_1-1-(2*m_1+5)/6)*log(determinante_R_1)
print(Chi_FG_1)
## [1] 391.509
# Valor critico
gl_1<-m_1*(m_1-1)/2
VC_1<-qchisq(0.05,gl_1,lower.tail = FALSE)
print(VC_1)
## [1] 18.30704
library(car)
VIF_car_1<-vif(modelo_regresion)
print(VIF_car_1)
## LSAT GPA llibvol lcost rank
## 3.635214 3.369004 2.110802 1.573583 3.124106
library(mctest)
mc.plot(modelo_regresion,vif = 2)
#0 Carga de datos.
options(scipen = 999999)
library(readxl)
ventas_empresa <- read_excel("C:/Users/Admin/Downloads/ventas_empresa.xlsx")
modelo_estimado_ventas <- lm(formula = V~C+P+M, data = ventas_empresa)
summary(modelo_estimado_ventas)
##
## Call:
## lm(formula = V ~ C + P + M, data = ventas_empresa)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.279 -6.966 1.555 6.721 14.719
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 107.4435 18.0575 5.950 0.00000808 ***
## C 0.9226 0.2227 4.142 0.000505 ***
## P 0.9502 0.1558 6.097 0.00000586 ***
## M 1.2978 0.4307 3.013 0.006872 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.506 on 20 degrees of freedom
## Multiple R-squared: 0.9798, Adjusted R-squared: 0.9768
## F-statistic: 323.6 on 3 and 20 DF, p-value: < 0.00000000000000022
library(normtest)
jb.norm.test(modelo_estimado_ventas$residuals)
##
## Jarque-Bera test for normality
##
## data: modelo_estimado_ventas$residuals
## JB = 1.4004, p-value = 0.278
library(nortest)
lillie.test(modelo_estimado_ventas$residuals)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: modelo_estimado_ventas$residuals
## D = 0.13659, p-value = 0.2935
shapiro.test(modelo_estimado_ventas$residuals)
Shapiro-Wilk normality test
data: modelo_estimado_ventas$residuals W = 0.95315, p-value = 0.3166
miu2 <- 0.0038915*((log(24))^3)-0.083751*((log(24))^2)-0.31082*(log(24))-1.5861
sigma2 <- exp(1)^((0.0030302*(log(24)^2))-0.082676*(log(24))-0.4803)
Wn_2 <- (log(1-0.95315)-miu2)/sigma2
print(Wn_2)
[1] 0.4772707
library(mctest)
source(file = "C:/Users/Admin/Downloads/correccion_eigprop (1).R")
my_eigprop(mod = modelo_estimado_ventas)
##
## Call:
## my_eigprop(mod = modelo_estimado_ventas)
##
## Eigenvalues CI (Intercept) C P M
## 1 3.9869 1.0000 0.0007 0.0001 0.0003 0.0001
## 2 0.0095 20.4852 0.8776 0.0049 0.0877 0.0075
## 3 0.0028 37.8141 0.1183 0.1594 0.8478 0.0636
## 4 0.0008 71.1635 0.0034 0.8356 0.0642 0.9288
##
## ===============================
## Row 4==> C, proportion 0.835554 >= 0.50
## Row 3==> P, proportion 0.847805 >= 0.50
## Row 4==> M, proportion 0.928751 >= 0.50
# prueba de FG manual
options(scipen = 999999)
# calcular Mat_x
matriz_x_2<-model.matrix(modelo_estimado_ventas)
m2<-ncol(matriz_x_2[,-1])
n2<-nrow(matriz_x_2[,-1])
# determinante de R forma fácil
determinante_R_2<-det(cor(matriz_x_2[,-1]))
# estadistico FG
Chi_FG_2<--(n2-1-(2*m2+5)/6)*log(determinante_R_2)
print(Chi_FG_2)
## [1] 71.20805
# Valor critico
gl_2<-m2*(m2-1)/2
VC_2<-qchisq(0.05,gl_2,lower.tail = FALSE)
print(VC_2)
## [1] 7.814728
library(car)
VIF_Car_2 <- vif(modelo_estimado_ventas)
print(VIF_Car_2)
## C P M
## 7.631451 3.838911 9.449210
mc.plot(mod = modelo_estimado_ventas, vif = 2)
library(dplyr)
load("C:/Users/Admin/Downloads/wage2.RData")
modelo_regresion_edu<-lm(educ~sibs+meduc+feduc,data = wage2)
summary(modelo_regresion_edu)
##
## Call:
## lm(formula = educ ~ sibs + meduc + feduc, data = wage2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.0906 -1.5957 -0.3677 1.6138 5.6103
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.36426 0.35850 28.910 < 0.0000000000000002 ***
## sibs -0.09364 0.03447 -2.716 0.00676 **
## meduc 0.13079 0.03269 4.001 0.0000696319512857 ***
## feduc 0.21000 0.02747 7.644 0.0000000000000679 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.987 on 718 degrees of freedom
## (213 observations deleted due to missingness)
## Multiple R-squared: 0.2141, Adjusted R-squared: 0.2108
## F-statistic: 65.2 on 3 and 718 DF, p-value: < 0.00000000000000022
library(normtest)
jb.norm.test(modelo_regresion_edu$residuals)
##
## Jarque-Bera test for normality
##
## data: modelo_regresion_edu$residuals
## JB = 35.655, p-value < 0.00000000000000022
library(nortest)
lillie.test(modelo_regresion_edu$residuals)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: modelo_regresion_edu$residuals
## D = 0.089992, p-value = 0.000000000000003394
shapiro.test(modelo_regresion_edu$residuals)
##
## Shapiro-Wilk normality test
##
## data: modelo_regresion_edu$residuals
## W = 0.96692, p-value = 0.00000000001058
miu_3 <- 0.0038915*((log(935))^3)-0.083751*((log(935))^2)-0.31082*(log(935))-1.5861
sigma_3 <- exp(1)^((0.0030302*(log(935)^2))-0.082676*(log(935))-0.4803)
Wn_3 <- (log(1-0.96692)-miu_3)/sigma_3
print(Wn_3)
## [1] 7.351479
library(mctest)
source(file = "C:/Users/Admin/Downloads/correccion_eigprop (1).R")
my_eigprop(mod = modelo_regresion_edu)
##
## Call:
## my_eigprop(mod = modelo_regresion_edu)
##
## Eigenvalues CI (Intercept) sibs meduc feduc
## 1 3.5576 1.0000 0.0033 0.0194 0.0031 0.0046
## 2 0.3756 3.0778 0.0015 0.7200 0.0107 0.0184
## 3 0.0417 9.2337 0.3235 0.1056 0.0813 0.8786
## 4 0.0251 11.9094 0.6717 0.1549 0.9049 0.0984
##
## ===============================
## Row 2==> sibs, proportion 0.720032 >= 0.50
## Row 4==> meduc, proportion 0.904919 >= 0.50
## Row 3==> feduc, proportion 0.878599 >= 0.50
options(scipen = 999999)
# calcular Mat_x
matriz_x_3<-model.matrix(modelo_regresion_edu)
m_3<-ncol(matriz_x_3[,-1])
n_3<-nrow(matriz_x_3[,-1])
# determinante de R forma fácil
determinante_R_3<-det(cor(matriz_x_3[,-1]))
# estadistico FG
Chi_FG_3<--(n_3-1-(2*m_3+5)/6)*log(determinante_R_3)
print(Chi_FG_3)
## [1] 358.3897
# Valor critico
gl_3<-m_3*(m_3-1)/2
VC_3<-qchisq(0.05,gl_3,lower.tail = FALSE)
print(VC_3)
## [1] 7.814728
library(car)
VIF_car_3<-vif(modelo_regresion_edu)
print(VIF_car_3)
## sibs meduc feduc
## 1.098950 1.561254 1.506359
library(mctest)
mc.plot(modelo_regresion_edu,vif = 2)