Para resolver este ejercicio tendrán que apelar a lo que aprendieron en las clases anteriores pero también (y no menor) a la lógica y a la buena amiga internet (animense a googlear los nombres de los test, sus interpretaciones y todo lo que los pueda ayudar a completar el ejercicio wikipedia es un buen inicio)
Este famoso conjunto de datos de iris (de Fisher o de Anderson) da las medidas en centímetros de las variables longitud y anchura de los sépalos ( sepal.length y sepal.width) y longitud y anchura de los pétalos ( petal.length y petal.width), respectivamente, para 50 flores de cada una de las 3 especies de iris. Las especies son Iris setosa, versicolor y virginica.
La base se ve así
data<-iris
head(data,3)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
Y está estructurada así:
str(data)
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
Veamos una estadistica de resumen de esta base:
summary(data)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## setosa :50
## versicolor:50
## virginica :50
##
##
##
Hacemos algunos gráficos para ver:
library("ggpubr")
# grafico de densidad
ggdensity(data$Petal.Length, fill = "lightgray")+
ggtitle("Petal Length", "density plot")
# QQ plot
ggqqplot(data$Petal.Length)+
ggtitle("Petal Length", "QQ Plot")
#Boxplot
boxplot(data$Petal.Length)
#correlacion de Pearson
cor.test(data$Petal.Length, data$Petal.Width)
##
## Pearson's product-moment correlation
##
## data: data$Petal.Length and data$Petal.Width
## t = 43.387, df = 148, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9490525 0.9729853
## sample estimates:
## cor
## 0.9628654
Vamos a incluir un grafiquito para ayudarnos a intepretar
ggplot(data, aes(x=Petal.Length, y=Petal.Width))+
geom_point()
ggplot(data, aes(x=Petal.Length, y=Petal.Width, color=Species))+
geom_point()+
geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'
data2<-data %>% filter(Species !="setosa") # aplique un filtro para quedarme solo con dos especies de plantas: versicolor y virginica
t.test(data2$Petal.Length ~ data2$Species)
##
## Welch Two Sample t-test
##
## data: data2$Petal.Length by data2$Species
## t = -12.604, df = 95.57, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.49549 -1.08851
## sample estimates:
## mean in group versicolor mean in group virginica
## 4.260 5.552
Vamos a incluir un grafiquito para ayudarnos a intepretar
ggplot(data2, aes(y=Petal.Length, x=Species))+
geom_boxplot()
data2$Species<-factor(data2$Species,
levels = c("versicolor", "virginica"))
data2 %>% tbl_summary(by="Species", missing = "no") %>%
add_p() %>%
add_overall()
| Characteristic | Overall, N = 1001 | versicolor, N = 501 | virginica, N = 501 | p-value2 |
|---|---|---|---|---|
| Sepal.Length | 6.30 (5.80, 6.70) | 5.90 (5.60, 6.30) | 6.50 (6.23, 6.90) | <0.001 |
| Sepal.Width | 2.90 (2.70, 3.02) | 2.80 (2.52, 3.00) | 3.00 (2.80, 3.18) | 0.005 |
| Petal.Length | 4.90 (4.38, 5.53) | 4.35 (4.00, 4.60) | 5.55 (5.10, 5.88) | <0.001 |
| Petal.Width | 1.60 (1.30, 2.00) | 1.30 (1.20, 1.50) | 2.00 (1.80, 2.30) | <0.001 |
| 1 Median (IQR) | ||||
| 2 Wilcoxon rank sum test | ||||