22/11, 2020
githubURL <- ("https://raw.githubusercontent.com/Curso-programacion/Datos_Arboles/master/Data.rds") download.file(githubURL, "Data.rds", method = "curl") Data <- read_rds("Data.rds")
alguna_funcion(Y ~ X1 + X2 + ... + Xn, data = data.frame)
~
: Explicado porModelos | Funcion |
---|---|
Prueba de t | t.test() |
ANOVA | aov() |
Modelo lineal simple | lm() |
modelo lineal generalizado | glm() |
Modelo aditivo | gam() |
Modelo no lineal | nls() |
modelos lineales mixtos | lmer() |
Boosted regression trees | gbm() |
Modelo <- lm(Altura ~ DAP, data = Data) Parametros <- broom::tidy(Modelo)
term | estimate | std.error | statistic | p.value |
---|---|---|---|---|
(Intercept) | 5.195 | 0.984 | 5.278 | 0 |
DAP | 0.296 | 0.031 | 9.584 | 0 |
\[ \operatorname{Altura} = 5.2 + 0.3(\operatorname{DAP}) + \epsilon \]
\[ \operatorname{Altura} = 5.2 + 0.3(\operatorname{DAP}) + \epsilon \]
term | estimate | std.error | statistic | p.value |
---|---|---|---|---|
(Intercept) | 5.1953339 | 0.9842945 | 5.278231 | 8e-07 |
DAP | 0.2956101 | 0.0308452 | 9.583671 | 0e+00 |
ggplot(Data, aes(y = Altura, x = DAP)) + geom_point() + geom_smooth(method = "lm") + theme_bw()
glance(Modelo)
r.squared | adj.r.squared | sigma | statistic | p.value | df | logLik | AIC | BIC | deviance | df.residual | nobs |
---|---|---|---|---|---|---|---|---|---|---|---|
0.486 | 0.481 | 4.781 | 91.847 | 0 | 1 | -294.356 | 594.712 | 602.498 | 2216.825 | 97 | 99 |
githubURL <- ("https://raw.githubusercontent.com/derek-corcoran-barrios/derek-corcoran-barrios.github.io/master/Clase4/TempHum.rds") download.file(githubURL, "TempHum.rds", method = "curl") TempHum <- read_rds("TempHum.rds") %>% mutate(Mes = as.numeric(Mes))
library(tidyverse) VA <- TempHum %>% filter(Ciudad_localidad == "Valdivia")
Mes | Año | Temperatura | Ciudad_localidad | Humedad |
---|---|---|---|---|
1 | 1981 | 15.2 | Valdivia | NA |
2 | 1981 | 15.1 | Valdivia | NA |
3 | 1981 | 13.9 | Valdivia | NA |
4 | 1981 | 12.4 | Valdivia | NA |
5 | 1981 | 10.4 | Valdivia | NA |
6 | 1981 | 7.9 | Valdivia | NA |
7 | 1981 | 7.2 | Valdivia | NA |
8 | 1981 | 7.2 | Valdivia | NA |
9 | 1981 | 8.2 | Valdivia | NA |
10 | 1981 | 10.7 | Valdivia | NA |
11 | 1981 | 11.9 | Valdivia | NA |
12 | 1981 | 14.8 | Valdivia | NA |
1 | 1982 | 16.7 | Valdivia | NA |
2 | 1982 | 14.3 | Valdivia | NA |
3 | 1982 | 13.1 | Valdivia | NA |
4 | 1982 | 11.6 | Valdivia | NA |
5 | 1982 | 11.0 | Valdivia | NA |
6 | 1982 | 6.2 | Valdivia | NA |
7 | 1982 | 7.5 | Valdivia | NA |
8 | 1982 | 7.8 | Valdivia | NA |
9 | 1982 | 10.2 | Valdivia | NA |
10 | 1982 | 10.2 | Valdivia | NA |
11 | 1982 | 11.6 | Valdivia | NA |
12 | 1982 | 15.5 | Valdivia | NA |
1 | 1983 | 17.5 | Valdivia | NA |
2 | 1983 | 15.2 | Valdivia | NA |
3 | 1983 | 12.8 | Valdivia | NA |
4 | 1983 | 11.1 | Valdivia | NA |
5 | 1983 | 8.4 | Valdivia | NA |
6 | 1983 | 5.7 | Valdivia | NA |
7 | 1983 | 5.4 | Valdivia | NA |
8 | 1983 | 7.1 | Valdivia | NA |
9 | 1983 | 7.6 | Valdivia | NA |
10 | 1983 | 11.1 | Valdivia | NA |
11 | 1983 | 13.5 | Valdivia | NA |
12 | 1983 | 16.7 | Valdivia | NA |
1 | 1984 | 16.1 | Valdivia | NA |
2 | 1984 | 13.8 | Valdivia | NA |
3 | 1984 | 13.6 | Valdivia | NA |
4 | 1984 | 8.8 | Valdivia | NA |
5 | 1984 | 8.1 | Valdivia | NA |
6 | 1984 | 5.0 | Valdivia | NA |
7 | 1984 | 6.0 | Valdivia | NA |
8 | 1984 | 6.7 | Valdivia | NA |
9 | 1984 | 9.4 | Valdivia | NA |
10 | 1984 | 10.2 | Valdivia | NA |
11 | 1984 | 12.8 | Valdivia | NA |
12 | 1984 | 15.3 | Valdivia | NA |
1 | 1985 | 15.8 | Valdivia | NA |
2 | 1985 | 15.3 | Valdivia | NA |
3 | 1985 | 13.4 | Valdivia | NA |
4 | 1985 | 9.6 | Valdivia | NA |
5 | 1985 | 9.4 | Valdivia | NA |
6 | 1985 | 10.3 | Valdivia | NA |
7 | 1985 | 7.0 | Valdivia | NA |
8 | 1985 | 7.5 | Valdivia | NA |
9 | 1985 | 8.5 | Valdivia | NA |
10 | 1985 | 10.0 | Valdivia | NA |
11 | 1985 | 14.1 | Valdivia | NA |
12 | 1985 | 15.3 | Valdivia | NA |
1 | 1986 | 15.0 | Valdivia | NA |
2 | 1986 | 15.1 | Valdivia | NA |
3 | 1986 | 11.9 | Valdivia | NA |
4 | 1986 | 10.9 | Valdivia | NA |
5 | 1986 | 9.4 | Valdivia | NA |
6 | 1986 | 7.3 | Valdivia | NA |
7 | 1986 | 7.6 | Valdivia | NA |
8 | 1986 | 7.1 | Valdivia | NA |
9 | 1986 | 8.7 | Valdivia | NA |
10 | 1986 | 12.2 | Valdivia | NA |
11 | 1986 | 11.4 | Valdivia | NA |
12 | 1986 | 14.6 | Valdivia | NA |
1 | 1987 | 16.2 | Valdivia | NA |
2 | 1987 | 16.0 | Valdivia | NA |
3 | 1987 | 14.6 | Valdivia | NA |
4 | 1987 | 10.8 | Valdivia | NA |
5 | 1987 | 8.0 | Valdivia | NA |
6 | 1987 | 8.1 | Valdivia | NA |
7 | 1987 | 9.0 | Valdivia | NA |
8 | 1987 | 7.3 | Valdivia | NA |
9 | 1987 | 8.8 | Valdivia | NA |
10 | 1987 | 11.4 | Valdivia | NA |
11 | 1987 | 13.7 | Valdivia | NA |
12 | 1987 | 14.7 | Valdivia | NA |
1 | 1988 | 15.6 | Valdivia | NA |
2 | 1988 | 17.1 | Valdivia | NA |
3 | 1988 | 13.4 | Valdivia | NA |
4 | 1988 | 10.4 | Valdivia | NA |
5 | 1988 | 7.8 | Valdivia | NA |
6 | 1988 | 6.8 | Valdivia | NA |
7 | 1988 | 5.0 | Valdivia | NA |
8 | 1988 | 7.7 | Valdivia | NA |
9 | 1988 | 8.7 | Valdivia | NA |
10 | 1988 | 9.8 | Valdivia | NA |
11 | 1988 | 13.3 | Valdivia | NA |
12 | 1988 | 14.3 | Valdivia | NA |
1 | 1989 | 16.6 | Valdivia | NA |
2 | 1989 | 16.1 | Valdivia | NA |
3 | 1989 | 12.3 | Valdivia | NA |
4 | 1989 | 10.3 | Valdivia | NA |
5 | 1989 | 7.4 | Valdivia | NA |
6 | 1989 | 8.6 | Valdivia | NA |
7 | 1989 | 6.7 | Valdivia | NA |
8 | 1989 | 7.5 | Valdivia | NA |
9 | 1989 | 8.1 | Valdivia | NA |
10 | 1989 | 10.9 | Valdivia | NA |
11 | 1989 | 13.2 | Valdivia | NA |
12 | 1989 | 15.2 | Valdivia | NA |
1 | 1990 | 15.8 | Valdivia | NA |
2 | 1990 | 16.0 | Valdivia | NA |
3 | 1990 | 13.0 | Valdivia | NA |
4 | 1990 | 10.2 | Valdivia | NA |
5 | 1990 | 8.6 | Valdivia | NA |
6 | 1990 | 6.7 | Valdivia | NA |
7 | 1990 | 6.7 | Valdivia | NA |
8 | 1990 | 8.8 | Valdivia | NA |
9 | 1990 | 8.8 | Valdivia | NA |
10 | 1990 | 10.4 | Valdivia | NA |
11 | 1990 | 12.0 | Valdivia | NA |
12 | 1990 | 14.4 | Valdivia | NA |
1 | 1991 | 15.3 | Valdivia | NA |
2 | 1991 | 15.7 | Valdivia | NA |
3 | 1991 | 13.3 | Valdivia | NA |
4 | 1991 | 11.2 | Valdivia | NA |
5 | 1991 | 9.0 | Valdivia | NA |
6 | 1991 | 6.6 | Valdivia | NA |
7 | 1991 | 6.5 | Valdivia | NA |
8 | 1991 | 6.4 | Valdivia | NA |
9 | 1991 | 9.4 | Valdivia | NA |
10 | 1991 | 10.2 | Valdivia | NA |
11 | 1991 | 12.8 | Valdivia | NA |
12 | 1991 | 13.0 | Valdivia | NA |
1 | 1992 | 17.3 | Valdivia | NA |
2 | 1992 | 14.3 | Valdivia | NA |
3 | 1992 | 14.9 | Valdivia | NA |
4 | 1992 | 10.1 | Valdivia | NA |
5 | 1992 | 7.8 | Valdivia | NA |
6 | 1992 | 6.9 | Valdivia | NA |
7 | 1992 | 5.1 | Valdivia | NA |
8 | 1992 | 7.8 | Valdivia | NA |
9 | 1992 | 8.7 | Valdivia | NA |
10 | 1992 | 9.5 | Valdivia | NA |
11 | 1992 | 13.8 | Valdivia | NA |
12 | 1992 | 13.7 | Valdivia | NA |
1 | 1993 | 15.0 | Valdivia | NA |
2 | 1993 | 16.3 | Valdivia | NA |
3 | 1993 | 14.6 | Valdivia | NA |
4 | 1993 | 11.3 | Valdivia | NA |
5 | 1993 | 8.8 | Valdivia | NA |
6 | 1993 | 8.3 | Valdivia | NA |
7 | 1993 | 6.3 | Valdivia | NA |
8 | 1993 | 6.8 | Valdivia | NA |
9 | 1993 | 8.8 | Valdivia | NA |
10 | 1993 | 10.9 | Valdivia | NA |
11 | 1993 | 12.3 | Valdivia | NA |
12 | 1993 | 14.5 | Valdivia | NA |
1 | 1994 | 16.1 | Valdivia | NA |
2 | 1994 | 15.3 | Valdivia | NA |
3 | 1994 | 14.3 | Valdivia | NA |
4 | 1994 | 10.6 | Valdivia | NA |
5 | 1994 | 10.1 | Valdivia | NA |
6 | 1994 | 9.4 | Valdivia | NA |
7 | 1994 | 7.1 | Valdivia | NA |
8 | 1994 | 6.7 | Valdivia | NA |
9 | 1994 | 9.0 | Valdivia | NA |
10 | 1994 | 11.3 | Valdivia | NA |
11 | 1994 | 12.8 | Valdivia | NA |
12 | 1994 | 15.2 | Valdivia | NA |
1 | 1995 | 15.1 | Valdivia | NA |
2 | 1995 | 15.1 | Valdivia | NA |
3 | 1995 | 12.7 | Valdivia | NA |
4 | 1995 | 11.8 | Valdivia | NA |
5 | 1995 | 8.8 | Valdivia | NA |
6 | 1995 | 7.4 | Valdivia | NA |
7 | 1995 | 5.6 | Valdivia | NA |
8 | 1995 | 6.3 | Valdivia | NA |
9 | 1995 | 7.7 | Valdivia | NA |
10 | 1995 | 10.4 | Valdivia | NA |
11 | 1995 | 13.1 | Valdivia | NA |
12 | 1995 | 17.3 | Valdivia | NA |
1 | 1996 | 15.4 | Valdivia | NA |
2 | 1996 | 14.8 | Valdivia | NA |
3 | 1996 | 13.8 | Valdivia | NA |
4 | 1996 | 9.6 | Valdivia | NA |
5 | 1996 | 8.7 | Valdivia | NA |
6 | 1996 | 4.4 | Valdivia | NA |
7 | 1996 | 7.8 | Valdivia | NA |
8 | 1996 | 8.6 | Valdivia | NA |
9 | 1996 | 9.3 | Valdivia | NA |
10 | 1996 | 10.6 | Valdivia | NA |
11 | 1996 | 12.5 | Valdivia | NA |
12 | 1996 | 15.2 | Valdivia | NA |
4 | 1997 | 12.3 | Valdivia | NA |
5 | 1997 | 9.9 | Valdivia | NA |
6 | 1997 | 8.7 | Valdivia | NA |
7 | 1997 | 8.1 | Valdivia | NA |
8 | 1997 | 7.6 | Valdivia | NA |
9 | 1997 | 8.9 | Valdivia | NA |
10 | 1997 | 10.3 | Valdivia | NA |
11 | 1997 | 12.8 | Valdivia | NA |
12 | 1997 | 14.9 | Valdivia | NA |
1 | 1998 | 15.2 | Valdivia | NA |
2 | 1998 | 17.4 | Valdivia | NA |
3 | 1998 | 13.2 | Valdivia | NA |
4 | 1998 | 10.9 | Valdivia | NA |
5 | 1998 | 11.4 | Valdivia | NA |
6 | 1998 | 7.6 | Valdivia | NA |
7 | 1998 | 7.4 | Valdivia | NA |
8 | 1998 | 7.3 | Valdivia | NA |
9 | 1998 | 7.4 | Valdivia | NA |
10 | 1998 | 10.6 | Valdivia | NA |
11 | 1998 | 12.1 | Valdivia | NA |
12 | 1998 | 15.2 | Valdivia | NA |
1 | 1999 | 17.4 | Valdivia | NA |
2 | 1999 | 15.7 | Valdivia | NA |
3 | 1999 | 12.7 | Valdivia | NA |
4 | 1999 | 10.1 | Valdivia | NA |
5 | 1999 | 8.1 | Valdivia | NA |
6 | 1999 | 6.0 | Valdivia | NA |
7 | 1999 | 5.6 | Valdivia | NA |
8 | 1999 | 8.3 | Valdivia | NA |
9 | 1999 | 9.3 | Valdivia | NA |
10 | 1999 | 11.3 | Valdivia | NA |
11 | 1999 | 13.5 | Valdivia | NA |
12 | 1999 | 14.8 | Valdivia | NA |
1 | 2000 | 15.5 | Valdivia | NA |
2 | 2000 | 14.8 | Valdivia | NA |
3 | 2000 | 11.6 | Valdivia | NA |
4 | 2000 | 10.6 | Valdivia | NA |
5 | 2000 | 9.1 | Valdivia | NA |
6 | 2000 | 8.5 | Valdivia | NA |
7 | 2000 | 6.1 | Valdivia | NA |
8 | 2000 | 7.8 | Valdivia | NA |
9 | 2000 | 7.7 | Valdivia | NA |
10 | 2000 | 11.5 | Valdivia | NA |
11 | 2000 | 12.2 | Valdivia | NA |
12 | 2000 | 14.1 | Valdivia | NA |
1 | 2001 | 15.3 | Valdivia | NA |
1 | 2007 | 16.2 | Valdivia | NA |
2 | 2010 | 15.4 | Valdivia | NA |
3 | 2010 | 14.9 | Valdivia | NA |
4 | 2010 | 10.9 | Valdivia | NA |
5 | 2010 | 7.7 | Valdivia | NA |
10 | 2010 | 10.0 | Valdivia | NA |
11 | 2010 | 13.6 | Valdivia | NA |
12 | 2010 | 14.9 | Valdivia | NA |
6 | 2011 | 7.5 | Valdivia | NA |
7 | 2011 | 6.5 | Valdivia | NA |
8 | 2011 | 7.1 | Valdivia | NA |
9 | 2011 | 9.3 | Valdivia | NA |
10 | 2011 | 10.2 | Valdivia | NA |
11 | 2011 | 13.2 | Valdivia | NA |
1 | 2012 | 17.5 | Valdivia | NA |
2 | 2012 | 14.9 | Valdivia | NA |
3 | 2012 | 13.7 | Valdivia | NA |
4 | 2012 | 10.2 | Valdivia | NA |
7 | 2012 | 5.3 | Valdivia | NA |
8 | 2012 | 7.6 | Valdivia | NA |
9 | 2012 | 9.1 | Valdivia | NA |
10 | 2012 | 10.7 | Valdivia | NA |
11 | 2012 | 13.5 | Valdivia | NA |
12 | 2012 | 14.2 | Valdivia | NA |
1 | 2013 | 18.8 | Valdivia | NA |
2 | 2013 | 16.6 | Valdivia | NA |
3 | 2013 | 13.6 | Valdivia | NA |
4 | 2013 | 11.9 | Valdivia | NA |
9 | 2013 | 6.8 | Valdivia | NA |
10 | 2013 | 7.0 | Valdivia | NA |
11 | 2013 | 8.1 | Valdivia | NA |
12 | 2013 | 11.0 | Valdivia | NA |
5 | 2013 | 12.5 | Valdivia | NA |
6 | 2013 | 16.7 | Valdivia | NA |
1 | 2014 | 16.2 | Valdivia | 74.5 |
2 | 2014 | 15.5 | Valdivia | 78.2 |
3 | 2014 | 12.4 | Valdivia | 86.2 |
4 | 2014 | 10.4 | Valdivia | 91.3 |
5 | 2014 | 9.8 | Valdivia | 94.1 |
6 | 2014 | 7.1 | Valdivia | 96.2 |
7 | 2014 | 7.5 | Valdivia | 93.5 |
8 | 2014 | 8.2 | Valdivia | 91.3 |
9 | 2014 | 9.0 | Valdivia | 88.2 |
10 | 2014 | 10.4 | Valdivia | 82.9 |
11 | 2014 | 12.4 | Valdivia | 75.5 |
12 | 2014 | 14.6 | Valdivia | 72.1 |
1 | 2015 | 17.4 | Valdivia | 63.5 |
2 | 2015 | 16.1 | Valdivia | 68.1 |
3 | 2015 | 13.9 | Valdivia | 76.4 |
4 | 2015 | 11.7 | Valdivia | 91.3 |
5 | 2015 | 10.3 | Valdivia | 91.8 |
6 | 2015 | 8.0 | Valdivia | 92.2 |
7 | 2015 | 7.9 | Valdivia | 91.3 |
8 | 2015 | 8.6 | Valdivia | 88.7 |
9 | 2015 | 8.0 | Valdivia | 83.2 |
10 | 2015 | 10.4 | Valdivia | 76.7 |
11 | 2015 | 12.7 | Valdivia | 75.9 |
10 | 2016 | 10.8 | Valdivia | 84.0 |
11 | 2016 | 13.6 | Valdivia | 75.0 |
1 | 2016 | 17.4 | Valdivia | 69.0 |
2 | 2016 | 15.5 | Valdivia | 73.0 |
3 | 2016 | 13.5 | Valdivia | NA |
4 | 2016 | 9.2 | Valdivia | NA |
5 | 2016 | 9.5 | Valdivia | 95.0 |
6 | 2016 | 5.8 | Valdivia | 95.0 |
7 | 2016 | 7.0 | Valdivia | 94.0 |
8 | 2016 | 8.9 | Valdivia | 90.0 |
9 | 2016 | 9.2 | Valdivia | 84.0 |
12 | 2016 | 14.8 | Valdivia | 74.0 |
1 | 2017 | 16.4 | Valdivia | 73.1 |
2 | 2017 | 16.9 | Valdivia | 77.9 |
3 | 2017 | 12.8 | Valdivia | 85.4 |
4 | 2017 | 11.9 | Valdivia | 91.5 |
5 | 2017 | 9.0 | Valdivia | NA |
6 | 2017 | 7.6 | Valdivia | 94.5 |
10 | 2017 | 10.1 | Valdivia | 85.5 |
11 | 2017 | 12.5 | Valdivia | 74.4 |
12 | 2017 | 14.8 | Valdivia | 73.5 |
12 | 2015 | NA | Valdivia | 71.0 |
ggplot(VA, aes(x = Mes, y = Temperatura)) + geom_point() + stat_smooth(method = "lm")
ggplot(VA, aes(x = Mes, y = Temperatura)) + geom_point() + stat_smooth(method = "lm", formula = y ~ x + I(x^2))
ModeloCuad <- lm(Temperatura ~ Mes + I(Mes^2), data = VA) Parametros <- tidy(ModeloCuad)
term | estimate | std.error | statistic | p.value |
---|---|---|---|---|
(Intercept) | 21.3117557 | 0.2705337 | 78.77670 | 0 |
Mes | -3.8735044 | 0.0961381 | -40.29105 | 0 |
I(Mes^2) | 0.2769514 | 0.0072012 | 38.45910 | 0 |
library(tidyr) San <- TempHum %>% filter(Ciudad_localidad == "Quinta Normal") %>% pivot_longer(cols = c(Temperatura, Humedad), names_to = "Unidad", values_to = "medida")
ggplot(San, aes(x = Mes, y = medida)) + geom_point() + stat_smooth(method = "lm", formula = y ~ x + I(x^2), aes(fill = Unidad, color = Unidad))