Warning: package 'dplyr' was built under R version 4.4.2
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
Interpretación: Las variables x1, x2 y x3 tienen una dispersión que pueda seguir un comportamiento lineal con pendiente negativa respecto a y. Las variables x4, x5 y x6 no tienen un comportamiento definido.
Calculamos las correlaciones
# df <- dat %>% select(x1,x6, y)# graficando las variables# plot(df$x1, df$y, pch=19, col=2,las=1)library("PerformanceAnalytics")
Warning: package 'PerformanceAnalytics' was built under R version 4.4.2
Cargando paquete requerido: xts
Warning: package 'xts' was built under R version 4.4.2
Cargando paquete requerido: zoo
Adjuntando el paquete: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
######################### Warning from 'xts' package ##########################
# #
# The dplyr lag() function breaks how base R's lag() function is supposed to #
# work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
# source() into this session won't work correctly. #
# #
# Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
# conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
# dplyr from breaking base R's lag() function. #
# #
# Code in packages is not affected. It's protected by R's namespace mechanism #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
# #
###############################################################################
Adjuntando el paquete: 'xts'
The following objects are masked from 'package:dplyr':
first, last
Adjuntando el paquete: 'PerformanceAnalytics'
The following object is masked from 'package:graphics':
legend
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Interpretación: Siguiendo lo mensionado anteriormento, ahora con valores numericos, las 3 primeras variables tienen una alta correlación inversa, mientras que las otras variables tienen una correlación baja a media.
# la matrix X conocida como matriz del modelo X=model.matrix(~x1+x6, data=dat); X
El modelo de regresión ajustado es dado por \[
y = 32.8846 - 0.0531 x_1 + 0.9522 x_6
\]
Call:
lm(formula = y ~ x1 + x6, data = dat)
Coefficients:
(Intercept) x1 x6
32.88455 -0.05315 0.95922
Analysis of Variance Table
Model 1: y ~ 1
Model 2: y ~ x1 + x6
Res.Df RSS Df Sum of Sq F Pr(>F)
1 31 1237.54
2 29 263.23 2 974.31 53.669 1.79e-10 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Interpretación: Observando el p-value tenemos fuertes evidencias al nivel de confianza 0.001 de recharzar la hipotesi nula. Al menos una de las variables predictoras contribuye de manera significativa a la predicción de y.
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
Interpretación: Al observar ambos valores podemos concluir que r2adj no penaliza demasiado (ambos valores cercanos) al tomar las variables mas significativas en la predicción.
Analysis of Variance Table
Model 1: y ~ x1
Model 2: y ~ x1 + x6
Res.Df RSS Df Sum of Sq F Pr(>F)
1 30 281.82
2 29 263.24 1 18.59 2.048 0.1631
Interpretación: Al nivel 0.001 el regresor x6 no tiene efecto en la variable de salida y (hipotesis nula no es rechazada).
anova(lmredu2, lm1)
Analysis of Variance Table
Model 1: y ~ x6
Model 2: y ~ x1 + x6
Res.Df RSS Df Sum of Sq F Pr(>F)
1 30 944.04
2 29 263.23 1 680.81 75.003 1.55e-09 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Interpretación: Al nivel 0.001 el regresor x1 si tiene efecto en la variable de salida y (hipotesis nula es rechazada). Por lo tanto, este regresor x1 no debe ser excluido del modelo.
Interpretación: Respecto a la variable de salida, las variables x1, x3 y x4 tienen una dispersión que podría seguir un comportamiento lineal con pendiente positiva. Las otras variables no tienen un comportamiento definido.
# df <- dat %>% select(x1,x6, y)# graficando las variables# plot(df$x1, df$y, pch=19, col=2,las=1)library("PerformanceAnalytics")px=ncol(dat);chart.Correlation(dat[,0:px], histogram=TRUE, pch=19)
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Warning in par(usr): argument 1 does not name a graphical parameter
Interpretación: Siguiendo lo mensionado anteriormente, las 4 primeras variables tienen una alta correlación directa, aqui hay que tener cuidado con la variable x2 y la correlación con y, mientras que las otras variables tienen una correlación baja a media.
# la matrix X conocida como matriz del modelo X=model.matrix(~x1+x2+x3+x4+x5+x6+x7+x8+x9, data=dat); X
Interpretación: Al observar ambos valores podemos concluir que r2adj penaliza un poco al tomar solo variables las significativas en la predicción. Esto quiere decir que hay variables que se pueden descartar para que no impacte el resultado del modelo.
Warning: package 'jtools' was built under R version 4.4.2
summ(lm2, digits =5)
MODEL INFO:
Observations: 24
Dependent Variable: y
Type: OLS linear regression
MODEL FIT:
F(9,14) = 9.03703, p = 0.00019
R² = 0.85315
Adj. R² = 0.75874
Standard errors:OLS
-----------------------------------------------------------
Est. S.E. t val. p
----------------- ---------- --------- ---------- ---------
(Intercept) 14.92765 5.91285 2.52461 0.02428
x1 1.92472 1.02990 1.86884 0.08271
x2 7.00053 4.30037 1.62789 0.12584
x3 0.14918 0.49039 0.30420 0.76545
x4 2.72281 4.35955 0.62456 0.54230
x5 2.00668 1.37351 1.46099 0.16610
x6 -0.41012 2.37854 -0.17243 0.86557
x7 -1.40324 3.39554 -0.41326 0.68568
x8 -0.03715 0.06672 -0.55679 0.58646
x9 1.55945 1.93750 0.80488 0.43435
-----------------------------------------------------------
Interpretación: De estas pruebas de hipotesis individuales a un nivel 0.001 todas las variables son significativos, esto quiere decir que todos tienen efecto en la variable de salida y.
De la consulta anterior podemos sacar los pesos de cada regresor.