Datos a utilizar

library(readxl)
ventas_empresa <- read_excel("C:/Users/MINEDUCYT/Desktop/GA24021/CicloI2026/ventas_empresa.xlsx")
head(ventas_empresa)
## # A tibble: 6 × 4
##       V     C     P     M
##   <dbl> <dbl> <dbl> <dbl>
## 1   607   197   173   110
## 2   590   208   152   107
## 3   543   181   150    99
## 4   558   194   150   102
## 5   571   192   163   109
## 6   615   196   179   114

Modelo a estimar

modelo_lineal<-lm(formula = V~C+P+M,data = ventas_empresa)
library(stargazer)
stargazer(modelo_lineal,title = "Modelo lineal",type = "text")
## 
## Modelo lineal
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                  V             
## -----------------------------------------------
## C                            0.923***          
##                               (0.223)          
##                                                
## P                            0.950***          
##                               (0.156)          
##                                                
## M                            1.298***          
##                               (0.431)          
##                                                
## Constant                    107.444***         
##                              (18.057)          
##                                                
## -----------------------------------------------
## Observations                    24             
## R2                             0.980           
## Adjusted R2                    0.977           
## Residual Std. Error       9.506 (df = 20)      
## F Statistic           323.641*** (df = 3; 20)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01

Pruebas de Normalidad

library(fitdistrplus)
#Prueba de Jarque Bera
library(tseries)
salida_JB<-jarque.bera.test(modelo_lineal$residuals)
salida_JB
## 
##  Jarque Bera Test
## 
## data:  modelo_lineal$residuals
## X-squared = 1.4004, df = 2, p-value = 0.4965
library(fastGraph)
alpha_sig<-0.05
JB<-salida_JB$statistic
g1<-salida_JB$parameter
VC<-qchisq(1-alpha_sig,g1,lower.tail = TRUE)
shadeDist(JB,ddist = "dchisq",parm1 = g1,lower.tail = FALSE,xmin = 0,sub=paste("VC:",round(VC,2),"","JB:",round(JB,2)))

#Prueba de Kolmogorov-Smirnov(Lilliefors)
library(nortest)
prueba_KS<-lillie.test(modelo_lineal$residuals)
prueba_KS
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  modelo_lineal$residuals
## D = 0.13659, p-value = 0.2935
#Prueba de Shapiro-Wilk
SW<-shapiro.test(modelo_lineal$residuals)
print(SW)
## 
##  Shapiro-Wilk normality test
## 
## data:  modelo_lineal$residuals
## W = 0.95315, p-value = 0.3166
library(fastGraph)
shadeDist(SW$statitic,ddist = "dnorm",lower.tail = FALSE,xmin = 0)

Para la prueba Jarque Bera Como 0.4965>0.05, no se rechaza la hipótesis nula, por lo que existe evidencia estadística de que los residuos se distribuyen normalmente

Para la prueba Shapiro-Wilk Dado que 0.3166>0.05, no se rechaza la hipótesis nula de normalidad.

Pruebas de Multicolinealidad

#Prueba de Farrar-Glaubar(FG)
library(mctest)
mctest::omcdiag(mod = modelo_lineal)
## 
## Call:
## mctest::omcdiag(mod = modelo_lineal)
## 
## 
## Overall Multicollinearity Diagnostics
## 
##                        MC Results detection
## Determinant |X'X|:         0.0346         0
## Farrar Chi-Square:        71.2080         1
## Red Indicator:             0.8711         1
## Sum of Lambda Inverse:    20.9196         1
## Theil's Method:            0.5430         1
## Condition Number:         71.1635         1
## 
## 1 --> COLLINEARITY is detected by the test 
## 0 --> COLLINEARITY is not detected by the test
library(fastGraph)
shadeDist(5,ddist = "dchisq",parm1 = 4,lower.tail = FALSE)

#Prueba de Factores Inflacionarios de la varianza(VIF)

library(car) #Usando libreria "car"
VIFs<-vif(modelo_lineal)
print(VIFs)
##        C        P        M 
## 7.631451 3.838911 9.449210
library(performance)#Usando libreria "performace"
VIFs<-multicollinearity(modelo_lineal,verbose = FALSE)
VIFs
## # Check for Multicollinearity
## 
## Low Correlation
## 
##  Term  VIF    VIF 95% CI adj. VIF Tolerance Tolerance 95% CI
##     P 3.84 [2.41,  6.73]     1.96      0.26     [0.15, 0.42]
## 
## Moderate Correlation
## 
##  Term  VIF    VIF 95% CI adj. VIF Tolerance Tolerance 95% CI
##     C 7.63 [4.49, 13.61]     2.76      0.13     [0.07, 0.22]
##     M 9.45 [5.49, 16.91]     3.07      0.11     [0.06, 0.18]
plot(VIFs)

La prueba de Farrar-Glauber permite verificar la existencia conjunta de multicolinealidad entre las variables explicativas.Como el estadístico de prueba no se encuentra dentro de la región crítica, no se rechaza la hipótesis nula, concluyéndose que no existe evidencia significativa de multicolinealidad.

Supuesto de Homocedasticicdad

#Prueba de White
library(lmtest)
white<-bptest(modelo_lineal,~I(C^2)+I(P^2)+I(M^2)+C*P+C*M+P*M,data = ventas_empresa)
print(white)
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo_lineal
## BP = 7.1227, df = 9, p-value = 0.6244
library(fastGraph)
alpha_sig<-0.05
White<-white$statistic
gl<-white$parameter
shadeDist(White,ddist = "dchisq",parm1 = gl,lower.tail = FALSE)

Como 0.6244>0.05 No se rechaza la H0,Por lo tanto, no existe evidencia estadística de heterocedasticidad en el modelo.

Supesto de autocorrelación

library(lmtest)
BG1<-bgtest(modelo_lineal,order = 1)
print(BG1)
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  modelo_lineal
## LM test = 2.5963, df = 1, p-value = 0.1071
BG2<-bgtest(modelo_lineal,order = 2)
print(BG2)
## 
##  Breusch-Godfrey test for serial correlation of order up to 2
## 
## data:  modelo_lineal
## LM test = 3.8409, df = 2, p-value = 0.1465
library(fastGraph)
shadeDist(BG1$statistic,
          ddist="dchisq",
          parm1=qchisq(0.95, df=1),
          lower.tail=FALSE,
          main="BG Orden 1")

shadeDist(BG2$statistic,
          ddist="dchisq",
          parm1=qchisq(0.95, df=2),
          lower.tail=FALSE,
          main="BG Orden 2")

La prueba Breusch-Godfrey de primer orden evalúa la existencia de autocorrelación serial en los residuos.Dado que 0.1071>0.05, no se rechaza la hipótesis nula de ausencia de autocorrelación.Por lo tanto, no existe evidencia de autocorrelación de primer orden en el modelo.

La prueba Breusch-Godfrey de segundo orden permite verificar autocorrelación serial de orden superior.Como 0.1465>0.05, no se rechaza la hipótesis nula de no autocorrelación.En consecuencia, no existe evidencia estadística de autocorrelación de segundo orden en el modelo.