#Regresión lineal
Ejercicio con el manual de Ciencia de Datos para Gente Sociable
options(scipen = 999)
library(tidyverse)
data_mundial <- read_csv("https://bitsandbricks.github.io/data/gapminder.csv")
Seleccionamos el paÃs Argentina
argentina <- data_mundial |>
filter(pais == "Argentina")
Hacemos un gráfico
ggplot(argentina)+
geom_point(aes(x=anio, y=expVida))+
geom_smooth(aes(x=anio, y=expVida),method = "lm")
## `geom_smooth()` using formula = 'y ~ x'
Y calculamos la regresión
regresion <- lm(data= argentina,
expVida~anio)
summary(regresion)
##
## Call:
## lm(formula = expVida ~ anio, data = argentina)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.53006 -0.13516 -0.01219 0.14228 0.55202
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -389.606345 9.677730 -40.26 0.000000000002140 ***
## anio 0.231708 0.004889 47.40 0.000000000000422 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2923 on 10 degrees of freedom
## Multiple R-squared: 0.9956, Adjusted R-squared: 0.9951
## F-statistic: 2246 on 1 and 10 DF, p-value: 0.0000000000004216