#¿Como funciona fastGraph?

Presente unas pequeñas instrucciones para graficar un valor crítico y un “p-value” para las distribuciones Z,T, F, chi^2 y algunos ejemplos gráficos.

#Cargado datos

options(scipen = 999999)
library(wooldridge)
data(hprice1)
head(force(hprice1), n=5)
##   price assess bdrms lotsize sqrft colonial   lprice  lassess llotsize   lsqrft
## 1   300  349.1     4    6126  2438        1 5.703783 5.855359 8.720297 7.798934
## 2   370  351.5     3    9903  2076        1 5.913503 5.862210 9.200593 7.638198
## 3   191  217.7     3    5200  1374        0 5.252274 5.383118 8.556414 7.225482
## 4   195  231.8     3    4600  1448        1 5.273000 5.445875 8.433811 7.277938
## 5   373  319.1     4    6095  2514        1 5.921578 5.765504 8.715224 7.829630

#Estimando modelo

options(scipen = 999999)
library(stargazer)
modelo_inves<-lm(formula = price~bdrms+lotsize,data = hprice1)
stargazer(modelo_inves,title = "Modelo de investigacion",type = "text",digits = 6)
## 
## Modelo de investigacion
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                price           
## -----------------------------------------------
## bdrms                      57.312850***        
##                             (10.884530)        
##                                                
## lotsize                     0.002858***        
##                             (0.000900)         
##                                                
## Constant                     63.262240         
##                             (39.619570)        
##                                                
## -----------------------------------------------
## Observations                    88             
## R2                           0.336817          
## Adjusted R2                  0.321213          
## Residual Std. Error     84.624130 (df = 85)    
## F Statistic          21.584860*** (df = 2; 85) 
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01

#Graficando distribucion Z

options(scipen = 999999)
library(fastGraph)
shadeDist(qnorm(0.95), "dnorm", 0, 1, col = c("black","red")) 

shadeDist(qnorm(0.95), lower.tail=FALSE, col = c("black","red"))

#Graficando dstribucion T

options(scipen = 999999)
library(fastGraph)
coeficientes<-summary(modelo_inves)$coefficients
valor_t<-coeficientes[,"t value"]
nombres<-names(valor_t)
for(t in 2:3)
{t_critico<-valor_t[t]
#oteniendo valores criticos
print(confint(modelo_inves, parm = t,level = 0.90))
#graficar valor t
t_valor_critico<- shadeDist( c(-t_critico, t_critico ), "dt", 13,col=c("black","red"),sub=paste("valor t:",nombres[t]))}
##            5 %     95 %
## bdrms 39.21212 75.41358

##                 5 %        95 %
## lotsize 0.001361347 0.004355174

#Graficando distribucion F

options(scipen = 999999)
F_Anova<-summary(modelo_inves)$fstatistic[1]
gl_num<-summary(modelo_inves)$fstatistic[2]
gl_deno<-summary(modelo_inves)$fstatistic[3]
f_critico<-qf(0.90,gl_num,gl_deno,lower.tail = TRUE)
#graficando valor F
shadeDist(xshade =F_Anova,"df",gl_num,gl_deno,lower.tail = FALSE,col=c("black","red"), sub=paste("valor critico",f_critico,"F critico",F_Anova))

options(scipen = 999999)
library(fastGraph)
shadeDist(qchisq(0.1,25,lower.tail = FALSE),ddist = 'dchisq',parm1 = 25,lower.tail = FALSE, col=c("black","red"))

shadeDist(23,ddist = 'dchisq',parm1 = 25,lower.tail = FALSE,col=c("black","red"),sub=paste(c(qchisq(0.1,25,lower.tail = FALSE))))