02/05, 2020

Modelos explicativos y predictivos

Modelos estadísticos

  • Simplificación numérica de la realidad
  • Todos los modelos están equivocados, algunos son útiles
  • Modelo no determinista que utiliza una muestra de una población para intentar determinar patrones de esta población.
    • ANOVA
    • regresión lineal
    • una regresión no lineal
  • Poder explicativo != Poder predictivo
  • Poder explivativo (\(R^2\))
  • Poder Predictivo (\(R^2\), en una nueva base de datos)

Ejemplo 1 Altura y sexo

r.squared p.value df
0.2 0 2

Ejemplo 1 Altura y sexo

aov(height ~ sex, data = heights) %>% broom::augment() %>% 
    dplyr::select(height, sex, .fitted, .resid) %>% 
    rename(Prediccion = .fitted, Diferencia = .resid) %>% 
    kable(digits = 2) %>% kable_styling(bootstrap_options = c("striped"), 
    full_width = F) %>% scroll_box(width = "800px", 
    height = "400px")
height sex Prediccion Diferencia
190.50 Male 176.06 14.44
177.80 Male 176.06 1.74
172.72 Male 176.06 -3.34
187.96 Male 176.06 11.90
154.94 Male 176.06 -21.12
165.10 Female 164.95 0.15
167.64 Female 164.95 2.69
157.48 Female 164.95 -7.47
167.64 Female 164.95 2.69
170.18 Male 176.06 -5.88
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
175.26 Male 176.06 -0.80
172.72 Male 176.06 -3.34
175.26 Male 176.06 -0.80
167.64 Male 176.06 -8.42
190.50 Male 176.06 14.44
162.56 Female 164.95 -2.39
152.40 Female 164.95 -12.55
170.18 Male 176.06 -5.88
167.64 Male 176.06 -8.42
162.56 Male 176.06 -13.50
177.80 Male 176.06 1.74
185.42 Male 176.06 9.36
182.88 Male 176.06 6.82
175.26 Male 176.06 -0.80
175.26 Male 176.06 -0.80
182.88 Male 176.06 6.82
162.56 Female 164.95 -2.39
182.88 Male 176.06 6.82
190.50 Male 176.06 14.44
180.34 Male 176.06 4.28
170.18 Female 164.95 5.23
167.64 Female 164.95 2.69
170.18 Female 164.95 5.23
175.26 Male 176.06 -0.80
172.72 Male 176.06 -3.34
169.55 Female 164.95 4.60
182.88 Male 176.06 6.82
160.02 Female 164.95 -4.93
175.26 Male 176.06 -0.80
172.72 Male 176.06 -3.34
160.02 Female 164.95 -4.93
152.40 Male 176.06 -23.66
185.42 Male 176.06 9.36
187.96 Male 176.06 11.90
187.96 Male 176.06 11.90
167.64 Male 176.06 -8.42
172.72 Male 176.06 -3.34
185.42 Male 176.06 9.36
177.80 Male 176.06 1.74
172.72 Male 176.06 -3.34
185.42 Male 176.06 9.36
179.07 Male 176.06 3.01
165.00 Female 164.95 0.05
180.34 Male 176.06 4.28
177.80 Male 176.06 1.74
170.18 Male 176.06 -5.88
175.26 Male 176.06 -0.80
170.18 Male 176.06 -5.88
175.26 Male 176.06 -0.80
185.42 Male 176.06 9.36
187.96 Male 176.06 11.90
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
182.88 Male 176.06 6.82
165.10 Female 164.95 0.15
165.10 Male 176.06 -10.96
177.80 Male 176.06 1.74
185.42 Male 176.06 9.36
170.18 Male 176.06 -5.88
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
172.72 Male 176.06 -3.34
165.10 Female 164.95 0.15
182.88 Male 176.06 6.82
180.34 Male 176.06 4.28
165.10 Female 164.95 0.15
182.88 Female 164.95 17.93
175.26 Male 176.06 -0.80
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
157.48 Female 164.95 -7.47
165.10 Female 164.95 0.15
177.80 Male 176.06 1.74
152.40 Male 176.06 -23.66
170.18 Male 176.06 -5.88
157.48 Female 164.95 -7.47
180.34 Male 176.06 4.28
160.02 Female 164.95 -4.93
172.72 Male 176.06 -3.34
163.00 Female 164.95 -1.95
162.56 Female 164.95 -2.39
180.34 Male 176.06 4.28
173.99 Male 176.06 -2.07
157.48 Female 164.95 -7.47
200.00 Female 164.95 35.05
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
180.34 Female 164.95 15.39
180.34 Male 176.06 4.28
176.78 Female 164.95 11.84
165.10 Female 164.95 0.15
177.80 Male 176.06 1.74
154.94 Female 164.95 -10.01
160.02 Female 164.95 -4.93
177.80 Male 176.06 1.74
170.18 Male 176.06 -5.88
157.48 Female 164.95 -7.47
172.72 Male 176.06 -3.34
185.42 Male 176.06 9.36
168.91 Female 164.95 3.96
175.26 Male 176.06 -0.80
187.96 Male 176.06 11.90
181.61 Male 176.06 5.55
193.04 Male 176.06 16.98
175.26 Male 176.06 -0.80
187.96 Male 176.06 11.90
189.23 Male 176.06 13.17
175.26 Male 176.06 -0.80
167.64 Female 164.95 2.69
162.56 Female 164.95 -2.39
198.12 Male 176.06 22.06
170.18 Male 176.06 -5.88
175.26 Female 164.95 10.31
170.18 Female 164.95 5.23
160.02 Female 164.95 -4.93
187.96 Male 176.06 11.90
157.48 Female 164.95 -7.47
175.26 Female 164.95 10.31
162.56 Female 164.95 -2.39
180.34 Male 176.06 4.28
158.75 Female 164.95 -6.20
172.72 Male 176.06 -3.34
170.18 Female 164.95 5.23
180.34 Male 176.06 4.28
187.96 Male 176.06 11.90
190.50 Male 176.06 14.44
165.10 Female 164.95 0.15
172.72 Male 176.06 -3.34
165.10 Female 164.95 0.15
167.64 Female 164.95 2.69
182.88 Male 176.06 6.82
185.42 Male 176.06 9.36
180.34 Male 176.06 4.28
187.96 Male 176.06 11.90
160.02 Female 164.95 -4.93
185.42 Male 176.06 9.36
172.72 Male 176.06 -3.34
195.58 Female 164.95 30.63
179.07 Male 176.06 3.01
160.02 Female 164.95 -4.93
175.26 Male 176.06 -0.80
175.26 Male 176.06 -0.80
174.98 Male 176.06 -1.08
168.91 Male 176.06 -7.15
163.00 Female 164.95 -1.95
160.02 Female 164.95 -4.93
165.10 Female 164.95 0.15
162.56 Female 164.95 -2.39
160.02 Female 164.95 -4.93
160.02 Female 164.95 -4.93
175.26 Female 164.95 10.31
175.26 Male 176.06 -0.80
162.56 Female 164.95 -2.39
157.48 Female 164.95 -7.47
177.80 Male 176.06 1.74
177.80 Male 176.06 1.74
149.86 Female 164.95 -15.09
165.10 Female 164.95 0.15
171.96 Male 176.06 -4.10
182.88 Male 176.06 6.82
187.96 Male 176.06 11.90
182.12 Male 176.06 6.06
180.01 Male 176.06 3.95
167.64 Female 164.95 2.69
182.88 Male 176.06 6.82
187.96 Male 176.06 11.90
175.26 Male 176.06 -0.80
180.34 Male 176.06 4.28
177.80 Female 164.95 12.85
177.80 Male 176.06 1.74
162.56 Male 176.06 -13.50
173.00 Male 176.06 -3.06
172.72 Female 164.95 7.77
167.64 Female 164.95 2.69
162.56 Female 164.95 -2.39
170.18 Male 176.06 -5.88
165.10 Female 164.95 0.15
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
164.01 Female 164.95 -0.94
129.54 Female 164.95 -35.41
160.02 Female 164.95 -4.93
177.80 Female 164.95 12.85
172.72 Male 176.06 -3.34
170.18 Female 164.95 5.23
180.34 Male 176.06 4.28
175.26 Male 176.06 -0.80
160.02 Female 164.95 -4.93
180.34 Male 176.06 4.28
177.80 Male 176.06 1.74
162.56 Female 164.95 -2.39
177.80 Male 176.06 1.74
172.72 Male 176.06 -3.34
167.64 Male 176.06 -8.42
175.26 Female 164.95 10.31
170.18 Male 176.06 -5.88
165.10 Female 164.95 0.15
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
190.50 Male 176.06 14.44
162.56 Female 164.95 -2.39
167.64 Female 164.95 2.69
172.72 Male 176.06 -3.34
175.26 Female 164.95 10.31
185.42 Male 176.06 9.36
167.64 Male 176.06 -8.42
180.34 Male 176.06 4.28
170.18 Male 176.06 -5.88
177.80 Male 176.06 1.74
170.18 Male 176.06 -5.88
154.94 Female 164.95 -10.01
162.56 Female 164.95 -2.39
162.56 Female 164.95 -2.39
165.10 Male 176.06 -10.96
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
165.10 Male 176.06 -10.96
175.26 Male 176.06 -0.80
172.72 Male 176.06 -3.34
170.18 Male 176.06 -5.88
149.86 Male 176.06 -26.20
149.86 Male 176.06 -26.20
182.88 Female 164.95 17.93
195.58 Male 176.06 19.52
182.88 Male 176.06 6.82
150.00 Female 164.95 -14.95
177.80 Male 176.06 1.74
175.26 Male 176.06 -0.80
182.88 Male 176.06 6.82
175.26 Male 176.06 -0.80
173.00 Male 176.06 -3.06
173.00 Male 176.06 -3.06
172.72 Male 176.06 -3.34
165.10 Male 176.06 -10.96
170.18 Female 164.95 5.23
170.18 Male 176.06 -5.88
172.72 Male 176.06 -3.34
175.26 Male 176.06 -0.80
203.20 Male 176.06 27.14
172.72 Male 176.06 -3.34
172.72 Male 176.06 -3.34
152.40 Female 164.95 -12.55
177.80 Male 176.06 1.74
152.40 Female 164.95 -12.55
152.40 Female 164.95 -12.55
165.00 Female 164.95 0.05
167.64 Female 164.95 2.69
175.00 Male 176.06 -1.06
177.00 Male 176.06 0.94
172.72 Female 164.95 7.77
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
167.64 Male 176.06 -8.42
160.02 Male 176.06 -16.04
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
182.88 Male 176.06 6.82
183.01 Male 176.06 6.95
180.34 Male 176.06 4.28
184.15 Male 176.06 8.09
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
177.80 Male 176.06 1.74
175.26 Male 176.06 -0.80
203.20 Male 176.06 27.14
172.72 Male 176.06 -3.34
167.64 Male 176.06 -8.42
177.80 Male 176.06 1.74
165.10 Male 176.06 -10.96
178.00 Male 176.06 1.94
190.50 Male 176.06 14.44
167.64 Male 176.06 -8.42
175.26 Male 176.06 -0.80
134.62 Female 164.95 -30.33
180.34 Male 176.06 4.28
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
173.99 Male 176.06 -2.07
172.72 Female 164.95 7.77
163.00 Female 164.95 -1.95
172.72 Female 164.95 7.77
150.00 Male 176.06 -26.06
169.98 Male 176.06 -6.08
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
187.96 Male 176.06 11.90
175.00 Male 176.06 -1.06
172.72 Female 164.95 7.77
177.80 Male 176.06 1.74
175.26 Male 176.06 -0.80
154.94 Female 164.95 -10.01
187.96 Male 176.06 11.90
165.10 Male 176.06 -10.96
182.88 Male 176.06 6.82
167.64 Female 164.95 2.69
172.72 Male 176.06 -3.34
154.94 Male 176.06 -21.12
177.80 Male 176.06 1.74
165.10 Female 164.95 0.15
172.72 Male 176.06 -3.34
178.00 Male 176.06 1.94
177.80 Male 176.06 1.74
180.34 Male 176.06 4.28
187.96 Male 176.06 11.90
165.00 Female 164.95 0.05
180.34 Male 176.06 4.28
187.96 Male 176.06 11.90
162.56 Male 176.06 -13.50
180.34 Male 176.06 4.28
167.64 Female 164.95 2.69
165.10 Male 176.06 -10.96
165.00 Female 164.95 0.05
187.96 Male 176.06 11.90
190.50 Male 176.06 14.44
180.00 Male 176.06 3.94
172.72 Male 176.06 -3.34
157.48 Female 164.95 -7.47
189.99 Male 176.06 13.93
175.26 Male 176.06 -0.80
173.74 Male 176.06 -2.32
170.18 Male 176.06 -5.88
165.10 Male 176.06 -10.96
172.72 Male 176.06 -3.34
170.18 Female 164.95 5.23
176.02 Male 176.06 -0.04
169.00 Male 176.06 -7.06
170.18 Male 176.06 -5.88
170.18 Male 176.06 -5.88
185.42 Male 176.06 9.36
190.50 Male 176.06 14.44
177.80 Male 176.06 1.74
180.34 Male 176.06 4.28
162.56 Female 164.95 -2.39
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
181.61 Male 176.06 5.55
182.88 Male 176.06 6.82
175.00 Male 176.06 -1.06
172.72 Male 176.06 -3.34
162.56 Male 176.06 -13.50
175.26 Male 176.06 -0.80
177.80 Male 176.06 1.74
190.50 Female 164.95 25.55
170.18 Male 176.06 -5.88
157.00 Male 176.06 -19.06
185.42 Male 176.06 9.36
169.00 Male 176.06 -7.06
160.02 Female 164.95 -4.93
167.64 Male 176.06 -8.42
183.00 Male 176.06 6.94
172.01 Male 176.06 -4.05
165.10 Female 164.95 0.15
175.26 Male 176.06 -0.80
180.34 Male 176.06 4.28
167.64 Male 176.06 -8.42
182.88 Male 176.06 6.82
183.90 Male 176.06 7.84
175.26 Male 176.06 -0.80
182.88 Male 176.06 6.82
200.79 Male 176.06 24.73
162.00 Male 176.06 -14.06
178.00 Male 176.06 1.94
180.00 Male 176.06 3.94
168.66 Male 176.06 -7.40
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
176.00 Male 176.06 -0.06
170.00 Male 176.06 -6.06
160.02 Female 164.95 -4.93
168.00 Female 164.95 3.05
198.12 Male 176.06 22.06
190.50 Male 176.06 14.44
178.00 Male 176.06 1.94
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
165.10 Female 164.95 0.15
180.34 Male 176.06 4.28
173.99 Male 176.06 -2.07
165.10 Male 176.06 -10.96
175.26 Male 176.06 -0.80
190.00 Male 176.06 13.94
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
167.64 Male 176.06 -8.42
160.02 Female 164.95 -4.93
180.34 Male 176.06 4.28
162.56 Male 176.06 -13.50
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
184.00 Male 176.06 7.94
170.18 Male 176.06 -5.88
173.99 Male 176.06 -2.07
172.72 Female 164.95 7.77
175.26 Male 176.06 -0.80
177.80 Male 176.06 1.74
173.99 Male 176.06 -2.07
136.58 Male 176.06 -39.48
169.98 Male 176.06 -6.08
185.42 Male 176.06 9.36
172.72 Male 176.06 -3.34
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
181.61 Male 176.06 5.55
167.64 Female 164.95 2.69
184.00 Male 176.06 7.94
182.88 Male 176.06 6.82
170.18 Male 176.06 -5.88
182.88 Male 176.06 6.82
167.00 Male 176.06 -9.06
182.88 Male 176.06 6.82
187.96 Male 176.06 11.90
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
172.00 Male 176.06 -4.06
180.34 Male 176.06 4.28
165.10 Male 176.06 -10.96
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
180.34 Male 176.06 4.28
175.26 Male 176.06 -0.80
160.02 Female 164.95 -4.93
180.34 Male 176.06 4.28
165.10 Male 176.06 -10.96
157.48 Female 164.95 -7.47
170.18 Male 176.06 -5.88
180.00 Male 176.06 3.94
137.16 Male 176.06 -38.90
165.10 Male 176.06 -10.96
165.10 Male 176.06 -10.96
195.58 Male 176.06 19.52
170.18 Male 176.06 -5.88
173.00 Male 176.06 -3.06
175.26 Male 176.06 -0.80
172.72 Male 176.06 -3.34
157.48 Female 164.95 -7.47
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
180.34 Male 176.06 4.28
165.00 Male 176.06 -11.06
162.56 Female 164.95 -2.39
170.18 Male 176.06 -5.88
180.00 Male 176.06 3.94
167.64 Male 176.06 -8.42
183.00 Male 176.06 6.94
170.00 Male 176.06 -6.06
167.64 Male 176.06 -8.42
167.64 Male 176.06 -8.42
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
162.56 Female 164.95 -2.39
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
172.00 Male 176.06 -4.06
190.50 Male 176.06 14.44
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
173.99 Male 176.06 -2.07
167.64 Female 164.95 2.69
180.34 Male 176.06 4.28
180.34 Male 176.06 4.28
168.00 Male 176.06 -8.06
182.88 Male 176.06 6.82
162.56 Female 164.95 -2.39
177.80 Female 164.95 12.85
170.18 Male 176.06 -5.88
177.80 Male 176.06 1.74
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
160.02 Male 176.06 -16.04
165.10 Male 176.06 -10.96
160.02 Male 176.06 -16.04
170.00 Male 176.06 -6.06
177.80 Male 176.06 1.74
179.83 Male 176.06 3.77
172.00 Male 176.06 -4.06
172.72 Male 176.06 -3.34
167.64 Female 164.95 2.69
196.00 Male 176.06 19.94
165.10 Male 176.06 -10.96
176.00 Male 176.06 -0.06
171.45 Male 176.06 -4.61
171.45 Male 176.06 -4.61
172.72 Male 176.06 -3.34
167.64 Male 176.06 -8.42
187.96 Male 176.06 11.90
182.88 Male 176.06 6.82
184.99 Male 176.06 8.93
195.58 Male 176.06 19.52
170.18 Male 176.06 -5.88
177.80 Male 176.06 1.74
162.56 Male 176.06 -13.50
165.10 Male 176.06 -10.96
185.42 Male 176.06 9.36
157.48 Female 164.95 -7.47
169.42 Male 176.06 -6.64
175.26 Female 164.95 10.31
170.18 Male 176.06 -5.88
173.00 Male 176.06 -3.06
175.26 Male 176.06 -0.80
174.00 Male 176.06 -2.06
176.00 Male 176.06 -0.06
175.00 Male 176.06 -1.06
180.34 Male 176.06 4.28
162.56 Male 176.06 -13.50
170.18 Male 176.06 -5.88
177.80 Male 176.06 1.74
172.72 Male 176.06 -3.34
172.16 Female 164.95 7.22
173.99 Male 176.06 -2.07
172.72 Male 176.06 -3.34
171.98 Female 164.95 7.04
168.91 Male 176.06 -7.15
175.26 Male 176.06 -0.80
200.66 Male 176.06 24.60
162.56 Female 164.95 -2.39
152.40 Male 176.06 -23.66
182.88 Male 176.06 6.82
154.94 Female 164.95 -10.01
187.96 Male 176.06 11.90
167.64 Female 164.95 2.69
165.10 Female 164.95 0.15
170.18 Male 176.06 -5.88
174.75 Male 176.06 -1.31
175.26 Male 176.06 -0.80
198.12 Male 176.06 22.06
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
167.64 Male 176.06 -8.42
187.96 Male 176.06 11.90
180.34 Male 176.06 4.28
185.42 Male 176.06 9.36
170.18 Male 176.06 -5.88
182.88 Male 176.06 6.82
177.80 Male 176.06 1.74
178.05 Male 176.06 1.99
157.48 Male 176.06 -18.58
175.26 Male 176.06 -0.80
165.10 Female 164.95 0.15
172.72 Female 164.95 7.77
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
160.02 Female 164.95 -4.93
167.64 Male 176.06 -8.42
170.18 Male 176.06 -5.88
185.93 Male 176.06 9.87
162.56 Female 164.95 -2.39
187.96 Male 176.06 11.90
186.99 Male 176.06 10.94
182.88 Male 176.06 6.82
173.74 Female 164.95 8.79
175.26 Male 176.06 -0.80
154.94 Female 164.95 -10.01
170.18 Male 176.06 -5.88
175.26 Male 176.06 -0.80
167.64 Male 176.06 -8.42
172.72 Male 176.06 -3.34
165.10 Male 176.06 -10.96
175.01 Male 176.06 -1.05
171.98 Male 176.06 -4.08
170.18 Male 176.06 -5.88
170.18 Male 176.06 -5.88
149.86 Female 164.95 -15.09
149.86 Female 164.95 -15.09
170.18 Female 164.95 5.23
183.00 Male 176.06 6.94
180.34 Male 176.06 4.28
172.00 Male 176.06 -4.06
172.72 Male 176.06 -3.34
169.93 Male 176.06 -6.13
173.99 Male 176.06 -2.07
187.96 Male 176.06 11.90
193.04 Male 176.06 16.98
152.40 Male 176.06 -23.66
175.26 Male 176.06 -0.80
182.88 Male 176.06 6.82
175.26 Male 176.06 -0.80
170.18 Male 176.06 -5.88
177.80 Male 176.06 1.74
173.99 Male 176.06 -2.07
177.80 Male 176.06 1.74
170.18 Male 176.06 -5.88
177.80 Male 176.06 1.74
175.26 Male 176.06 -0.80
165.10 Female 164.95 0.15
175.01 Male 176.06 -1.05
175.26 Male 176.06 -0.80
168.00 Male 176.06 -8.06
170.00 Female 164.95 5.05
177.80 Male 176.06 1.74
195.58 Male 176.06 19.52
179.96 Male 176.06 3.90
170.00 Male 176.06 -6.06
175.00 Male 176.06 -1.06
162.56 Female 164.95 -2.39
175.26 Male 176.06 -0.80
170.18 Male 176.06 -5.88
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
170.18 Male 176.06 -5.88
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
184.99 Male 176.06 8.93
177.80 Male 176.06 1.74
160.02 Female 164.95 -4.93
180.34 Male 176.06 4.28
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
184.00 Male 176.06 7.94
177.80 Male 176.06 1.74
172.72 Male 176.06 -3.34
149.86 Female 164.95 -15.09
180.34 Male 176.06 4.28
155.75 Male 176.06 -20.31
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
185.42 Male 176.06 9.36
180.34 Male 176.06 4.28
175.26 Male 176.06 -0.80
180.34 Male 176.06 4.28
170.00 Male 176.06 -6.06
147.32 Male 176.06 -28.74
139.70 Female 164.95 -25.25
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
165.10 Male 176.06 -10.96
182.88 Male 176.06 6.82
187.96 Female 164.95 23.01
180.34 Male 176.06 4.28
175.26 Male 176.06 -0.80
162.00 Male 176.06 -14.06
180.34 Male 176.06 4.28
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
175.26 Male 176.06 -0.80
177.80 Male 176.06 1.74
185.42 Male 176.06 9.36
165.00 Male 176.06 -11.06
184.00 Male 176.06 7.94
185.98 Male 176.06 9.92
162.56 Female 164.95 -2.39
177.80 Male 176.06 1.74
190.50 Male 176.06 14.44
160.02 Male 176.06 -16.04
183.01 Male 176.06 6.95
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
190.50 Male 176.06 14.44
172.72 Male 176.06 -3.34
173.00 Male 176.06 -3.06
177.80 Male 176.06 1.74
168.00 Female 164.95 3.05
187.96 Male 176.06 11.90
160.00 Male 176.06 -16.06
172.72 Male 176.06 -3.34
172.72 Male 176.06 -3.34
177.80 Male 176.06 1.74
180.34 Male 176.06 4.28
172.00 Male 176.06 -4.06
170.00 Male 176.06 -6.06
177.80 Male 176.06 1.74
178.00 Male 176.06 1.94
170.69 Male 176.06 -5.37
175.26 Male 176.06 -0.80
177.80 Male 176.06 1.74
175.26 Male 176.06 -0.80
184.00 Male 176.06 7.94
175.26 Male 176.06 -0.80
184.02 Male 176.06 7.96
175.26 Male 176.06 -0.80
170.18 Male 176.06 -5.88
192.99 Male 176.06 16.93
180.34 Male 176.06 4.28
170.18 Male 176.06 -5.88
180.34 Male 176.06 4.28
170.18 Male 176.06 -5.88
165.10 Male 176.06 -10.96
157.48 Male 176.06 -18.58
180.34 Male 176.06 4.28
187.96 Male 176.06 11.90
175.26 Male 176.06 -0.80
182.88 Male 176.06 6.82
174.00 Male 176.06 -2.06
170.00 Male 176.06 -6.06
172.72 Male 176.06 -3.34
170.00 Male 176.06 -6.06
160.02 Male 176.06 -16.04
160.00 Female 164.95 -4.95
177.80 Male 176.06 1.74
192.00 Male 176.06 15.94
172.72 Male 176.06 -3.34
175.26 Male 176.06 -0.80
180.34 Male 176.06 4.28
180.34 Male 176.06 4.28
176.02 Male 176.06 -0.04
167.00 Male 176.06 -9.06
180.00 Male 176.06 3.94
170.18 Male 176.06 -5.88
172.01 Male 176.06 -4.05
177.80 Male 176.06 1.74
170.18 Male 176.06 -5.88
165.10 Male 176.06 -10.96
170.18 Male 176.06 -5.88
158.50 Female 164.95 -6.45
180.34 Male 176.06 4.28
150.00 Male 176.06 -26.06
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
190.50 Male 176.06 14.44
182.88 Male 176.06 6.82
167.64 Male 176.06 -8.42
180.34 Male 176.06 4.28
193.04 Male 176.06 16.98
175.26 Male 176.06 -0.80
175.26 Male 176.06 -0.80
170.00 Male 176.06 -6.06
167.64 Male 176.06 -8.42
174.00 Male 176.06 -2.06
176.00 Male 176.06 -0.06
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
162.56 Female 164.95 -2.39
167.64 Male 176.06 -8.42
177.80 Male 176.06 1.74
170.18 Male 176.06 -5.88
192.02 Male 176.06 15.96
181.61 Male 176.06 5.55
182.88 Male 176.06 6.82
160.02 Female 164.95 -4.93
157.48 Female 164.95 -7.47
175.26 Male 176.06 -0.80
172.72 Female 164.95 7.77
181.99 Male 176.06 5.93
190.50 Male 176.06 14.44
175.00 Male 176.06 -1.06
187.96 Male 176.06 11.90
165.10 Female 164.95 0.15
162.56 Female 164.95 -2.39
172.72 Female 164.95 7.77
165.10 Female 164.95 0.15
162.56 Female 164.95 -2.39
170.18 Female 164.95 5.23
175.26 Male 176.06 -0.80
172.72 Male 176.06 -3.34
170.18 Female 164.95 5.23
175.00 Female 164.95 10.05
159.00 Female 164.95 -5.94
177.80 Male 176.06 1.74
175.26 Female 164.95 10.31
165.10 Female 164.95 0.15
160.02 Female 164.95 -4.93
170.94 Male 176.06 -5.12
163.07 Female 164.95 -1.88
160.02 Female 164.95 -4.93
154.94 Male 176.06 -21.12
170.18 Male 176.06 -5.88
180.34 Male 176.06 4.28
154.94 Female 164.95 -10.01
154.94 Female 164.95 -10.01
173.00 Female 164.95 8.05
168.00 Female 164.95 3.05
171.45 Female 164.95 6.50
152.40 Female 164.95 -12.55
170.18 Female 164.95 5.23
172.01 Female 164.95 7.06
167.64 Female 164.95 2.69
170.18 Male 176.06 -5.88
177.80 Female 164.95 12.85
167.64 Female 164.95 2.69
163.83 Female 164.95 -1.12
172.72 Female 164.95 7.77
175.26 Male 176.06 -0.80
172.72 Male 176.06 -3.34
180.34 Male 176.06 4.28
193.04 Male 176.06 16.98
180.00 Male 176.06 3.94
167.64 Male 176.06 -8.42
170.18 Female 164.95 5.23
180.34 Male 176.06 4.28
158.75 Female 164.95 -6.20
170.18 Male 176.06 -5.88
170.18 Male 176.06 -5.88
172.00 Male 176.06 -4.06
152.40 Female 164.95 -12.55
170.18 Male 176.06 -5.88
172.72 Female 164.95 7.77
190.50 Male 176.06 14.44
165.10 Male 176.06 -10.96
165.10 Male 176.06 -10.96
162.56 Female 164.95 -2.39
157.48 Female 164.95 -7.47
180.00 Male 176.06 3.94
190.50 Male 176.06 14.44
180.34 Male 176.06 4.28
170.18 Female 164.95 5.23
182.88 Male 176.06 6.82
152.40 Female 164.95 -12.55
172.72 Male 176.06 -3.34
162.56 Female 164.95 -2.39
180.00 Male 176.06 3.94
180.00 Male 176.06 3.94
185.42 Male 176.06 9.36
191.52 Male 176.06 15.46
172.72 Female 164.95 7.77
177.80 Male 176.06 1.74
175.26 Male 176.06 -0.80
160.02 Female 164.95 -4.93
157.48 Female 164.95 -7.47
185.42 Male 176.06 9.36
182.88 Male 176.06 6.82
172.72 Female 164.95 7.77
154.94 Female 164.95 -10.01
152.40 Female 164.95 -12.55
165.10 Male 176.06 -10.96
160.02 Female 164.95 -4.93
170.18 Male 176.06 -5.88
175.26 Female 164.95 10.31
187.96 Male 176.06 11.90
172.72 Female 164.95 7.77
177.80 Male 176.06 1.74
185.42 Male 176.06 9.36
177.80 Male 176.06 1.74
152.40 Female 164.95 -12.55
167.64 Female 164.95 2.69
172.72 Female 164.95 7.77
170.18 Male 176.06 -5.88
165.10 Male 176.06 -10.96
180.34 Male 176.06 4.28
177.80 Female 164.95 12.85
165.10 Male 176.06 -10.96
185.00 Male 176.06 8.94
177.80 Male 176.06 1.74
177.80 Male 176.06 1.74
165.10 Female 164.95 0.15
177.80 Male 176.06 1.74
177.80 Male 176.06 1.74
171.96 Female 164.95 7.01
157.48 Female 164.95 -7.47
175.26 Male 176.06 -0.80
175.26 Male 176.06 -0.80
157.48 Female 164.95 -7.47
187.96 Male 176.06 11.90
180.34 Male 176.06 4.28
177.80 Female 164.95 12.85
162.56 Male 176.06 -13.50
185.42 Male 176.06 9.36
177.80 Male 176.06 1.74
167.64 Male 176.06 -8.42
167.64 Male 176.06 -8.42
172.72 Male 176.06 -3.34
157.48 Female 164.95 -7.47
167.64 Female 164.95 2.69
162.56 Female 164.95 -2.39
170.18 Male 176.06 -5.88
180.34 Male 176.06 4.28
198.12 Male 176.06 22.06
175.26 Male 176.06 -0.80
170.18 Female 164.95 5.23
177.80 Male 176.06 1.74
165.10 Female 164.95 0.15
177.80 Male 176.06 1.74
167.00 Male 176.06 -9.06
180.34 Male 176.06 4.28
172.72 Male 176.06 -3.34
170.18 Female 164.95 5.23
168.00 Male 176.06 -8.06
162.56 Female 164.95 -2.39
172.72 Male 176.06 -3.34
152.40 Female 164.95 -12.55
162.56 Female 164.95 -2.39
185.93 Male 176.06 9.87
182.88 Male 176.06 6.82
185.42 Male 176.06 9.36
180.34 Male 176.06 4.28
184.00 Male 176.06 7.94
170.18 Female 164.95 5.23
180.34 Male 176.06 4.28
180.34 Male 176.06 4.28
174.98 Male 176.06 -1.08
174.98 Male 176.06 -1.08
178.00 Male 176.06 1.94
182.00 Male 176.06 5.94
175.26 Female 164.95 10.31
164.00 Female 164.95 -0.95
167.64 Female 164.95 2.69
172.72 Male 176.06 -3.34
177.80 Male 176.06 1.74
177.80 Male 176.06 1.74
172.72 Male 176.06 -3.34
178.05 Male 176.06 1.99
185.00 Female 164.95 20.05
182.88 Male 176.06 6.82
182.88 Male 176.06 6.82
167.64 Male 176.06 -8.42
167.64 Male 176.06 -8.42
175.26 Male 176.06 -0.80
167.64 Male 176.06 -8.42
200.00 Male 176.06 23.94
170.18 Male 176.06 -5.88
177.80 Male 176.06 1.74
170.18 Male 176.06 -5.88
167.64 Male 176.06 -8.42
177.80 Male 176.06 1.74
185.00 Male 176.06 8.94
171.96 Male 176.06 -4.10
182.88 Male 176.06 6.82
175.26 Female 164.95 10.31
165.10 Male 176.06 -10.96
167.64 Male 176.06 -8.42
177.80 Male 176.06 1.74
172.00 Male 176.06 -4.06
170.18 Male 176.06 -5.88
182.88 Male 176.06 6.82
172.72 Female 164.95 7.77
175.26 Female 164.95 10.31
164.85 Male 176.06 -11.21
160.00 Male 176.06 -16.06
190.50 Male 176.06 14.44
175.26 Male 176.06 -0.80
165.00 Female 164.95 0.05
163.83 Male 176.06 -12.23
162.56 Male 176.06 -13.50
165.10 Male 176.06 -10.96
177.80 Male 176.06 1.74
154.94 Male 176.06 -21.12
170.18 Male 176.06 -5.88
152.00 Male 176.06 -24.06
171.45 Male 176.06 -4.61
180.00 Male 176.06 3.94
179.98 Male 176.06 3.92
175.00 Male 176.06 -1.06
177.80 Male 176.06 1.74
158.00 Male 176.06 -18.06
173.00 Male 176.06 -3.06
164.00 Male 176.06 -12.06
193.04 Male 176.06 16.98
169.00 Male 176.06 -7.06
177.80 Male 176.06 1.74
185.00 Male 176.06 8.94
168.00 Male 176.06 -8.06
175.26 Male 176.06 -0.80
169.00 Male 176.06 -7.06
165.10 Male 176.06 -10.96
172.72 Male 176.06 -3.34
174.00 Male 176.06 -2.06
172.72 Male 176.06 -3.34
173.00 Male 176.06 -3.06
190.50 Male 176.06 14.44
175.26 Male 176.06 -0.80
179.00 Male 176.06 2.94
167.64 Male 176.06 -8.42
175.26 Male 176.06 -0.80
170.18 Male 176.06 -5.88
174.98 Male 176.06 -1.08
185.98 Male 176.06 9.92
167.64 Male 176.06 -8.42
165.10 Male 176.06 -10.96
182.88 Male 176.06 6.82
190.50 Male 176.06 14.44
182.88 Male 176.06 6.82
170.00 Male 176.06 -6.06
132.08 Female 164.95 -32.87
132.08 Female 164.95 -32.87
200.66 Female 164.95 35.71
177.80 Male 176.06 1.74
182.88 Male 176.06 6.82
172.00 Male 176.06 -4.06
162.56 Female 164.95 -2.39
173.00 Male 176.06 -3.06
170.18 Male 176.06 -5.88
158.00 Male 176.06 -18.06
190.50 Male 176.06 14.44
190.50 Male 176.06 14.44
205.74 Male 176.06 29.68
175.26 Male 176.06 -0.80
175.00 Male 176.06 -1.06
159.00 Male 176.06 -17.06
193.04 Male 176.06 16.98
190.00 Female 164.95 25.05
176.78 Male 176.06 0.72
170.18 Male 176.06 -5.88
160.02 Female 164.95 -4.93
177.80 Male 176.06 1.74
184.00 Male 176.06 7.94
167.64 Female 164.95 2.69
170.00 Male 176.06 -6.06
158.00 Male 176.06 -18.06
185.42 Male 176.06 9.36
182.88 Male 176.06 6.82
152.40 Female 164.95 -12.55
193.04 Male 176.06 16.98
165.10 Male 176.06 -10.96
167.64 Male 176.06 -8.42
180.00 Male 176.06 3.94
175.01 Male 176.06 -1.05
180.34 Male 176.06 4.28
162.56 Female 164.95 -2.39
210.00 Male 176.06 33.94
182.88 Male 176.06 6.82
172.72 Male 176.06 -3.34
170.18 Male 176.06 -5.88
175.26 Male 176.06 -0.80
163.07 Female 164.95 -1.88
182.88 Male 176.06 6.82
160.02 Male 176.06 -16.04
162.00 Female 164.95 -2.95
167.64 Male 176.06 -8.42
170.00 Male 176.06 -6.06
187.96 Male 176.06 11.90
182.88 Male 176.06 6.82
170.18 Male 176.06 -5.88
180.34 Male 176.06 4.28
127.00 Male 176.06 -49.06
170.00 Male 176.06 -6.06
157.00 Male 176.06 -19.06
186.00 Male 176.06 9.94
165.10 Male 176.06 -10.96
170.00 Male 176.06 -6.06
160.02 Male 176.06 -16.04
187.96 Male 176.06 11.90
172.00 Male 176.06 -4.06
152.40 Male 176.06 -23.66
152.40 Male 176.06 -23.66
175.26 Male 176.06 -0.80
175.26 Male 176.06 -0.80
127.00 Male 176.06 -49.06
175.26 Female 164.95 10.31
175.26 Male 176.06 -0.80
161.00 Male 176.06 -15.06
167.64 Male 176.06 -8.42
167.64 Male 176.06 -8.42

Ejemplo 2 temperautra explicada por fecha

Ejemplo 2 temperautra explicada por fecha

Ejemplo 3

¿Podemos explicar o predecir la eficiencia de combustible (mpg) a partir de los caballos de fuerza (hp) de un Vehículo?

Datos de entrenamiento y de prueba

  • Para mostrar poder explicativo vs predictivo
  • Datos de entrenamiento (ajustar el modelo y ver poder explicativo)
  • Datos de prueba (Ver el poder predictivo)
set.seed(2018)
index <- sample(1:nrow(mtcars), size = round(nrow(mtcars)/2))

Train <- mtcars[index, ]

Test <- mtcars[-index, ]

\[mpg = \beta_1 hp + \beta_2 hp^2 + c\]

Entrenamos el modelo

  • Ajustemos un modelo lineal
Modelo <- lm(mpg ~ hp + I(hp^2), data = Train)

Poder explicativo:

  • Veamos el poder explicativo
glance(Modelo)
R cuadrado, valor de p y grados de libertad del modelo
r.squared p.value df
0.7879861 4.18e-05 3
  • podemos explicar un 78.8% de la variación en la eficiencia del vehículo.

Observemos el modelo gráficamente

Los puntos representan las observaciones con las que se entrenó el modelo, la linea roja segmentada representa la predicción del modelo

Los puntos representan las observaciones con las que se entrenó el modelo, la linea roja segmentada representa la predicción del modelo

Poder Predictivo:

  • Generemos una predicción en la base de datos de prueba
Test$Pred <- predict(Modelo, Test)
Test <- Test %>% mutate(resid = mpg - Pred) %>% select(hp, 
    mpg, Pred, resid)
hp mpg Pred resid
110 21.0 20.86 0.14
110 21.4 20.86 0.54
175 18.7 15.19 3.51
105 18.1 21.49 -3.39
245 14.3 14.28 0.02
123 19.2 19.36 -0.16
180 15.2 14.95 0.25
215 10.4 14.01 -3.61
230 14.7 14.02 0.68
52 30.4 29.84 0.56
65 33.9 27.51 6.39
66 27.3 27.34 -0.04
91 26.0 23.40 2.60
113 30.4 20.50 9.90
175 19.7 15.19 4.51
335 15.0 21.01 -6.01

Poder Predictivo (Calculo)

library(caret)
postResample(pred = Test$Pred, obs = Test$mpg)
##      RMSE  Rsquared       MAE 
## 3.8741375 0.6805523 2.6437118

Poder Predictivo (Visual)

Sobreajuste

Que pasa al complejizar el modelo

\[mpg = \beta_1 hp + \beta_2 hp^2 + ... + \beta_12 hp^{12} c\]