library(paqueteMETODOS)
## Cargando paquete requerido: dplyr
## 
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Cargando paquete requerido: ggplot2
library(nortest)
data(biomasa)
modelo=lm(bio_total ~ diametro, data=biomasa)
summary(modelo)
## 
## Call:
## lm(formula = bio_total ~ diametro, data = biomasa)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.3775 -2.6594  0.0237  1.8758 11.9876 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -9.0203     1.4129  -6.384 7.86e-09 ***
## diametro      5.1026     0.2508  20.346  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.435 on 88 degrees of freedom
## Multiple R-squared:  0.8247, Adjusted R-squared:  0.8227 
## F-statistic:   414 on 1 and 88 DF,  p-value: < 2.2e-16

lm(formula = log(bio_total) ~ diametro, data = biomasa)

Este resultado muestra el valor del coeficiente de determinación (R2) que corresponde al porcentaje de la variabilidad de Y explicada por el modelo. Para el ejemplo R2=0.8227 indicando que el modelo explica un 82.27% de la variación de Y.

par(mfrow=c(2,2))
plot(modelo)

### Test de Shapiro

shapiro.test(modelo$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  modelo$residuals
## W = 0.95356, p-value = 0.002793

Test de Anderson-Darling

nortest::ad.test(modelo$residuals)
## 
##  Anderson-Darling normality test
## 
## data:  modelo$residuals
## A = 0.86658, p-value = 0.02517

Test de Lilliefors (Kolmogorov-Smirnov)

lillie.test(modelo$residuals)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  modelo$residuals
## D = 0.078633, p-value = 0.1856

Varianza contante

Test de Breusch-Pagan

lmtest::bptest(modelo)
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo
## BP = 11.76, df = 1, p-value = 0.0006052

Test de Goldfeld-Quandt

lmtest::gqtest(modelo)
## 
##  Goldfeld-Quandt test
## 
## data:  modelo
## GQ = 2.0131, df1 = 43, df2 = 43, p-value = 0.01196
## alternative hypothesis: variance increases from segment 1 to 2

No autocorrelación de errores

Test de Durbin-Watson

lmtest::dwtest(modelo)
## 
##  Durbin-Watson test
## 
## data:  modelo
## DW = 1.0719, p-value = 1.035e-06
## alternative hypothesis: true autocorrelation is greater than 0

Transformación de variables

library(paqueteMETODOS)
data("biomasa")
modelo1=lm(bio_total ~ diametro, data=biomasa)           # Lin - Lin
modelo2=lm(bio_total ~ log(diametro), data=biomasa)      # Lin - Log
modelo3=lm(log(bio_total) ~ diametro, data=biomasa)      # Log - Lin
modelo4=lm(log(bio_total) ~ log(diametro), data=biomasa) # Log - Log
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
stargazer(modelo1, modelo2, modelo3, modelo4, type="text", df=FALSE)
## 
## ===============================================================
##                                 Dependent variable:            
##                     -------------------------------------------
##                           bio_total          log(bio_total)    
##                        (1)        (2)        (3)        (4)    
## ---------------------------------------------------------------
## diametro             5.103***              0.278***            
##                      (0.251)               (0.011)             
##                                                                
## log(diametro)                  23.369***              1.344*** 
##                                 (1.564)               (0.058)  
##                                                                
## Constant            -9.020***  -19.909***  1.328***   0.618*** 
##                      (1.413)    (2.629)    (0.060)    (0.098)  
##                                                                
## ---------------------------------------------------------------
## Observations            90         90         90         90    
## R2                    0.825      0.717      0.887      0.858   
## Adjusted R2           0.823      0.714      0.885      0.857   
## Residual Std. Error   3.435      4.362      0.145      0.162   
## F Statistic         413.961*** 223.224*** 687.562*** 532.232***
## ===============================================================
## Note:                               *p<0.1; **p<0.05; ***p<0.01

Los mejores indicadores los tiene el modelo (3) : log - lin

() = 1.328 + 0.278 _i ]