options(scipen = 999999)
library(readxl)
library(stargazer)
ventas_empresa <- read_excel("C:/Users/Osiel/Desktop/LAB 3 ECO/ventas_empresa.xlsx")
#ejesutando regresion
Regresion1<-lm(formula = V~C+P+M, data = ventas_empresa)
stargazer(Regresion1, title = "Ventas de Empresa", type = "html", digits = 6)
| Dependent variable: | |
| V | |
| C | 0.922567*** |
| (0.222733) | |
| P | 0.950177*** |
| (0.155845) | |
| M | 1.297786*** |
| (0.430729) | |
| Constant | 107.443500*** |
| (18.057490) | |
| Observations | 24 |
| R2 | 0.979817 |
| Adjusted R2 | 0.976789 |
| Residual Std. Error | 9.505570 (df = 20) |
| F Statistic | 323.641500*** (df = 3; 20) |
| Note: | p<0.1; p<0.05; p<0.01 |
# Creando residuales
library(stargazer)
residuos_1<-Regresion1$residuals
#Creando regresion auxiliar
data_PW_1<-as.data.frame(cbind(residuos_1,ventas_empresa))
Reg_aux_1<-lm(I(residuos_1^2)~C+P+M+I(C^2)+I(P^2)+I(M^2)+(C*P)+(C*M)+(P*M),
data = data_PW_1)
#coeficiente de determinacion
resumen_1<-summary(Reg_aux_1)
R2_1<-resumen_1$r.squared
n_1<-nrow(data_PW_1)
#estadistico de prueba
LM_w_1<-n_1*R2_1
#Grados de libertad
gl_1<-3+3+3
#Valor critico
VC_1<-qchisq(p=0.95,df=gl_1)
#pivalue
p_value_1<-1-pchisq(q =LM_w_1, df = gl_1)
salida_1<- c(LM_w_1, VC_1, p_value_1)
names(salida_1)<-c("LMw","Valor Critico","P value")
stargazer(salida_1, title = "Prueba de White", type = "html", digits = 6)
| LMw | Valor Critico | P value |
| 7.122650 | 16.918980 | 0.624351 |
library(lmtest)
PW_1<-bptest(Regresion1,~I(C^2)+I(P^2)+I(M^2)+(C*P)+(C*M)+(P*M), data = ventas_empresa)
print(PW_1)
##
## studentized Breusch-Pagan test
##
## data: Regresion1
## BP = 7.1227, df = 9, p-value = 0.6244
Conclusion:La Ho: Hay evidencia de que la varianza de los residuos es Homocedastica, No se rechaza, el estadistico (7.1227) no es mayor al VC (16.918), No hay evidencia de Heterocedasticidad.
library(lmtest)
bgtest(Regresion1,order = 2)
##
## Breusch-Godfrey test for serial correlation of order up to 2
##
## data: Regresion1
## LM test = 3.8409, df = 2, p-value = 0.1465
conclusion: el Pvalue es mayor al nivel de significacion la Ho no se rechaza, los residuos no siguen autocorrelacion de segundo orden.
library(lmtest)
dwtest(Regresion1,alternative = "two.side", iterations = 1000)
##
## Durbin-Watson test
##
## data: Regresion1
## DW = 1.2996, p-value = 0.05074
## alternative hypothesis: true autocorrelation is not 0
Conclusion: En base a la tabla el resultado es no concluente.
library(lmtest)
bgtest(Regresion1,order = 1)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: Regresion1
## LM test = 2.5963, df = 1, p-value = 0.1071
conclusion: el Pvalue es mayor al nivel de significacion la Ho no se rechaza, los residuos no siguen autocorrelacion de primer orden.
options(scipen = 999999)
library(stargazer)
load("C:/Users/Osiel/Desktop/LAB 3 ECO/wage2.Rdata")
#ejesutando regresion
Regresion2<-lm(formula = educ~sibs+meduc+feduc, data = wage2)
stargazer(Regresion2, title = "Años de escolaridad en empleados Hombres", type = "html", digits = 6)
| Dependent variable: | |
| educ | |
| sibs | -0.093636*** |
| (0.034471) | |
| meduc | 0.130787*** |
| (0.032689) | |
| feduc | 0.210004*** |
| (0.027475) | |
| Constant | 10.364260*** |
| (0.358500) | |
| Observations | 722 |
| R2 | 0.214094 |
| Adjusted R2 | 0.210810 |
| Residual Std. Error | 1.987052 (df = 718) |
| F Statistic | 65.198250*** (df = 3; 718) |
| Note: | p<0.1; p<0.05; p<0.01 |
library(lmtest)
PW_2<-bptest(Regresion2,~I(sibs^2)+I(meduc^2)+I(feduc^2)+(sibs*meduc)+(sibs*feduc)+(meduc*feduc), data = wage2)
print(PW_2)
##
## studentized Breusch-Pagan test
##
## data: Regresion2
## BP = 15.537, df = 9, p-value = 0.0772
#Valor critico
gl_2<-9
VC_2<-qchisq(p=0.95,df=gl_2)
print(VC_2)
## [1] 16.91898
Conclusion:La Ho: Hay evidencia de que la varianza de los residuos es Homocedastica, No se rechaza, el estadistico (15.537) no es mayor al VC (16.918), No hay evidencia de Heterocedasticidad.
library(lmtest)
bgtest(Regresion2,order = 2)
##
## Breusch-Godfrey test for serial correlation of order up to 2
##
## data: Regresion2
## LM test = 4.5747, df = 2, p-value = 0.1015
conclusion: el Pvalue es mayor al nivel de significacion la Ho no se rechaza, los residuos no siguen autocorrelacion de segundo orden.
library(lmtest)
dwtest(Regresion2,alternative = "two.side", iterations = 1000)
##
## Durbin-Watson test
##
## data: Regresion2
## DW = 1.8989, p-value = 0.1705
## alternative hypothesis: true autocorrelation is not 0
Conclusion: El resultado es no concluente.
library(lmtest)
bgtest(Regresion2,order = 1)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: Regresion2
## LM test = 1.8207, df = 1, p-value = 0.1772
conclusion: el Pvalue es mayor al nivel de significacion la Ho no se rechaza, los residuos no siguen autocorrelacion de primer orden.
options(scipen = 999999)
library(stargazer)
load("C:/Users/Osiel/Desktop/LAB 3 ECO/LAWSCH85.Rdata")
#creando Modelo
Regresion3<-lm(lsalary~LSAT+GPA+llibvol+lcost+rank, data = LAWSCH85)
stargazer(Regresion3, title = "Sueldo Inicial Medio", type = "html", digits = 6)
| Dependent variable: | |
| lsalary | |
| LSAT | 0.004696 |
| (0.004010) | |
| GPA | 0.247524*** |
| (0.090037) | |
| llibvol | 0.094993*** |
| (0.033254) | |
| lcost | 0.037554 |
| (0.032106) | |
| rank | -0.003325*** |
| (0.000348) | |
| Constant | 8.343226*** |
| (0.532519) | |
| Observations | 136 |
| R2 | 0.841685 |
| Adjusted R2 | 0.835596 |
| Residual Std. Error | 0.112412 (df = 130) |
| F Statistic | 138.229800*** (df = 5; 130) |
| Note: | p<0.1; p<0.05; p<0.01 |
library(lmtest)
PW_3<-bptest(Regresion3,~I(LSAT^2)+I(GPA^2)+I(llibvol^2)+I(lcost^2)+I(rank^2)+
(LSAT*GPA)+(LSAT*llibvol)+(LSAT*lcost)+(LSAT*rank)+(GPA*llibvol)+(GPA*lcost)+(GPA*rank)+(llibvol*lcost)+(llibvol*rank)+(lcost*rank), data = LAWSCH85)
print(PW_3)
##
## studentized Breusch-Pagan test
##
## data: Regresion3
## BP = 34.295, df = 20, p-value = 0.0242
#Valor critico
gl_3<-20
VC_3<-qchisq(p=0.95,df=gl_3)
print(VC_3)
## [1] 31.41043
conclusion:La Ho: Hay evidencia de que la varianza de los residuos es Homocedastica, se rechaza, el estadistico (34.295) es mayor al VC (31.41043), hay evidencia de Heterocedasticidad.
library(lmtest)
bgtest(Regresion3,order = 2)
##
## Breusch-Godfrey test for serial correlation of order up to 2
##
## data: Regresion3
## LM test = 3.2116, df = 2, p-value = 0.2007
conclusion: el Pvalue es mayor al nivel de significacion la Ho no se rechaza, los residuos no siguen autocorrelacion de segundo orden.
library(lmtest)
dwtest(Regresion3,alternative = "two.side", iterations = 1000)
##
## Durbin-Watson test
##
## data: Regresion3
## DW = 1.7058, p-value = 0.07519
## alternative hypothesis: true autocorrelation is not 0
Conclusion: El resultado es no concluente.
library(car)
durbinWatsonTest(Regresion1, simulate = TRUE, reps = 1000)
## lag Autocorrelation D-W Statistic p-value
## 1 0.3013888 1.299572 0.054
## Alternative hypothesis: rho != 0
library(lmtest)
bgtest(Regresion3,order = 1)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: Regresion3
## LM test = 2.9379, df = 1, p-value = 0.08652
conclusion: el Pvalue es mayor al nivel de significacion la Ho no se rechaza, los residuos no siguen autocorrelacion de primer orden.
options(scipen = 999999)
library(stargazer)
library(lmtest)
library(sandwich)
estimacion_omega<-vcovHC(Regresion3, type= "HC0")
coeftest(Regresion3, vcov. = estimacion_omega)->Regresion3_corregida
stargazer(Regresion3_corregida, title = "Sueldo Inicial Medio", type = "html", digits = 6)
| Dependent variable: | |
| LSAT | 0.004696 |
| (0.004476) | |
| GPA | 0.247524*** |
| (0.088615) | |
| llibvol | 0.094993*** |
| (0.027039) | |
| lcost | 0.037554 |
| (0.032589) | |
| rank | -0.003325*** |
| (0.000301) | |
| Constant | 8.343226*** |
| (0.509828) | |
| Note: | p<0.1; p<0.05; p<0.01 |