knitr::opts_chunk$set(echo = TRUE)
library(readxl)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Leemos el Excel
datos <- read_excel("Equipos.xlsx", skip = 2)
# Calculamos correlación
correlacion <- cor(datos$Goles, datos$`TÃtulos`)
print(paste("Correlación:", correlacion))
## [1] "Correlación: -0.271522439435476"
# Creamos el modelo
modelo <- lm(`TÃtulos` ~ Goles, data = datos)
summary(modelo)
##
## Call:
## lm(formula = TÃtulos ~ Goles, data = datos)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1225 -1.7209 -0.9092 -0.1171 11.3269
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.92009 2.35760 2.511 0.0199 *
## Goles -0.08988 0.06792 -1.323 0.1993
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.124 on 22 degrees of freedom
## Multiple R-squared: 0.07372, Adjusted R-squared: 0.03162
## F-statistic: 1.751 on 1 and 22 DF, p-value: 0.1993
ggplot(datos, aes(x = Goles, y = `TÃtulos`)) +
geom_point(color = "blue", size = 3) +
geom_smooth(method = "lm", color = "red") +
labs(title = "Regresión Lineal Simple", x = "Goles", y = "TÃtulos") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

par(mfrow=c(2,2))
plot(modelo)
