Mide el grado de asociación lineal entre las variables.
Podemos ver que una variable se realiciona con la otra por ejemplo X2=2*X1. Como la calculamos: \[ cor(x_i,x_k)\not = k \] Tener en cuenta que no aplica para relacines NO lineales: \[ Y=\beta_0+\beta_1*X_1+\beta_2*X_1^2 \] No aplica porque no viola el supuesto de multicolinealidad, eso va a pasar siempre que \(X_1\) tenga una variación en la muestra realtivamente grande, de no ser asà no se distanciaria mucho de \(X_1^2\) y si habrÃa multicolinealidad.
FALSO. Si hay multicolinealidad perfecta los coeficientes de resgresion de las vvariables X son indeterminados y sus rrores estandar son infinitos. Los estimadores no son MELI ya no que no cumplen con el supuesto de Gauss- Markov
FALSO. Si la correlacion es alta presisamente sujiere multicolinealidad alta.
x1<-rnorm(3000,1,2)
x2<-x1+rnorm(3000,0,1)
cor(x1,x2)
## [1] 0.8844234
y=2+5*x1+2*x2+rnorm(3000,0,1)
datos=data.frame(y,x1,x2)
library(GGally)
## Loading required package: ggplot2
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
ggpairs(datos, lower = list(continuous = "smooth"),
diag = list(continuous = "bar"), axisLabels = "none")
## Warning in check_and_set_ggpairs_defaults("diag", diag, continuous =
## "densityDiag", : Changing diag$continuous from 'bar' to 'barDiag'
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
regressor_ejer_3<-lm(y~.,data = datos)
summary(regressor_ejer_3)
##
## Call:
## lm(formula = y ~ ., data = datos)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.2968 -0.6455 0.0057 0.6660 3.5691
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.00094 0.02022 98.98 <2e-16 ***
## x1 5.01352 0.01985 252.53 <2e-16 ***
## x2 1.98352 0.01764 112.41 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9959 on 2997 degrees of freedom
## Multiple R-squared: 0.9949, Adjusted R-squared: 0.9949
## F-statistic: 2.907e+05 on 2 and 2997 DF, p-value: < 2.2e-16
A pesar de tener una alta correlacion entre x1 y x2 ambos dan que son significativos.
x1<-rnorm(3000,1,2)
x2<-x1+rnorm(3000,0,0.001)
cor(x1,x2)
## [1] 0.9999999
Se puede observar una correlacion casi perfecta
y=2+5*x1+2*x2+rnorm(3000,0,1)
datos=data.frame(y,x1,x2)
library(GGally)
ggpairs(datos, lower = list(continuous = "smooth"),
diag = list(continuous = "bar"), axisLabels = "none")
## Warning in check_and_set_ggpairs_defaults("diag", diag, continuous =
## "densityDiag", : Changing diag$continuous from 'bar' to 'barDiag'
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
regressor_ejer_3<-lm(y~.,data = datos)
summary(regressor_ejer_3)
##
## Call:
## lm(formula = y ~ ., data = datos)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.5778 -0.7021 -0.0014 0.6887 3.1612
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.99285 0.02036 97.881 <2e-16 ***
## x1 17.03572 18.63790 0.914 0.361
## x2 -10.03412 18.63804 -0.538 0.590
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.003 on 2997 degrees of freedom
## Multiple R-squared: 0.9947, Adjusted R-squared: 0.9947
## F-statistic: 2.829e+05 on 2 and 2997 DF, p-value: < 2.2e-16
Aca vemos que solo el intercepto da significativo.
rm(list=ls())
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
consumo=c(6127.9,
6863.1,
10687.4,
5518.4,
9783.9,
4828.9,
8614.3,
4311.9,
5216.1,
7486.6,
4898.3,
7924.3,
4473.3,
9409.9,
9000.1,
6316.5,
5176.0)
ingresop=c(8467.0,
9113.0,
14162.0,
7392.0,
13067.0,
6357.0,
11969.0,
5647.0,
6323.0,
9638.0,
6159.0,
10229.0,
5989.0,
13147.0,
12003.0,
7895.0,
6500.0)
ingresod=c(79.1,
82.8,
128.7,
66.0,
121.0,
56.8,
111.9,
50.9,
58.0,
90.1,
56.5,
95.6,
54.4,
121.7,
107.2,
71.1,
58.6)
datos=data.frame(consumo,ingresop,ingresod)
library(GGally)
ggpairs(datos, lower = list(continuous = "smooth"),
diag = list(continuous = "bar"), axisLabels = "none")
## Warning in check_and_set_ggpairs_defaults("diag", diag, continuous =
## "densityDiag", : Changing diag$continuous from 'bar' to 'barDiag'
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Aca vemos que hay una alta correlacion, pero no perfecta, en cmabio con el en ingresoD e ingresoP hay una correlacion muy alta 0.999 por lo que vamos a tener un problema de multicolinealidad. Una forma de solucionarlo es quitarlo del modelo.
reg<-lm(consumo~.,data = datos)
summary(reg)
##
## Call:
## lm(formula = consumo ~ ., data = datos)
##
## Residuals:
## Min 1Q Median 3Q Max
## -322.32 -195.70 -15.74 178.67 304.74
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 419.8450 198.4564 2.116 0.0528 .
## ingresop 0.9307 0.3807 2.445 0.0283 *
## ingresod -24.0271 40.8252 -0.589 0.5655
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 230.6 on 14 degrees of freedom
## Multiple R-squared: 0.9889, Adjusted R-squared: 0.9873
## F-statistic: 625.1 on 2 and 14 DF, p-value: 2.042e-14
Al correr la regresion podemos observar tambien que R^2 ajustado es muy alto, pero los regresores son muy pocos significativos.
Ahora probamos quitando el consumoP y ConsumoD del modelo
regPesos<-lm(consumo~datos$ingresop ,data = datos)
regDolares<-lm(consumo~datos$ingresod,data = datos)
stargazer(reg,regPesos,regDolares,type="text")
##
## =============================================================================================
## Dependent variable:
## -------------------------------------------------------------------------
## consumo
## (1) (2) (3)
## ---------------------------------------------------------------------------------------------
## ingresop 0.931**
## (0.381)
##
## ingresod -24.027
## (40.825)
##
## ingresop 0.707***
## (0.020)
##
## ingresod 75.637***
## (2.474)
##
## Constant 419.845* 454.250** 585.825**
## (198.456) (185.473) (215.200)
##
## ---------------------------------------------------------------------------------------------
## Observations 17 17 17
## R2 0.989 0.989 0.984
## Adjusted R2 0.987 0.988 0.983
## Residual Std. Error 230.579 (df = 14) 225.500 (df = 15) 266.091 (df = 15)
## F Statistic 625.118*** (df = 2; 14) 1,306.835*** (df = 1; 15) 934.312*** (df = 1; 15)
## =============================================================================================
## Note: *p<0.1; **p<0.05; ***p<0.01