#Cargamos librerías que usaremos en los ejercicios
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.4.3
## Warning: package 'ggplot2' was built under R version 4.4.3
## Warning: package 'tibble' was built under R version 4.4.2
## Warning: package 'tidyr' was built under R version 4.4.3
## Warning: package 'readr' was built under R version 4.4.2
## Warning: package 'purrr' was built under R version 4.4.2
## Warning: package 'dplyr' was built under R version 4.4.3
## Warning: package 'stringr' was built under R version 4.4.2
## Warning: package 'forcats' was built under R version 4.4.2
## Warning: package 'lubridate' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(psych)
## Warning: package 'psych' was built under R version 4.4.3
## 
## Adjuntando el paquete: 'psych'
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(rapportools)
## Warning: package 'rapportools' was built under R version 4.4.3
## 
## Adjuntando el paquete: 'rapportools'
## 
## The following object is masked from 'package:dplyr':
## 
##     n
## 
## The following objects are masked from 'package:stats':
## 
##     IQR, median, sd, var
## 
## The following objects are masked from 'package:base':
## 
##     max, mean, min, range, sum
library(knitr)
## Warning: package 'knitr' was built under R version 4.4.2

EJERCICIO 1

El package de R datasets (https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html) pone a nuestra disposición una serie de conjuntos de datos con los que poder trabajar como, por ejemplo, iris, cars o Titanic. Escoged un conjunto de datos. Deberéis:
• Buscar un resumen estadístico de las variables del dataset Iris y Orange.

• Generar una tabla de frecuencias absolutas y una tabla de frecuencias relativas con el dataset Iris. ¿Todas las tablas generadas tienen sentido para vosotros?

• Generar una tabla de frecuencias absolutas con cada una de las variables del conjunto de datos Orange. ¿Todas las tablas generadas tienen sentido para vosotros?

• Generar una tabla de doble entrada entre las variables Tree y Age de Orange.

#Parte 1 - Escogemos el conjunto iris
data("iris")
view(iris)
summary(iris)
##   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  
##                 
##                 
## 
data("Orange")
view(Orange)
summary(Orange)
##  Tree       age         circumference  
##  3:7   Min.   : 118.0   Min.   : 30.0  
##  1:7   1st Qu.: 484.0   1st Qu.: 65.5  
##  5:7   Median :1004.0   Median :115.0  
##  2:7   Mean   : 922.1   Mean   :115.9  
##  4:7   3rd Qu.:1372.0   3rd Qu.:161.5  
##        Max.   :1582.0   Max.   :214.0
print(summary(iris))
##   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  
##                 
##                 
## 
print(summary(Orange))
##  Tree       age         circumference  
##  3:7   Min.   : 118.0   Min.   : 30.0  
##  1:7   1st Qu.: 484.0   1st Qu.: 65.5  
##  5:7   Median :1004.0   Median :115.0  
##  2:7   Mean   : 922.1   Mean   :115.9  
##  4:7   3rd Qu.:1372.0   3rd Qu.:161.5  
##        Max.   :1582.0   Max.   :214.0
#Parte 2 - # Tablas de frecuencia absolutas
kable(table(iris$Sepal.Length), caption = "Frecuencia de Sepal.Length")
Frecuencia de Sepal.Length
Var1 Freq
4.3 1
4.4 3
4.5 1
4.6 4
4.7 2
4.8 5
4.9 6
5 10
5.1 9
5.2 4
5.3 1
5.4 6
5.5 7
5.6 6
5.7 8
5.8 7
5.9 3
6 6
6.1 6
6.2 4
6.3 9
6.4 7
6.5 5
6.6 2
6.7 8
6.8 3
6.9 4
7 1
7.1 1
7.2 3
7.3 1
7.4 1
7.6 1
7.7 4
7.9 1
kable(table(iris$Sepal.Width), caption = "Frecuencia de Sepal.Width")  
Frecuencia de Sepal.Width
Var1 Freq
2 1
2.2 3
2.3 4
2.4 3
2.5 8
2.6 5
2.7 9
2.8 14
2.9 10
3 26
3.1 11
3.2 13
3.3 6
3.4 12
3.5 6
3.6 4
3.7 3
3.8 6
3.9 2
4 1
4.1 1
4.2 1
4.4 1
kable(table(iris$Petal.Length), caption = "Frecuencia de Petal.Length")
Frecuencia de Petal.Length
Var1 Freq
1 1
1.1 1
1.2 2
1.3 7
1.4 13
1.5 13
1.6 7
1.7 4
1.9 2
3 1
3.3 2
3.5 2
3.6 1
3.7 1
3.8 1
3.9 3
4 5
4.1 3
4.2 4
4.3 2
4.4 4
4.5 8
4.6 3
4.7 5
4.8 4
4.9 5
5 4
5.1 8
5.2 2
5.3 2
5.4 2
5.5 3
5.6 6
5.7 3
5.8 3
5.9 2
6 2
6.1 3
6.3 1
6.4 1
6.6 1
6.7 2
6.9 1
kable(table(iris$Petal.Width), caption = "Frecuencia de Petal.Width")
Frecuencia de Petal.Width
Var1 Freq
0.1 5
0.2 29
0.3 7
0.4 7
0.5 1
0.6 1
1 7
1.1 3
1.2 5
1.3 13
1.4 8
1.5 12
1.6 4
1.7 2
1.8 12
1.9 5
2 6
2.1 6
2.2 3
2.3 8
2.4 3
2.5 3
kable(table(iris$Species), caption = "Frecuencia de Species")
Frecuencia de Species
Var1 Freq
setosa 50
versicolor 50
virginica 50
# Tablas de frecuencias relativas
kable(prop.table(table(iris$Sepal.Length)), caption = "Proporción de Sepal.Length")
Proporción de Sepal.Length
Var1 Freq
4.3 0.0066667
4.4 0.0200000
4.5 0.0066667
4.6 0.0266667
4.7 0.0133333
4.8 0.0333333
4.9 0.0400000
5 0.0666667
5.1 0.0600000
5.2 0.0266667
5.3 0.0066667
5.4 0.0400000
5.5 0.0466667
5.6 0.0400000
5.7 0.0533333
5.8 0.0466667
5.9 0.0200000
6 0.0400000
6.1 0.0400000
6.2 0.0266667
6.3 0.0600000
6.4 0.0466667
6.5 0.0333333
6.6 0.0133333
6.7 0.0533333
6.8 0.0200000
6.9 0.0266667
7 0.0066667
7.1 0.0066667
7.2 0.0200000
7.3 0.0066667
7.4 0.0066667
7.6 0.0066667
7.7 0.0266667
7.9 0.0066667
kable(prop.table(table(iris$Sepal.Width)), caption = "Proporción de Sepal.Width")
Proporción de Sepal.Width
Var1 Freq
2 0.0066667
2.2 0.0200000
2.3 0.0266667
2.4 0.0200000
2.5 0.0533333
2.6 0.0333333
2.7 0.0600000
2.8 0.0933333
2.9 0.0666667
3 0.1733333
3.1 0.0733333
3.2 0.0866667
3.3 0.0400000
3.4 0.0800000
3.5 0.0400000
3.6 0.0266667
3.7 0.0200000
3.8 0.0400000
3.9 0.0133333
4 0.0066667
4.1 0.0066667
4.2 0.0066667
4.4 0.0066667
kable(prop.table(table(iris$Petal.Length)), caption = "Proporción de Petal.Length")
Proporción de Petal.Length
Var1 Freq
1 0.0066667
1.1 0.0066667
1.2 0.0133333
1.3 0.0466667
1.4 0.0866667
1.5 0.0866667
1.6 0.0466667
1.7 0.0266667
1.9 0.0133333
3 0.0066667
3.3 0.0133333
3.5 0.0133333
3.6 0.0066667
3.7 0.0066667
3.8 0.0066667
3.9 0.0200000
4 0.0333333
4.1 0.0200000
4.2 0.0266667
4.3 0.0133333
4.4 0.0266667
4.5 0.0533333
4.6 0.0200000
4.7 0.0333333
4.8 0.0266667
4.9 0.0333333
5 0.0266667
5.1 0.0533333
5.2 0.0133333
5.3 0.0133333
5.4 0.0133333
5.5 0.0200000
5.6 0.0400000
5.7 0.0200000
5.8 0.0200000
5.9 0.0133333
6 0.0133333
6.1 0.0200000
6.3 0.0066667
6.4 0.0066667
6.6 0.0066667
6.7 0.0133333
6.9 0.0066667
kable(prop.table(table(iris$Petal.Width)), caption = "Proporción de Petal.Width")
Proporción de Petal.Width
Var1 Freq
0.1 0.0333333
0.2 0.1933333
0.3 0.0466667
0.4 0.0466667
0.5 0.0066667
0.6 0.0066667
1 0.0466667
1.1 0.0200000
1.2 0.0333333
1.3 0.0866667
1.4 0.0533333
1.5 0.0800000
1.6 0.0266667
1.7 0.0133333
1.8 0.0800000
1.9 0.0333333
2 0.0400000
2.1 0.0400000
2.2 0.0200000
2.3 0.0533333
2.4 0.0200000
2.5 0.0200000

Para variables como species sí puede tener sentido ya que es una variable categórica, por lo que las frecuencias absolutas y relativas nos dicen cuántos casos hay de cada especie.

Para variables numéricas solo tendría sentido si agrupamos por rangos ya que hacer una tabla de frecuencias con valores exactos generara una tabla con muchos valores únicos y frecuencias muy bajas

#Parte 3
kable(table(Orange))
Tree age circumference Freq
3 118 30 1
1 118 30 1
5 118 30 1
2 118 30 0
4 118 30 0
3 484 30 0
1 484 30 0
5 484 30 0
2 484 30 0
4 484 30 0
3 664 30 0
1 664 30 0
5 664 30 0
2 664 30 0
4 664 30 0
3 1004 30 0
1 1004 30 0
5 1004 30 0
2 1004 30 0
4 1004 30 0
3 1231 30 0
1 1231 30 0
5 1231 30 0
2 1231 30 0
4 1231 30 0
3 1372 30 0
1 1372 30 0
5 1372 30 0
2 1372 30 0
4 1372 30 0
3 1582 30 0
1 1582 30 0
5 1582 30 0
2 1582 30 0
4 1582 30 0
3 118 32 0
1 118 32 0
5 118 32 0
2 118 32 0
4 118 32 1
3 484 32 0
1 484 32 0
5 484 32 0
2 484 32 0
4 484 32 0
3 664 32 0
1 664 32 0
5 664 32 0
2 664 32 0
4 664 32 0
3 1004 32 0
1 1004 32 0
5 1004 32 0
2 1004 32 0
4 1004 32 0
3 1231 32 0
1 1231 32 0
5 1231 32 0
2 1231 32 0
4 1231 32 0
3 1372 32 0
1 1372 32 0
5 1372 32 0
2 1372 32 0
4 1372 32 0
3 1582 32 0
1 1582 32 0
5 1582 32 0
2 1582 32 0
4 1582 32 0
3 118 33 0
1 118 33 0
5 118 33 0
2 118 33 1
4 118 33 0
3 484 33 0
1 484 33 0
5 484 33 0
2 484 33 0
4 484 33 0
3 664 33 0
1 664 33 0
5 664 33 0
2 664 33 0
4 664 33 0
3 1004 33 0
1 1004 33 0
5 1004 33 0
2 1004 33 0
4 1004 33 0
3 1231 33 0
1 1231 33 0
5 1231 33 0
2 1231 33 0
4 1231 33 0
3 1372 33 0
1 1372 33 0
5 1372 33 0
2 1372 33 0
4 1372 33 0
3 1582 33 0
1 1582 33 0
5 1582 33 0
2 1582 33 0
4 1582 33 0
3 118 49 0
1 118 49 0
5 118 49 0
2 118 49 0
4 118 49 0
3 484 49 0
1 484 49 0
5 484 49 1
2 484 49 0
4 484 49 0
3 664 49 0
1 664 49 0
5 664 49 0
2 664 49 0
4 664 49 0
3 1004 49 0
1 1004 49 0
5 1004 49 0
2 1004 49 0
4 1004 49 0
3 1231 49 0
1 1231 49 0
5 1231 49 0
2 1231 49 0
4 1231 49 0
3 1372 49 0
1 1372 49 0
5 1372 49 0
2 1372 49 0
4 1372 49 0
3 1582 49 0
1 1582 49 0
5 1582 49 0
2 1582 49 0
4 1582 49 0
3 118 51 0
1 118 51 0
5 118 51 0
2 118 51 0
4 118 51 0
3 484 51 1
1 484 51 0
5 484 51 0
2 484 51 0
4 484 51 0
3 664 51 0
1 664 51 0
5 664 51 0
2 664 51 0
4 664 51 0
3 1004 51 0
1 1004 51 0
5 1004 51 0
2 1004 51 0
4 1004 51 0
3 1231 51 0
1 1231 51 0
5 1231 51 0
2 1231 51 0
4 1231 51 0
3 1372 51 0
1 1372 51 0
5 1372 51 0
2 1372 51 0
4 1372 51 0
3 1582 51 0
1 1582 51 0
5 1582 51 0
2 1582 51 0
4 1582 51 0
3 118 58 0
1 118 58 0
5 118 58 0
2 118 58 0
4 118 58 0
3 484 58 0
1 484 58 1
5 484 58 0
2 484 58 0
4 484 58 0
3 664 58 0
1 664 58 0
5 664 58 0
2 664 58 0
4 664 58 0
3 1004 58 0
1 1004 58 0
5 1004 58 0
2 1004 58 0
4 1004 58 0
3 1231 58 0
1 1231 58 0
5 1231 58 0
2 1231 58 0
4 1231 58 0
3 1372 58 0
1 1372 58 0
5 1372 58 0
2 1372 58 0
4 1372 58 0
3 1582 58 0
1 1582 58 0
5 1582 58 0
2 1582 58 0
4 1582 58 0
3 118 62 0
1 118 62 0
5 118 62 0
2 118 62 0
4 118 62 0
3 484 62 0
1 484 62 0
5 484 62 0
2 484 62 0
4 484 62 1
3 664 62 0
1 664 62 0
5 664 62 0
2 664 62 0
4 664 62 0
3 1004 62 0
1 1004 62 0
5 1004 62 0
2 1004 62 0
4 1004 62 0
3 1231 62 0
1 1231 62 0
5 1231 62 0
2 1231 62 0
4 1231 62 0
3 1372 62 0
1 1372 62 0
5 1372 62 0
2 1372 62 0
4 1372 62 0
3 1582 62 0
1 1582 62 0
5 1582 62 0
2 1582 62 0
4 1582 62 0
3 118 69 0
1 118 69 0
5 118 69 0
2 118 69 0
4 118 69 0
3 484 69 0
1 484 69 0
5 484 69 0
2 484 69 1
4 484 69 0
3 664 69 0
1 664 69 0
5 664 69 0
2 664 69 0
4 664 69 0
3 1004 69 0
1 1004 69 0
5 1004 69 0
2 1004 69 0
4 1004 69 0
3 1231 69 0
1 1231 69 0
5 1231 69 0
2 1231 69 0
4 1231 69 0
3 1372 69 0
1 1372 69 0
5 1372 69 0
2 1372 69 0
4 1372 69 0
3 1582 69 0
1 1582 69 0
5 1582 69 0
2 1582 69 0
4 1582 69 0
3 118 75 0
1 118 75 0
5 118 75 0
2 118 75 0
4 118 75 0
3 484 75 0
1 484 75 0
5 484 75 0
2 484 75 0
4 484 75 0
3 664 75 1
1 664 75 0
5 664 75 0
2 664 75 0
4 664 75 0
3 1004 75 0
1 1004 75 0
5 1004 75 0
2 1004 75 0
4 1004 75 0
3 1231 75 0
1 1231 75 0
5 1231 75 0
2 1231 75 0
4 1231 75 0
3 1372 75 0
1 1372 75 0
5 1372 75 0
2 1372 75 0
4 1372 75 0
3 1582 75 0
1 1582 75 0
5 1582 75 0
2 1582 75 0
4 1582 75 0
3 118 81 0
1 118 81 0
5 118 81 0
2 118 81 0
4 118 81 0
3 484 81 0
1 484 81 0
5 484 81 0
2 484 81 0
4 484 81 0
3 664 81 0
1 664 81 0
5 664 81 1
2 664 81 0
4 664 81 0
3 1004 81 0
1 1004 81 0
5 1004 81 0
2 1004 81 0
4 1004 81 0
3 1231 81 0
1 1231 81 0
5 1231 81 0
2 1231 81 0
4 1231 81 0
3 1372 81 0
1 1372 81 0
5 1372 81 0
2 1372 81 0
4 1372 81 0
3 1582 81 0
1 1582 81 0
5 1582 81 0
2 1582 81 0
4 1582 81 0
3 118 87 0
1 118 87 0
5 118 87 0
2 118 87 0
4 118 87 0
3 484 87 0
1 484 87 0
5 484 87 0
2 484 87 0
4 484 87 0
3 664 87 0
1 664 87 1
5 664 87 0
2 664 87 0
4 664 87 0
3 1004 87 0
1 1004 87 0
5 1004 87 0
2 1004 87 0
4 1004 87 0
3 1231 87 0
1 1231 87 0
5 1231 87 0
2 1231 87 0
4 1231 87 0
3 1372 87 0
1 1372 87 0
5 1372 87 0
2 1372 87 0
4 1372 87 0
3 1582 87 0
1 1582 87 0
5 1582 87 0
2 1582 87 0
4 1582 87 0
3 118 108 0
1 118 108 0
5 118 108 0
2 118 108 0
4 118 108 0
3 484 108 0
1 484 108 0
5 484 108 0
2 484 108 0
4 484 108 0
3 664 108 0
1 664 108 0
5 664 108 0
2 664 108 0
4 664 108 0
3 1004 108 1
1 1004 108 0
5 1004 108 0
2 1004 108 0
4 1004 108 0
3 1231 108 0
1 1231 108 0
5 1231 108 0
2 1231 108 0
4 1231 108 0
3 1372 108 0
1 1372 108 0
5 1372 108 0
2 1372 108 0
4 1372 108 0
3 1582 108 0
1 1582 108 0
5 1582 108 0
2 1582 108 0
4 1582 108 0
3 118 111 0
1 118 111 0
5 118 111 0
2 118 111 0
4 118 111 0
3 484 111 0
1 484 111 0
5 484 111 0
2 484 111 0
4 484 111 0
3 664 111 0
1 664 111 0
5 664 111 0
2 664 111 1
4 664 111 0
3 1004 111 0
1 1004 111 0
5 1004 111 0
2 1004 111 0
4 1004 111 0
3 1231 111 0
1 1231 111 0
5 1231 111 0
2 1231 111 0
4 1231 111 0
3 1372 111 0
1 1372 111 0
5 1372 111 0
2 1372 111 0
4 1372 111 0
3 1582 111 0
1 1582 111 0
5 1582 111 0
2 1582 111 0
4 1582 111 0
3 118 112 0
1 118 112 0
5 118 112 0
2 118 112 0
4 118 112 0
3 484 112 0
1 484 112 0
5 484 112 0
2 484 112 0
4 484 112 0
3 664 112 0
1 664 112 0
5 664 112 0
2 664 112 0
4 664 112 1
3 1004 112 0
1 1004 112 0
5 1004 112 0
2 1004 112 0
4 1004 112 0
3 1231 112 0
1 1231 112 0
5 1231 112 0
2 1231 112 0
4 1231 112 0
3 1372 112 0
1 1372 112 0
5 1372 112 0
2 1372 112 0
4 1372 112 0
3 1582 112 0
1 1582 112 0
5 1582 112 0
2 1582 112 0
4 1582 112 0
3 118 115 0
1 118 115 0
5 118 115 0
2 118 115 0
4 118 115 0
3 484 115 0
1 484 115 0
5 484 115 0
2 484 115 0
4 484 115 0
3 664 115 0
1 664 115 0
5 664 115 0
2 664 115 0
4 664 115 0
3 1004 115 0
1 1004 115 1
5 1004 115 0
2 1004 115 0
4 1004 115 0
3 1231 115 1
1 1231 115 0
5 1231 115 0
2 1231 115 0
4 1231 115 0
3 1372 115 0
1 1372 115 0
5 1372 115 0
2 1372 115 0
4 1372 115 0
3 1582 115 0
1 1582 115 0
5 1582 115 0
2 1582 115 0
4 1582 115 0
3 118 120 0
1 118 120 0
5 118 120 0
2 118 120 0
4 118 120 0
3 484 120 0
1 484 120 0
5 484 120 0
2 484 120 0
4 484 120 0
3 664 120 0
1 664 120 0
5 664 120 0
2 664 120 0
4 664 120 0
3 1004 120 0
1 1004 120 0
5 1004 120 0
2 1004 120 0
4 1004 120 0
3 1231 120 0
1 1231 120 1
5 1231 120 0
2 1231 120 0
4 1231 120 0
3 1372 120 0
1 1372 120 0
5 1372 120 0
2 1372 120 0
4 1372 120 0
3 1582 120 0
1 1582 120 0
5 1582 120 0
2 1582 120 0
4 1582 120 0
3 118 125 0
1 118 125 0
5 118 125 0
2 118 125 0
4 118 125 0
3 484 125 0
1 484 125 0
5 484 125 0
2 484 125 0
4 484 125 0
3 664 125 0
1 664 125 0
5 664 125 0
2 664 125 0
4 664 125 0
3 1004 125 0
1 1004 125 0
5 1004 125 1
2 1004 125 0
4 1004 125 0
3 1231 125 0
1 1231 125 0
5 1231 125 0
2 1231 125 0
4 1231 125 0
3 1372 125 0
1 1372 125 0
5 1372 125 0
2 1372 125 0
4 1372 125 0
3 1582 125 0
1 1582 125 0
5 1582 125 0
2 1582 125 0
4 1582 125 0
3 118 139 0
1 118 139 0
5 118 139 0
2 118 139 0
4 118 139 0
3 484 139 0
1 484 139 0
5 484 139 0
2 484 139 0
4 484 139 0
3 664 139 0
1 664 139 0
5 664 139 0
2 664 139 0
4 664 139 0
3 1004 139 0
1 1004 139 0
5 1004 139 0
2 1004 139 0
4 1004 139 0
3 1231 139 0
1 1231 139 0
5 1231 139 0
2 1231 139 0
4 1231 139 0
3 1372 139 1
1 1372 139 0
5 1372 139 0
2 1372 139 0
4 1372 139 0
3 1582 139 0
1 1582 139 0
5 1582 139 0
2 1582 139 0
4 1582 139 0
3 118 140 0
1 118 140 0
5 118 140 0
2 118 140 0
4 118 140 0
3 484 140 0
1 484 140 0
5 484 140 0
2 484 140 0
4 484 140 0
3 664 140 0
1 664 140 0
5 664 140 0
2 664 140 0
4 664 140 0
3 1004 140 0
1 1004 140 0
5 1004 140 0
2 1004 140 0
4 1004 140 0
3 1231 140 0
1 1231 140 0
5 1231 140 0
2 1231 140 0
4 1231 140 0
3 1372 140 0
1 1372 140 0
5 1372 140 0
2 1372 140 0
4 1372 140 0
3 1582 140 1
1 1582 140 0
5 1582 140 0
2 1582 140 0
4 1582 140 0
3 118 142 0
1 118 142 0
5 118 142 0
2 118 142 0
4 118 142 0
3 484 142 0
1 484 142 0
5 484 142 0
2 484 142 0
4 484 142 0
3 664 142 0
1 664 142 0
5 664 142 0
2 664 142 0
4 664 142 0
3 1004 142 0
1 1004 142 0
5 1004 142 0
2 1004 142 0
4 1004 142 0
3 1231 142 0
1 1231 142 0
5 1231 142 1
2 1231 142 0
4 1231 142 0
3 1372 142 0
1 1372 142 1
5 1372 142 0
2 1372 142 0
4 1372 142 0
3 1582 142 0
1 1582 142 0
5 1582 142 0
2 1582 142 0
4 1582 142 0
3 118 145 0
1 118 145 0
5 118 145 0
2 118 145 0
4 118 145 0
3 484 145 0
1 484 145 0
5 484 145 0
2 484 145 0
4 484 145 0
3 664 145 0
1 664 145 0
5 664 145 0
2 664 145 0
4 664 145 0
3 1004 145 0
1 1004 145 0
5 1004 145 0
2 1004 145 0
4 1004 145 0
3 1231 145 0
1 1231 145 0
5 1231 145 0
2 1231 145 0
4 1231 145 0
3 1372 145 0
1 1372 145 0
5 1372 145 0
2 1372 145 0
4 1372 145 0
3 1582 145 0
1 1582 145 1
5 1582 145 0
2 1582 145 0
4 1582 145 0
3 118 156 0
1 118 156 0
5 118 156 0
2 118 156 0
4 118 156 0
3 484 156 0
1 484 156 0
5 484 156 0
2 484 156 0
4 484 156 0
3 664 156 0
1 664 156 0
5 664 156 0
2 664 156 0
4 664 156 0
3 1004 156 0
1 1004 156 0
5 1004 156 0
2 1004 156 1
4 1004 156 0
3 1231 156 0
1 1231 156 0
5 1231 156 0
2 1231 156 0
4 1231 156 0
3 1372 156 0
1 1372 156 0
5 1372 156 0
2 1372 156 0
4 1372 156 0
3 1582 156 0
1 1582 156 0
5 1582 156 0
2 1582 156 0
4 1582 156 0
3 118 167 0
1 118 167 0
5 118 167 0
2 118 167 0
4 118 167 0
3 484 167 0
1 484 167 0
5 484 167 0
2 484 167 0
4 484 167 0
3 664 167 0
1 664 167 0
5 664 167 0
2 664 167 0
4 664 167 0
3 1004 167 0
1 1004 167 0
5 1004 167 0
2 1004 167 0
4 1004 167 1
3 1231 167 0
1 1231 167 0
5 1231 167 0
2 1231 167 0
4 1231 167 0
3 1372 167 0
1 1372 167 0
5 1372 167 0
2 1372 167 0
4 1372 167 0
3 1582 167 0
1 1582 167 0
5 1582 167 0
2 1582 167 0
4 1582 167 0
3 118 172 0
1 118 172 0
5 118 172 0
2 118 172 0
4 118 172 0
3 484 172 0
1 484 172 0
5 484 172 0
2 484 172 0
4 484 172 0
3 664 172 0
1 664 172 0
5 664 172 0
2 664 172 0
4 664 172 0
3 1004 172 0
1 1004 172 0
5 1004 172 0
2 1004 172 0
4 1004 172 0
3 1231 172 0
1 1231 172 0
5 1231 172 0
2 1231 172 1
4 1231 172 0
3 1372 172 0
1 1372 172 0
5 1372 172 0
2 1372 172 0
4 1372 172 0
3 1582 172 0
1 1582 172 0
5 1582 172 0
2 1582 172 0
4 1582 172 0
3 118 174 0
1 118 174 0
5 118 174 0
2 118 174 0
4 118 174 0
3 484 174 0
1 484 174 0
5 484 174 0
2 484 174 0
4 484 174 0
3 664 174 0
1 664 174 0
5 664 174 0
2 664 174 0
4 664 174 0
3 1004 174 0
1 1004 174 0
5 1004 174 0
2 1004 174 0
4 1004 174 0
3 1231 174 0
1 1231 174 0
5 1231 174 0
2 1231 174 0
4 1231 174 0
3 1372 174 0
1 1372 174 0
5 1372 174 1
2 1372 174 0
4 1372 174 0
3 1582 174 0
1 1582 174 0
5 1582 174 0
2 1582 174 0
4 1582 174 0
3 118 177 0
1 118 177 0
5 118 177 0
2 118 177 0
4 118 177 0
3 484 177 0
1 484 177 0
5 484 177 0
2 484 177 0
4 484 177 0
3 664 177 0
1 664 177 0
5 664 177 0
2 664 177 0
4 664 177 0
3 1004 177 0
1 1004 177 0
5 1004 177 0
2 1004 177 0
4 1004 177 0
3 1231 177 0
1 1231 177 0
5 1231 177 0
2 1231 177 0
4 1231 177 0
3 1372 177 0
1 1372 177 0
5 1372 177 0
2 1372 177 0
4 1372 177 0
3 1582 177 0
1 1582 177 0
5 1582 177 1
2 1582 177 0
4 1582 177 0
3 118 179 0
1 118 179 0
5 118 179 0
2 118 179 0
4 118 179 0
3 484 179 0
1 484 179 0
5 484 179 0
2 484 179 0
4 484 179 0
3 664 179 0
1 664 179 0
5 664 179 0
2 664 179 0
4 664 179 0
3 1004 179 0
1 1004 179 0
5 1004 179 0
2 1004 179 0
4 1004 179 0
3 1231 179 0
1 1231 179 0
5 1231 179 0
2 1231 179 0
4 1231 179 1
3 1372 179 0
1 1372 179 0
5 1372 179 0
2 1372 179 0
4 1372 179 0
3 1582 179 0
1 1582 179 0
5 1582 179 0
2 1582 179 0
4 1582 179 0
3 118 203 0
1 118 203 0
5 118 203 0
2 118 203 0
4 118 203 0
3 484 203 0
1 484 203 0
5 484 203 0
2 484 203 0
4 484 203 0
3 664 203 0
1 664 203 0
5 664 203 0
2 664 203 0
4 664 203 0
3 1004 203 0
1 1004 203 0
5 1004 203 0
2 1004 203 0
4 1004 203 0
3 1231 203 0
1 1231 203 0
5 1231 203 0
2 1231 203 0
4 1231 203 0
3 1372 203 0
1 1372 203 0
5 1372 203 0
2 1372 203 1
4 1372 203 0
3 1582 203 0
1 1582 203 0
5 1582 203 0
2 1582 203 1
4 1582 203 0
3 118 209 0
1 118 209 0
5 118 209 0
2 118 209 0
4 118 209 0
3 484 209 0
1 484 209 0
5 484 209 0
2 484 209 0
4 484 209 0
3 664 209 0
1 664 209 0
5 664 209 0
2 664 209 0
4 664 209 0
3 1004 209 0
1 1004 209 0
5 1004 209 0
2 1004 209 0
4 1004 209 0
3 1231 209 0
1 1231 209 0
5 1231 209 0
2 1231 209 0
4 1231 209 0
3 1372 209 0
1 1372 209 0
5 1372 209 0
2 1372 209 0
4 1372 209 1
3 1582 209 0
1 1582 209 0
5 1582 209 0
2 1582 209 0
4 1582 209 0
3 118 214 0
1 118 214 0
5 118 214 0
2 118 214 0
4 118 214 0
3 484 214 0
1 484 214 0
5 484 214 0
2 484 214 0
4 484 214 0
3 664 214 0
1 664 214 0
5 664 214 0
2 664 214 0
4 664 214 0
3 1004 214 0
1 1004 214 0
5 1004 214 0
2 1004 214 0
4 1004 214 0
3 1231 214 0
1 1231 214 0
5 1231 214 0
2 1231 214 0
4 1231 214 0
3 1372 214 0
1 1372 214 0
5 1372 214 0
2 1372 214 0
4 1372 214 0
3 1582 214 0
1 1582 214 0
5 1582 214 0
2 1582 214 0
4 1582 214 1
kable(table(Orange$Tree))
Var1 Freq
3 7
1 7
5 7
2 7
4 7
kable(table(Orange$age))
Var1 Freq
118 5
484 5
664 5
1004 5
1231 5
1372 5
1582 5
kable(table(Orange$circumference))
Var1 Freq
30 3
32 1
33 1
49 1
51 1
58 1
62 1
69 1
75 1
81 1
87 1
108 1
111 1
112 1
115 2
120 1
125 1
139 1
140 1
142 2
145 1
156 1
167 1
172 1
174 1
177 1
179 1
203 2
209 1
214 1
#Parte 4
kable(table(Orange$Tree, Orange$age))
118 484 664 1004 1231 1372 1582
3 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
5 1 1 1 1 1 1 1
2 1 1 1 1 1 1 1
4 1 1 1 1 1 1 1

Al igual que en el caso anterior, estas tablas de frecuencias tienen sentido si estamos trabajando con variables categóricas o numéricas discretas con pocos valores, para variables continuas podría resultar interesante si previamente hemos agrupado los datos

EJERCICIO 2

Copiad y ejecutad el código siguiente de los dos vectores:

vect1 <- c(1,2,1,2,1,2,1,2,1,2,1,1,1,1,2,2,1,1,2,1) 
vect2 <- c(1,1,2,2,2,1,2,1,1,2,1,2,1,1,1,2,1,1,1,1) 

Responded a los apartados siguientes: 

  1. Usando el vect1 creamos un nuevo vector llamado Bajo_peso que sea un factor con dos niveles. Las etiquetas corresponden a 1 = Bajo peso y 2 = Peso normal. 

  2. Usando el vect2 creamos un nuevo vector llamado Fumador que sea un factor con dos niveles. Las etiquetas corresponden a 1 = Fuma y 2 = No fuma.

  3. Creamos una tabla de contingencia con las dos variables anteriores con el nombre Tabla.

  4. Miramos la relación de las variables anteriores con la prueba del ji cuadrado.

  5. Miramos también cómo resulta el test de Fisher.

#A)
Bajo_peso <- factor(vect1, levels=c(1,2), labels=c("Bajo peso", "Peso normal"))
print(Bajo_peso)
##  [1] Bajo peso   Peso normal Bajo peso   Peso normal Bajo peso   Peso normal
##  [7] Bajo peso   Peso normal Bajo peso   Peso normal Bajo peso   Bajo peso  
## [13] Bajo peso   Bajo peso   Peso normal Peso normal Bajo peso   Bajo peso  
## [19] Peso normal Bajo peso  
## Levels: Bajo peso Peso normal
#B)
Fumador <- factor(vect2, levels=c(1,2), labels=c("Fuma", "No fuma"))
print(Fumador)
##  [1] Fuma    Fuma    No fuma No fuma No fuma Fuma    No fuma Fuma    Fuma   
## [10] No fuma Fuma    No fuma Fuma    Fuma    Fuma    No fuma Fuma    Fuma   
## [19] Fuma    Fuma   
## Levels: Fuma No fuma
#C)
resultado <-chisq.test(Bajo_peso, Fumador)
## Warning in chisq.test(Bajo_peso, Fumador): Chi-squared approximation may be
## incorrect
print(resultado)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  Bajo_peso and Fumador
## X-squared = 0, df = 1, p-value = 1
#D)
resulado_fisher <-fisher.test(Bajo_peso, Fumador)
print(resulado_fisher)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  Bajo_peso and Fumador
## p-value = 1
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##   0.1200513 10.9278345
## sample estimates:
## odds ratio 
##   1.189031

EJERCICIO 3

  1. Activad el paquete de datos airquality del paquete datasets y generad los siguientes gráficos:
    • Un gráfico de dispersión de la variable Ozone de color azul y con almohadillas (#) en vez de puntos. • Un gráfico de caja de color rojo con la variable Temp con el título Temperatura (en grados Farenheit).

  2. Activad el paquete de datos airmiles del paquete datasets y generad los siguientes gráficos:
    • Un gráfico de líneas de la serie de datos airmiles con el título Datos de pasajeros en vuelos comerciales (en miles) y de color azul (cadetblue2) y la etiqueta del eje x con Miles de pasajeros.
    • Un histograma de la serie de datos airmiles de color marrón (chocolate2).

  3. Representad los cuatro gráficos en una única imagen donde los veamos juntos.

#Para representar todos los gráficos en una sola imagen creamos una matriz de 2x2 antes de los gráficos 
par(mfrow=c(2,2))
#A.1) Gráfico de dispersión, con pch conseguimos cambiar de circulos a almohadillas
data("airquality")
plot(airquality$Ozone, col="blue", pch=35)

#A.2) Gráfico de caja, con main= ponemos el titulo
boxplot(airquality$Temp, col = "red", main="Temperatura (en grados Farenheit)")

#B.1) Gráfico de lineas. con xlab= ponemos la etiqueta al eje x
data("airmiles")
plot(airmiles, col="cadetblue", xlab="Miles de pasarejos", main="Datos  de  pasajeros   en  vuelos  comerciales (en miles)")

#B.2) Gráfico de histograma
hist(airmiles, col = "chocolate2")

EJERCICIO 4

Intentad reproducir el ejemplo 7 de este LAB con unos datos simulados por vosotros. No hace falta que sean parecidos, pero es necesario que podáis hacer diferentes gráficos estadísticos con el comando plot().

set.seed(123)
x1 <- rnorm(1500) #simulamos una variable x1
y1 <- x1 + rnorm(1500) #simulamos una variable y1
plot(x1, y1, main="Gráfico de dispersión", col= c("lightblue", "red"), pch = c(1, 19))

boxplot(x1, y1, main="Boxplot", col= c("lightblue", "red"), xlab = "Grupos")

plot(density(x1), col="lightblue")

EJERCICIO 5

Para poder practicar la creación de gráficos con ggplot2, vamos a crear seis gráficos con diferentes características y con diferentes conjuntos de datos de paquetes trabajados anteriormente.

  1. Con los datos airquality del paquete datasets cread un gráfico de dispersión simple, pero con la recta de regresión ajustada en color rojo (darkred).
library(ggplot2)
ggplot(data = airquality, aes(x = Wind, y = Ozone)) +
  geom_point() +
  geom_smooth(method = "lm", color = "red")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 37 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 37 rows containing missing values or values outside the scale range
## (`geom_point()`).

  1. Con los datos airquality del paquete datasets cread un gráfico de dispersión con las variables Solar.R y Temp con sus respectivas etiquetas de eje. Los colores y la forma de los puntos deben ser en función de la variable Month convertida a factor.
#Con col=factor().... y shape=factor() lo que hacemos es convertir la variable entre () a factor, y codificar el color y la forma en base a dicha variable
ggplot(data = airquality, aes(x= Solar.R, y= Temp, col=factor(Month), shape=factor(Month)))+
  geom_point(size=2)
## Warning: Removed 7 rows containing missing values or values outside the scale range
## (`geom_point()`).

  1. Con los datos de Birthwt del paquete MASS mostrad la distribución de la variable age que tenga el borde de color negro y azul en el interior de las barras.
library(MASS)
## Warning: package 'MASS' was built under R version 4.4.3
## 
## Adjuntando el paquete: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
ggplot(data = birthwt, aes(age))+
  geom_histogram(fill="lightblue", col="black")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

  1. Con los datos de Birthwt del paquete MASS mostrad la distribución de la variable age, pero separada en dos gráficos (fumador/no fumador) por la variable smoke.
library(MASS)
ggplot(data = birthwt, aes(age))+
  geom_histogram(fill="lightblue", col="black")+
  facet_grid(~smoke)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

EJERCICIO 6

Cread un gráfico con unos datos extraídos del paquete Datasets de R y guardadlo como imagen (.jpg) con el nombre migrafic1 y, también, como documento en PDF con el nombre migrafic2. Haced una captura de pantalla del fichero generado.

jpeg("migrafic1.jpeg")
ggplot(data = iris, aes(x=Petal.Length, y=Petal.Width, col = Species))+
  geom_point(size=1.5)

dev.off
## function (which = dev.cur()) 
## {
##     if (which == 1) 
##         stop("cannot shut down device 1 (the null device)")
##     .External(C_devoff, as.integer(which))
##     dev.cur()
## }
## <bytecode: 0x000001933ef30ae8>
## <environment: namespace:grDevices>
pdf("migrafic2.pdf")
ggplot(data = iris, aes(x=Sepal.Length, y=Sepal.Width, colour = Species))+
  geom_point(size=1.5)

EJERCICIO 7

Para practicar la regresión lineal simple usaremos el conjunto de datos Orange que se encuentra en la librería tidyverse y que tiene información sobre tres variables (árbol, edad en días desde que se sembró el árbol y circunferencia del tronco en centímetros) de 35 naranjos.

• Queremos saber qué valor de circunferencia tendrá un árbol seiscientos días después de plantarlo. Cread para ello un modelo lineal y practicad la regresión lineal paso a paso con los pasos que habéis visto en este laboratorio.

library(tidyverse)
#Seguimos los diferentes pasos indicados para la regresión
data("Orange")
view(Orange)
#Cargamos los datos y hacemos una inspección visual y estadística de los datos
summary(Orange)
##  Tree       age         circumference  
##  3:7   Min.   : 118.0   Min.   : 30.0  
##  1:7   1st Qu.: 484.0   1st Qu.: 65.5  
##  5:7   Median :1004.0   Median :115.0  
##  2:7   Mean   : 922.1   Mean   :115.9  
##  4:7   3rd Qu.:1372.0   3rd Qu.:161.5  
##        Max.   :1582.0   Max.   :214.0
grafico_visual<-pairs(Orange)

print(grafico_visual)
## NULL
#Hacemos un estudio de correlación
correlacion <-cor.test(Orange$circumference, Orange$age)
print(correlacion)
## 
##  Pearson's product-moment correlation
## 
## data:  Orange$circumference and Orange$age
## t = 12.9, df = 33, p-value = 1.931e-14
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.8342364 0.9557955
## sample estimates:
##       cor 
## 0.9135189
#Planteamos el modelo
regresion <- lm(circumference ~ age, data = Orange)
resumen_modelo <-summary(regresion)
print(resumen_modelo)
## 
## Call:
## lm(formula = circumference ~ age, data = Orange)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -46.310 -14.946  -0.076  19.697  45.111 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 17.399650   8.622660   2.018   0.0518 .  
## age          0.106770   0.008277  12.900 1.93e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 23.74 on 33 degrees of freedom
## Multiple R-squared:  0.8345, Adjusted R-squared:  0.8295 
## F-statistic: 166.4 on 1 and 33 DF,  p-value: 1.931e-14
#Graficamos el modelo
plot(Orange$age, Orange$circumference)
abline(regresion)

#Evaluamos residuos
residuos <-rstandard(regresion)
valores_ajustados <- fitted(regresion)
plot(valores_ajustados, residuos)

qqnorm(residuos)
qqline(residuos)

#Hacemos la predicción para un arbol con 600 dias
nuevos_datos <- data.frame(age = 600)
pred_circunferencia <- predict(regresion, nuevos_datos)
print(pred_circunferencia)
##        1 
## 81.46185

EJERCICIO 8

Repetid los gráficos (aquellos que podáis) de la regresión lineal simple del ejercicio anterior pero ahora con ggplot2

#Primero evaluamos la graficamente la correlación entre ambas variables
ggplot(data = Orange) + geom_point(aes(x = age, y = circumference))

#Añadimos la recta de correlación
ggplot(data = Orange) + geom_point(aes(x = age, y = circumference)) + geom_smooth(aes(x = age, y = circumference), method = "lm", se = TRUE)
## `geom_smooth()` using formula = 'y ~ x'

EJERCICIO 9

Activad el conjunto de datos PlantGrowth del paquete datasets de R. Este archivo tiene los recultados de un experimento para comparar los rendimientos medios por el peso seco de las plantas (weight) obtenidos bajo un control y dos condiciones de tratamiento diferentes (group factor). • ¿Creéis que hay diferencias entre tratamientos?

#Cargamos los datos y hacemos un resumen x grupo
view(PlantGrowth)
describeBy(PlantGrowth$weight, PlantGrowth$group)
## 
##  Descriptive statistics by group 
## group: ctrl
##    vars  n mean   sd median trimmed  mad  min  max range skew kurtosis   se
## X1    1 10 5.03 0.58   5.15       5 0.72 4.17 6.11  1.94 0.23    -1.12 0.18
## ------------------------------------------------------------ 
## group: trt1
##    vars  n mean   sd median trimmed  mad  min  max range skew kurtosis   se
## X1    1 10 4.66 0.79   4.55    4.62 0.53 3.59 6.03  2.44 0.47     -1.1 0.25
## ------------------------------------------------------------ 
## group: trt2
##    vars  n mean   sd median trimmed  mad  min  max range skew kurtosis   se
## X1    1 10 5.53 0.44   5.44     5.5 0.36 4.92 6.31  1.39 0.48    -1.16 0.14
pairs(PlantGrowth)

#Para ver si hay diferencias entre los tratamientos, primero lo graficamos como boxplot
boxplot(PlantGrowth$weight ~ PlantGrowth$group)

Simplemente por inspección visual no parece haber diferencias entre el control y el tratamiento 1 y tratamiento 2 Aunque puede que haya diferencias entre tratamiento 1 y tratamiento 2

• Se cumplen las condiciones para poder aplicar una ANOVA. ¿Qué pruebas os planteáis?

#comprobamos la presencia de outliers (aunque se pueden ver en el boxplot)
tapply(PlantGrowth$weight, PlantGrowth$group, function(x) {
  boxplot.stats(x)$out
})
## $ctrl
## numeric(0)
## 
## $trt1
## [1] 6.03
## 
## $trt2
## numeric(0)
#Comprobamos la normalidad y la homocedasticidad de las varianzas
by(PlantGrowth$weight, PlantGrowth$group, shapiro.test)
## PlantGrowth$group: ctrl
## 
##  Shapiro-Wilk normality test
## 
## data:  dd[x, ]
## W = 0.95668, p-value = 0.7475
## 
## ------------------------------------------------------------ 
## PlantGrowth$group: trt1
## 
##  Shapiro-Wilk normality test
## 
## data:  dd[x, ]
## W = 0.93041, p-value = 0.4519
## 
## ------------------------------------------------------------ 
## PlantGrowth$group: trt2
## 
##  Shapiro-Wilk normality test
## 
## data:  dd[x, ]
## W = 0.94101, p-value = 0.5643
bartlett.test(PlantGrowth$weight, PlantGrowth$group)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  PlantGrowth$weight and PlantGrowth$group
## Bartlett's K-squared = 2.8786, df = 2, p-value = 0.2371
#Se cumple la normalidad de las muestras y la homocedasticidad de las varianzas

#Realizamos ANOVA
model_anova <- aov(weight ~ group, data = PlantGrowth)
summary(model_anova)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## group        2  3.766  1.8832   4.846 0.0159 *
## Residuals   27 10.492  0.3886                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(model_anova)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = weight ~ group, data = PlantGrowth)
## 
## $group
##             diff        lwr       upr     p adj
## trt1-ctrl -0.371 -1.0622161 0.3202161 0.3908711
## trt2-ctrl  0.494 -0.1972161 1.1852161 0.1979960
## trt2-trt1  0.865  0.1737839 1.5562161 0.0120064

Estos resultados muestran que hay diferencias entre el tratamiento 2 y el 1, pero no así en el resto de comparaciones entre grupos

EJERCICIO 10

Buscad información del paquete Plotly para la creación de gráficos interactivos y generad un histograma o un gráfico de barras interactivo. Explicad qué se puede hacer con este gráfico.

library(plotly)
## Warning: package 'plotly' was built under R version 4.4.2
## 
## Adjuntando el paquete: 'plotly'
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
# Histograma con colores por especie
plot_ly(data = iris,
        x = ~Sepal.Length,
        color = ~Species,
        type = "histogram",
        opacity = 0.5,
        colors = c("#E41A1C", "#377EB8", "#4DAF4A"),
        barmode = "overlay") %>%
  layout(title = "Distribución del Largo del Sépalo por Especie",
         xaxis = list(title = "Largo del Sépalo (cm)"),
         yaxis = list(title = "Frecuencia"))  
## Warning: 'histogram' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'autobinx', 'autobiny', 'bingroup', 'cliponaxis', 'constraintext', 'cumulative', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'histfunc', 'histnorm', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'nbinsx', 'nbinsy', 'offsetgroup', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textsrc', 'texttemplate', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'x', 'xaxis', 'xbins', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'yaxis', 'ybins', 'ycalendar', 'yhoverformat', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'histogram' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'autobinx', 'autobiny', 'bingroup', 'cliponaxis', 'constraintext', 'cumulative', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'histfunc', 'histnorm', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'nbinsx', 'nbinsy', 'offsetgroup', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textsrc', 'texttemplate', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'x', 'xaxis', 'xbins', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'yaxis', 'ybins', 'ycalendar', 'yhoverformat', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'histogram' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'autobinx', 'autobiny', 'bingroup', 'cliponaxis', 'constraintext', 'cumulative', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'histfunc', 'histnorm', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'nbinsx', 'nbinsy', 'offsetgroup', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textsrc', 'texttemplate', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'x', 'xaxis', 'xbins', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'yaxis', 'ybins', 'ycalendar', 'yhoverformat', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'

Plotly es una librería de R que permite crear gráficos interactivos y dinámicos para visualización de datos. Al ser interactivo permite hacer zoom, desplazarse por el gráfico, poder ver datos al posicionar el cursor encima de partes del gráfico y también descargarlos en jpeg.

CASO PRÁCTICO

A partir de unos datos bioclínicos o biosanitarios que escojáis y que importéis a R, explicad sus variables (mínimo de ocho variables) y también:

Para este ejercicio he empleado el siguiente conjunto de datos Características y carga del covid agudo y v

#Empleamos el conjunto de datos: Characteristics and burden of acute COVID-19 and long-COVID 

library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
covid <- read_excel("Data.xlsx")
View(covid)

• Realizad un resumen estadístico completo del dataset y explicad los resultados. Se trata de una base de datos sobre las características y la carga del covid agudo y covid persistente. La base de datos incluye datos de 416 participantes y mediciones de 254 variables (la mayoría de caracter numérico). Sin embargo, la gran mayoría de las variables presentan valores nulos o NA.

#Dado el tamaño de la base de datos, podemos comenzar con ver la estructura y dimensiones:
str(covid)          
## tibble [416 × 254] (S3: tbl_df/tbl/data.frame)
##  $ id                                                       : num [1:416] 1 2 3 4 5 6 7 8 9 10 ...
##  $ age                                                      : num [1:416] NA 29.5 NA NA 23.7 ...
##  $ duration_since_disease_by_10052022                       : num [1:416] NA 18.34 1.88 NA 1.95 ...
##  $ origin                                                   : num [1:416] NA 1 1 NA 4 NA 1 NA 1 NA ...
##  $ origin_other                                             : chr [1:416] NA NA NA NA ...
##  $ gender                                                   : num [1:416] NA 1 1 NA 1 NA 1 NA 1 NA ...
##  $ height                                                   : num [1:416] NA 172 186 NA 176 NA 160 NA 163 NA ...
##  $ weight                                                   : num [1:416] NA 87 78 NA 62 NA 70 NA 59 NA ...
##  $ BMI                                                      : num [1:416] NA 29.4 22.5 NA 20 ...
##  $ comorbidities                                            : num [1:416] NA 1 1 NA 1 NA NA NA 1 NA ...
##  $ com_dementia                                             : logi [1:416] NA NA NA NA NA NA ...
##  $ com_parkinson                                            : logi [1:416] NA NA NA NA NA NA ...
##  $ com_epilepsy                                             : logi [1:416] NA NA NA NA NA NA ...
##  $ com_MS                                                   : logi [1:416] NA NA NA NA NA NA ...
##  $ com_stroke                                               : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ com_hypertonia                                           : num [1:416] NA NA NA NA NA NA 1 NA NA NA ...
##  $ com_hypertonia_new                                       : num [1:416] NA 0 0 NA 0 NA 1 NA 0 NA ...
##  $ com_diabetes                                             : num [1:416] NA NA NA NA NA NA 1 NA NA NA ...
##  $ com_copd                                                 : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ com_cardiac_insufficiency                                : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ com_cancer                                               : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ com_cancer_type                                          : chr [1:416] NA NA NA NA ...
##  $ com_other                                                : chr [1:416] NA NA NA NA ...
##  $ education                                                : num [1:416] NA 8 9 NA NA NA 3 NA 8 NA ...
##  $ education_other                                          : chr [1:416] NA NA NA NA ...
##  $ education_years                                          : num [1:416] NA 19 20 NA NA NA NA NA 18 NA ...
##  $ current_job_Arbeiter                                     : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ current_job_Angestellter                                 : num [1:416] NA 1 1 NA NA NA NA NA 1 NA ...
##  $ current_job_Student                                      : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ current_job_Schüler                                      : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ current_job_Pensionist                                   : num [1:416] NA NA NA NA NA NA 1 NA NA NA ...
##  $ current_job_Arbeitsloser                                 : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ current_job_Selbstständiger                              : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ current_job_other                                        : chr [1:416] NA NA NA NA ...
##  $ changes_work_covid                                       : num [1:416] NA 2 2 NA 2 NA NA NA 2 NA ...
##  $ changes_work_covid_hours_reduced                         : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ changes_work_covid_no_work_anymore                       : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ changes_work_covid_job_change                            : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ changes_work_covid_sick_leave                            : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ changes_work_covid_other                                 : chr [1:416] NA NA NA NA ...
##  $ financial_losses                                         : num [1:416] NA 2 2 NA 2 NA NA NA 2 NA ...
##  $ covid_infection_acute_duration                           : num [1:416] NA 5 2 NA 3 NA 2 NA 4 NA ...
##  $ covid_infection_acute_duration_other                     : chr [1:416] NA NA NA NA ...
##  $ course_disease_severe                                    : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ course_disease_mild                                      : num [1:416] NA 1 1 NA 1 NA 1 NA NA NA ...
##  $ course_disease_asymptomatic                              : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ hospitalization                                          : num [1:416] NA 2 2 NA 2 NA NA NA 2 NA ...
##  $ hospitalization_cov19_or_ICU                             : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ covid_hospitalization_duration                           : num [1:416] NA NA NA NA NA NA NA NA NA NA ...
##  $ symptoms_fatigue_burden                                  : num [1:416] NA 5 5 NA NA NA NA NA 4 NA ...
##  $ symptoms_poor_memory_burden                              : num [1:416] NA NA 3 NA 2 NA 3 NA 4 NA ...
##  $ symptoms_limitation_mental_performance_burden            : num [1:416] NA NA 2 NA 2 NA 3 NA 5 NA ...
##  $ symptoms_fever_burden                                    : num [1:416] NA NA NA NA 4 NA NA NA 1 NA ...
##  $ symptoms_loss_of_appetite_burden                         : num [1:416] NA 4 NA NA 4 NA NA NA 5 NA ...
##  $ symptoms_rattling_breathing_burden                       : num [1:416] NA 3 NA NA 2 NA NA NA 5 NA ...
##  $ symptoms_runny_nose_burden                               : num [1:416] NA 3 4 NA 3 NA NA NA 1 NA ...
##  $ symptoms_increased_temperature_burden                    : num [1:416] NA NA NA NA 4 NA NA NA 1 NA ...
##  $ symptoms_dry_cough_burden                                : num [1:416] NA 5 1 NA 4 NA NA NA 5 NA ...
##  $ symptoms_vomiting_burden                                 : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_sore_throat_burden                              : num [1:416] NA NA NA NA 1 NA NA NA 1 NA ...
##  $ symptoms_diarrhoea_burden                                : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_bloody_cough_burden                             : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_chills_or_sweating_burden                       : num [1:416] NA 3 NA NA 2 NA NA NA 3 NA ...
##  $ symptoms_altered_taste_smell_burden                      : num [1:416] NA 5 NA NA 4 NA 3 NA 5 NA ...
##  $ symptoms_sneeze_burden                                   : num [1:416] NA 2 NA NA 3 NA NA NA 1 NA ...
##  $ symptoms_difficulty_breathing_normal_oxy_sat_burden      : num [1:416] NA 4 NA NA 2 NA NA NA 5 NA ...
##  $ symptoms_tightness_chest_burden                          : num [1:416] NA 3 NA NA NA NA NA NA 5 NA ...
##  $ symptoms_shortness_of_breath_burden                      : num [1:416] NA 3 NA NA NA NA NA NA 5 NA ...
##  $ symptoms_cough_mucus_burden                              : num [1:416] NA 3 NA NA 5 NA NA NA 4 NA ...
##  $ symptoms_nausea_burden                                   : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_burning_chest_pain_burden                       : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_disorientation_confusion_burden                 : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_muscle_pain_burden                              : num [1:416] NA 2 NA NA NA NA NA NA 3 NA ...
##  $ symptoms_dizziness_burden                                : num [1:416] NA 3 NA NA NA NA NA NA 5 NA ...
##  $ symptoms_low_temp_burden                                 : num [1:416] NA NA NA NA NA NA NA NA 4 NA ...
##  $ symptoms_exhaustion_burden                               : num [1:416] NA 5 NA NA 3 NA 3 NA 5 NA ...
##  $ symptoms_stomach_pain_burden                             : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_other_sleep_symptoms_burden                     : num [1:416] NA NA NA NA NA NA NA NA 4 NA ...
##  $ symptoms_headache_burden                                 : num [1:416] NA 5 NA NA 3 NA NA NA 5 NA ...
##  $ symptoms_covidzeh_burden                                 : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_hallucinatoin_burden                            : num [1:416] NA NA NA NA 2 NA NA NA 1 NA ...
##  $ symptoms_bone_pain_burden                                : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_tachycardia_burden                              : num [1:416] NA 2 NA NA NA NA NA NA 4 NA ...
##  $ symptoms_sleepapnoea_burden                              : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_insomnia_burden                                 : num [1:416] NA NA NA NA NA NA NA NA 4 NA ...
##  $ symptoms_slurred_speech_burden                           : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_joint_pain_burden                               : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_heart_palpations_burden                         : num [1:416] NA 4 NA NA NA NA NA NA 5 NA ...
##  $ symptoms_other_temp_deviations_burden                    : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_other_eye_sympt_burden                          : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_muscle_cramps_burden                            : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_disturbed_neurological_sensations_burden        : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_peeling_skin_burden                             : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_heartburn_reflux_burden                         : num [1:416] NA NA NA NA NA NA NA NA 2 NA ...
##  $ symptoms_skin_rash_burden                                : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_constipation_burden                             : num [1:416] NA NA NA NA NA NA NA NA 2 NA ...
##  $ symptoms_bladder_control_problems_burden                 : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##  $ symptoms_hearloss_burden                                 : num [1:416] NA NA NA NA NA NA NA NA 3 NA ...
##  $ symptoms_bradycardia_burden                              : num [1:416] NA NA NA NA NA NA NA NA 1 NA ...
##   [list output truncated]
dim(covid) 
## [1] 416 254
summary(covid)
##        id             age        duration_since_disease_by_10052022
##  Min.   :  1.0   Min.   :16.34   Min.   : 0.2736                   
##  1st Qu.:104.8   1st Qu.:34.34   1st Qu.: 2.8034                   
##  Median :208.5   Median :44.34   Median :12.1011                   
##  Mean   :208.5   Mean   :44.18   Mean   :10.5355                   
##  3rd Qu.:312.2   3rd Qu.:54.34   3rd Qu.:17.3250                   
##  Max.   :416.0   Max.   :79.70   Max.   :26.4913                   
##                  NA's   :99      NA's   :141                       
##      origin      origin_other           gender          height     
##  Min.   :1.000   Length:416         Min.   :1.000   Min.   :123.0  
##  1st Qu.:1.000   Class :character   1st Qu.:1.000   1st Qu.:165.0  
##  Median :1.000   Mode  :character   Median :1.000   Median :170.0  
##  Mean   :1.267                      Mean   :1.261   Mean   :171.1  
##  3rd Qu.:1.000                      3rd Qu.:2.000   3rd Qu.:177.0  
##  Max.   :5.000                      Max.   :2.000   Max.   :200.0  
##  NA's   :79                         NA's   :83      NA's   :88     
##      weight            BMI        comorbidities com_dementia   com_parkinson 
##  Min.   : 43.00   Min.   :15.42   Min.   :1     Mode:logical   Mode:logical  
##  1st Qu.: 62.00   1st Qu.:21.80   1st Qu.:1     NA's:416       NA's:416      
##  Median : 73.00   Median :24.65   Median :1                                  
##  Mean   : 76.33   Mean   :25.96   Mean   :1                                  
##  3rd Qu.: 85.00   3rd Qu.:28.37   3rd Qu.:1                                  
##  Max.   :178.00   Max.   :62.50   Max.   :1                                  
##  NA's   :83       NA's   :89      NA's   :199                                
##  com_epilepsy    com_MS          com_stroke  com_hypertonia com_hypertonia_new
##  Mode:logical   Mode:logical   Min.   :1     Min.   :1      Min.   :0.00000   
##  NA's:416       NA's:416       1st Qu.:1     1st Qu.:1      1st Qu.:0.00000   
##                                Median :1     Median :1      Median :0.00000   
##                                Mean   :1     Mean   :1      Mean   :0.08824   
##                                3rd Qu.:1     3rd Qu.:1      3rd Qu.:0.00000   
##                                Max.   :1     Max.   :1      Max.   :1.00000   
##                                NA's   :414   NA's   :386    NA's   :76        
##   com_diabetes    com_copd   com_cardiac_insufficiency   com_cancer 
##  Min.   :1     Min.   :1     Min.   :1                 Min.   :1    
##  1st Qu.:1     1st Qu.:1     1st Qu.:1                 1st Qu.:1    
##  Median :1     Median :1     Median :1                 Median :1    
##  Mean   :1     Mean   :1     Mean   :1                 Mean   :1    
##  3rd Qu.:1     3rd Qu.:1     3rd Qu.:1                 3rd Qu.:1    
##  Max.   :1     Max.   :1     Max.   :1                 Max.   :1    
##  NA's   :406   NA's   :412   NA's   :411               NA's   :410  
##  com_cancer_type     com_other           education     education_other   
##  Length:416         Length:416         Min.   : 2.00   Length:416        
##  Class :character   Class :character   1st Qu.: 6.00   Class :character  
##  Mode  :character   Mode  :character   Median : 7.00   Mode  :character  
##                                        Mean   : 6.91                     
##                                        3rd Qu.: 8.00                     
##                                        Max.   :11.00                     
##                                        NA's   :81                        
##  education_years current_job_Arbeiter current_job_Angestellter
##  Min.   : 6.50   Min.   :1            Min.   :1               
##  1st Qu.:12.00   1st Qu.:1            1st Qu.:1               
##  Median :15.00   Median :1            Median :1               
##  Mean   :14.55   Mean   :1            Mean   :1               
##  3rd Qu.:18.00   3rd Qu.:1            3rd Qu.:1               
##  Max.   :25.00   Max.   :1            Max.   :1               
##  NA's   :252     NA's   :400          NA's   :177             
##  current_job_Student current_job_Schüler current_job_Pensionist
##  Min.   :1           Min.   :1           Min.   :1             
##  1st Qu.:1           1st Qu.:1           1st Qu.:1             
##  Median :1           Median :1           Median :1             
##  Mean   :1           Mean   :1           Mean   :1             
##  3rd Qu.:1           3rd Qu.:1           3rd Qu.:1             
##  Max.   :1           Max.   :1           Max.   :1             
##  NA's   :394         NA's   :411         NA's   :393           
##  current_job_Arbeitsloser current_job_Selbstständiger current_job_other 
##  Min.   :1                Min.   :1                   Length:416        
##  1st Qu.:1                1st Qu.:1                   Class :character  
##  Median :1                Median :1                   Mode  :character  
##  Mean   :1                Mean   :1                                     
##  3rd Qu.:1                3rd Qu.:1                                     
##  Max.   :1                Max.   :1                                     
##  NA's   :409              NA's   :387                                   
##  changes_work_covid changes_work_covid_hours_reduced
##  Min.   :1.00       Min.   :1                       
##  1st Qu.:1.00       1st Qu.:1                       
##  Median :2.00       Median :1                       
##  Mean   :1.59       Mean   :1                       
##  3rd Qu.:2.00       3rd Qu.:1                       
##  Max.   :2.00       Max.   :1                       
##  NA's   :92         NA's   :385                     
##  changes_work_covid_no_work_anymore changes_work_covid_job_change
##  Min.   :1                          Min.   :1                    
##  1st Qu.:1                          1st Qu.:1                    
##  Median :1                          Median :1                    
##  Mean   :1                          Mean   :1                    
##  3rd Qu.:1                          3rd Qu.:1                    
##  Max.   :1                          Max.   :1                    
##  NA's   :404                        NA's   :406                  
##  changes_work_covid_sick_leave changes_work_covid_other financial_losses
##  Min.   :1                     Length:416               Min.   :1.000   
##  1st Qu.:1                     Class :character         1st Qu.:1.000   
##  Median :1                     Mode  :character         Median :2.000   
##  Mean   :1                                              Mean   :1.595   
##  3rd Qu.:1                                              3rd Qu.:2.000   
##  Max.   :1                                              Max.   :2.000   
##  NA's   :339                                            NA's   :100     
##  covid_infection_acute_duration covid_infection_acute_duration_other
##  Min.   :1.000                  Length:416                          
##  1st Qu.:2.000                  Class :character                    
##  Median :3.000                  Mode  :character                    
##  Mean   :3.415                                                      
##  3rd Qu.:4.000                                                      
##  Max.   :9.000                                                      
##  NA's   :117                                                        
##  course_disease_severe course_disease_mild course_disease_asymptomatic
##  Min.   :1             Min.   :1           Min.   :1                  
##  1st Qu.:1             1st Qu.:1           1st Qu.:1                  
##  Median :1             Median :1           Median :1                  
##  Mean   :1             Mean   :1           Mean   :1                  
##  3rd Qu.:1             3rd Qu.:1           3rd Qu.:1                  
##  Max.   :1             Max.   :1           Max.   :1                  
##  NA's   :357           NA's   :194         NA's   :398                
##  hospitalization hospitalization_cov19_or_ICU covid_hospitalization_duration
##  Min.   :1.000   Min.   :1.000                Min.   :1                     
##  1st Qu.:2.000   1st Qu.:1.000                1st Qu.:1                     
##  Median :2.000   Median :1.000                Median :1                     
##  Mean   :1.922   Mean   :1.222                Mean   :2                     
##  3rd Qu.:2.000   3rd Qu.:1.000                3rd Qu.:3                     
##  Max.   :2.000   Max.   :2.000                Max.   :7                     
##  NA's   :120     NA's   :398                  NA's   :398                   
##  symptoms_fatigue_burden symptoms_poor_memory_burden
##  Min.   :1.000           Min.   :1.000              
##  1st Qu.:3.000           1st Qu.:2.000              
##  Median :4.000           Median :3.000              
##  Mean   :3.961           Mean   :2.793              
##  3rd Qu.:5.000           3rd Qu.:4.000              
##  Max.   :5.000           Max.   :5.000              
##  NA's   :134             NA's   :189                
##  symptoms_limitation_mental_performance_burden symptoms_fever_burden
##  Min.   :1.000                                 Min.   :1.000        
##  1st Qu.:2.000                                 1st Qu.:1.000        
##  Median :3.000                                 Median :2.500        
##  Mean   :3.018                                 Mean   :2.583        
##  3rd Qu.:4.000                                 3rd Qu.:4.000        
##  Max.   :5.000                                 Max.   :5.000        
##  NA's   :188                                   NA's   :198          
##  symptoms_loss_of_appetite_burden symptoms_rattling_breathing_burden
##  Min.   :1.000                    Min.   :1.000                     
##  1st Qu.:2.000                    1st Qu.:1.000                     
##  Median :3.000                    Median :2.000                     
##  Mean   :3.041                    Mean   :2.377                     
##  3rd Qu.:4.000                    3rd Qu.:3.000                     
##  Max.   :5.000                    Max.   :5.000                     
##  NA's   :197                      NA's   :257                       
##  symptoms_runny_nose_burden symptoms_increased_temperature_burden
##  Min.   :1.000              Min.   :1.000                        
##  1st Qu.:1.000              1st Qu.:1.000                        
##  Median :3.000              Median :3.000                        
##  Mean   :2.722              Mean   :2.727                        
##  3rd Qu.:4.000              3rd Qu.:4.000                        
##  Max.   :5.000              Max.   :5.000                        
##  NA's   :193                NA's   :218                          
##  symptoms_dry_cough_burden symptoms_vomiting_burden symptoms_sore_throat_burden
##  Min.   :1.000             Min.   :1.000            Min.   :1.000              
##  1st Qu.:3.000             1st Qu.:1.000            1st Qu.:2.000              
##  Median :4.000             Median :1.000            Median :3.000              
##  Mean   :3.409             Mean   :1.619            Mean   :2.874              
##  3rd Qu.:4.000             3rd Qu.:2.000            3rd Qu.:4.000              
##  Max.   :5.000             Max.   :5.000            Max.   :5.000              
##  NA's   :186               NA's   :311              NA's   :210                
##  symptoms_diarrhoea_burden symptoms_bloody_cough_burden
##  Min.   :1.000             Min.   :1.000               
##  1st Qu.:1.000             1st Qu.:1.000               
##  Median :2.000             Median :1.000               
##  Mean   :2.286             Mean   :1.344               
##  3rd Qu.:3.000             3rd Qu.:1.000               
##  Max.   :5.000             Max.   :4.000               
##  NA's   :276               NA's   :355                 
##  symptoms_chills_or_sweating_burden symptoms_altered_taste_smell_burden
##  Min.   :1.000                      Min.   :1.00                       
##  1st Qu.:3.000                      1st Qu.:3.00                       
##  Median :3.000                      Median :5.00                       
##  Mean   :3.378                      Mean   :3.97                       
##  3rd Qu.:4.000                      3rd Qu.:5.00                       
##  Max.   :5.000                      Max.   :5.00                       
##  NA's   :199                        NA's   :219                        
##  symptoms_sneeze_burden symptoms_difficulty_breathing_normal_oxy_sat_burden
##  Min.   :1.000          Min.   :1.000                                      
##  1st Qu.:2.000          1st Qu.:2.000                                      
##  Median :3.000          Median :3.000                                      
##  Mean   :2.694          Mean   :3.184                                      
##  3rd Qu.:4.000          3rd Qu.:4.000                                      
##  Max.   :5.000          Max.   :5.000                                      
##  NA's   :243            NA's   :215                                        
##  symptoms_tightness_chest_burden symptoms_shortness_of_breath_burden
##  Min.   :1.000                   Min.   :1.000                      
##  1st Qu.:3.000                   1st Qu.:3.000                      
##  Median :3.000                   Median :4.000                      
##  Mean   :3.335                   Mean   :3.591                      
##  3rd Qu.:4.000                   3rd Qu.:5.000                      
##  Max.   :5.000                   Max.   :5.000                      
##  NA's   :210                     NA's   :201                        
##  symptoms_cough_mucus_burden symptoms_nausea_burden
##  Min.   :1.000               Min.   :1.000         
##  1st Qu.:1.500               1st Qu.:1.000         
##  Median :3.000               Median :2.000         
##  Mean   :2.789               Mean   :2.481         
##  3rd Qu.:4.000               3rd Qu.:3.000         
##  Max.   :5.000               Max.   :5.000         
##  NA's   :269                 NA's   :287           
##  symptoms_burning_chest_pain_burden symptoms_disorientation_confusion_burden
##  Min.   :1.000                      Min.   :1.000                           
##  1st Qu.:2.000                      1st Qu.:1.000                           
##  Median :3.000                      Median :2.000                           
##  Mean   :2.774                      Mean   :2.303                           
##  3rd Qu.:4.000                      3rd Qu.:3.000                           
##  Max.   :5.000                      Max.   :5.000                           
##  NA's   :292                        NA's   :294                             
##  symptoms_muscle_pain_burden symptoms_dizziness_burden symptoms_low_temp_burden
##  Min.   :1.000               Min.   :1.000             Min.   :1.000           
##  1st Qu.:3.000               1st Qu.:2.000             1st Qu.:1.000           
##  Median :4.000               Median :3.000             Median :1.000           
##  Mean   :3.535               Mean   :3.292             Mean   :1.828           
##  3rd Qu.:5.000               3rd Qu.:4.000             3rd Qu.:2.500           
##  Max.   :5.000               Max.   :5.000             Max.   :5.000           
##  NA's   :199                 NA's   :224               NA's   :329             
##  symptoms_exhaustion_burden symptoms_stomach_pain_burden
##  Min.   :1.000              Min.   :1.000               
##  1st Qu.:4.000              1st Qu.:1.000               
##  Median :4.000              Median :1.000               
##  Mean   :4.125              Mean   :1.953               
##  3rd Qu.:5.000              3rd Qu.:3.000               
##  Max.   :5.000              Max.   :5.000               
##  NA's   :161                NA's   :310                 
##  symptoms_other_sleep_symptoms_burden symptoms_headache_burden
##  Min.   :1.000                        Min.   :1.000           
##  1st Qu.:2.000                        1st Qu.:3.000           
##  Median :3.000                        Median :4.000           
##  Mean   :3.205                        Mean   :3.763           
##  3rd Qu.:4.000                        3rd Qu.:5.000           
##  Max.   :5.000                        Max.   :5.000           
##  NA's   :265                          NA's   :197             
##  symptoms_covidzeh_burden symptoms_hallucinatoin_burden
##  Min.   :1.00             Min.   :1.000                
##  1st Qu.:1.00             1st Qu.:1.000                
##  Median :1.00             Median :1.000                
##  Mean   :1.75             Mean   :1.328                
##  3rd Qu.:2.25             3rd Qu.:1.000                
##  Max.   :5.00             Max.   :5.000                
##  NA's   :348              NA's   :355                  
##  symptoms_bone_pain_burden symptoms_tachycardia_burden
##  Min.   :1.000             Min.   :1.000              
##  1st Qu.:2.000             1st Qu.:1.000              
##  Median :3.000             Median :3.000              
##  Mean   :3.117             Mean   :2.617              
##  3rd Qu.:4.000             3rd Qu.:4.000              
##  Max.   :5.000             Max.   :5.000              
##  NA's   :288               NA's   :296                
##  symptoms_sleepapnoea_burden symptoms_insomnia_burden
##  Min.   :1.00                Min.   :1.000           
##  1st Qu.:1.00                1st Qu.:2.000           
##  Median :2.00                Median :3.000           
##  Mean   :2.16                Mean   :3.224           
##  3rd Qu.:3.00                3rd Qu.:4.000           
##  Max.   :5.00                Max.   :5.000           
##  NA's   :335                 NA's   :264             
##  symptoms_slurred_speech_burden symptoms_joint_pain_burden
##  Min.   :1.000                  Min.   :1.000             
##  1st Qu.:1.000                  1st Qu.:3.000             
##  Median :2.000                  Median :4.000             
##  Mean   :2.063                  Mean   :3.562             
##  3rd Qu.:3.000                  3rd Qu.:5.000             
##  Max.   :5.000                  Max.   :5.000             
##  NA's   :337                    NA's   :247               
##  symptoms_heart_palpations_burden symptoms_other_temp_deviations_burden
##  Min.   :1.000                    Min.   :1.000                        
##  1st Qu.:2.000                    1st Qu.:1.000                        
##  Median :3.000                    Median :1.000                        
##  Mean   :3.245                    Mean   :1.861                        
##  3rd Qu.:4.000                    3rd Qu.:3.000                        
##  Max.   :5.000                    Max.   :5.000                        
##  NA's   :269                      NA's   :351                          
##  symptoms_other_eye_sympt_burden symptoms_muscle_cramps_burden
##  Min.   :1.000                   Min.   :1.00                 
##  1st Qu.:1.000                   1st Qu.:1.00                 
##  Median :3.000                   Median :2.00                 
##  Mean   :2.536                   Mean   :2.33                 
##  3rd Qu.:3.000                   3rd Qu.:3.00                 
##  Max.   :5.000                   Max.   :5.00                 
##  NA's   :304                     NA's   :319                  
##  symptoms_disturbed_neurological_sensations_burden symptoms_peeling_skin_burden
##  Min.   :1.00                                      Min.   :1.000               
##  1st Qu.:2.00                                      1st Qu.:1.000               
##  Median :3.00                                      Median :1.000               
##  Mean   :2.74                                      Mean   :1.826               
##  3rd Qu.:3.25                                      3rd Qu.:3.000               
##  Max.   :5.00                                      Max.   :5.000               
##  NA's   :312                                       NA's   :347                 
##  symptoms_heartburn_reflux_burden symptoms_skin_rash_burden
##  Min.   :1.000                    Min.   :1.00             
##  1st Qu.:1.000                    1st Qu.:1.00             
##  Median :2.000                    Median :2.00             
##  Mean   :2.046                    Mean   :2.16             
##  3rd Qu.:3.000                    3rd Qu.:3.00             
##  Max.   :5.000                    Max.   :5.00             
##  NA's   :329                      NA's   :335              
##  symptoms_constipation_burden symptoms_bladder_control_problems_burden
##  Min.   :1.000                Min.   :1.000                           
##  1st Qu.:1.000                1st Qu.:1.000                           
##  Median :1.000                Median :1.000                           
##  Mean   :1.781                Mean   :1.753                           
##  3rd Qu.:2.000                3rd Qu.:2.000                           
##  Max.   :5.000                Max.   :5.000                           
##  NA's   :343                  NA's   :343                             
##  symptoms_hearloss_burden symptoms_bradycardia_burden
##  Min.   :1.000            Min.   :1.000              
##  1st Qu.:1.000            1st Qu.:1.000              
##  Median :1.000            Median :1.000              
##  Mean   :1.783            Mean   :1.538              
##  3rd Qu.:2.000            3rd Qu.:2.000              
##  Max.   :5.000            Max.   :5.000              
##  NA's   :347              NA's   :351                
##  symptoms_nerve_pain_burden symptoms_hearing_impairment_burden
##  Min.   :1.000              Min.   :1.000                     
##  1st Qu.:1.000              1st Qu.:1.000                     
##  Median :3.000              Median :2.000                     
##  Mean   :2.781              Mean   :1.932                     
##  3rd Qu.:4.000              3rd Qu.:3.000                     
##  Max.   :5.000              Max.   :5.000                     
##  NA's   :311                NA's   :342                       
##  symptoms_tremor_burden symptoms_dermographism_burden symtpoms_petechiae_burden
##  Min.   :1.000          Min.   :1.000                 Min.   :1.000            
##  1st Qu.:1.000          1st Qu.:1.000                 1st Qu.:1.000            
##  Median :2.000          Median :1.000                 Median :1.000            
##  Mean   :2.308          Mean   :1.667                 Mean   :1.717            
##  3rd Qu.:3.000          3rd Qu.:2.000                 3rd Qu.:2.000            
##  Max.   :5.000          Max.   :5.000                 Max.   :5.000            
##  NA's   :322            NA's   :362                   NA's   :356              
##  symptoms_skin_abnormalities_allergies_burden
##  Min.   :1.000                               
##  1st Qu.:1.000                               
##  Median :1.000                               
##  Mean   :2.183                               
##  3rd Qu.:3.000                               
##  Max.   :5.000                               
##  NA's   :345                                 
##  symptoms_discomfort_after_exertion_burden symptoms_tinnitus_burden
##  Min.   :1.000                             Min.   :1.000           
##  1st Qu.:3.000                             1st Qu.:1.000           
##  Median :4.000                             Median :3.000           
##  Mean   :3.816                             Mean   :2.611           
##  3rd Qu.:5.000                             3rd Qu.:4.000           
##  Max.   :5.000                             Max.   :5.000           
##  NA's   :237                               NA's   :321             
##  symptoms_visual_disturbances_burden symptoms_menstrual_disorders_burden
##  Min.   :1.000                       Min.   :1.000                      
##  1st Qu.:1.000                       1st Qu.:1.000                      
##  Median :2.000                       Median :2.000                      
##  Mean   :2.362                       Mean   :2.224                      
##  3rd Qu.:3.000                       3rd Qu.:3.000                      
##  Max.   :5.000                       Max.   :5.000                      
##  NA's   :322                         NA's   :349                        
##  symptoms_anaphylactic_reaction_burden symptoms_protruding_veins_burden
##  Min.   :1.000                         Min.   :1.000                   
##  1st Qu.:1.000                         1st Qu.:1.000                   
##  Median :1.000                         Median :1.000                   
##  Mean   :1.269                         Mean   :1.781                   
##  3rd Qu.:1.000                         3rd Qu.:2.250                   
##  Max.   :4.000                         Max.   :5.000                   
##  NA's   :364                           NA's   :352                     
##  symptoms_new_allergies_burden symptoms_weight_loss_burden
##  Min.   :1.000                 Min.   :1.000              
##  1st Qu.:1.000                 1st Qu.:1.000              
##  Median :1.000                 Median :2.000              
##  Mean   :1.454                 Mean   :2.381              
##  3rd Qu.:1.000                 3rd Qu.:3.000              
##  Max.   :5.000                 Max.   :5.000              
##  NA's   :361                   NA's   :303                
##  covid_vaccinated_before_inf covid_vaccination_after_inf
##  Min.   :0.0000              Min.   :1.000              
##  1st Qu.:0.0000              1st Qu.:1.000              
##  Median :0.0000              Median :1.000              
##  Mean   :0.4527              Mean   :1.442              
##  3rd Qu.:1.0000              3rd Qu.:2.000              
##  Max.   :1.0000              Max.   :2.000              
##  NA's   :120                 NA's   :131                
##  vaccine_1st_vaccination vaccine_1st_vaccination_comment
##  Min.   :1               Length:416                     
##  1st Qu.:1               Class :character               
##  Median :1               Mode  :character               
##  Mean   :1                                              
##  3rd Qu.:1                                              
##  Max.   :1                                              
##  NA's   :291                                            
##  vaccine_2nd_vaccination vaccine_2nd_vaccination_comment
##  Min.   :1               Length:416                     
##  1st Qu.:1               Class :character               
##  Median :1               Mode  :character               
##  Mean   :1                                              
##  3rd Qu.:1                                              
##  Max.   :1                                              
##  NA's   :293                                            
##  vaccine_3rd_vaccination vaccine_3rd_vaccination_comment sick_leave_days 
##  Min.   :1               Length:416                      Min.   :  0.00  
##  1st Qu.:1               Class :character                1st Qu.: 10.00  
##  Median :1               Mode  :character                Median : 16.00  
##  Mean   :1                                               Mean   : 44.38  
##  3rd Qu.:1                                               3rd Qu.: 41.00  
##  Max.   :1                                               Max.   :450.00  
##  NA's   :311                                             NA's   :169     
##  long_covid_symptoms_after_infection_days
##  Min.   :1.000                           
##  1st Qu.:1.000                           
##  Median :2.000                           
##  Mean   :2.219                           
##  3rd Qu.:3.000                           
##  Max.   :5.000                           
##  NA's   :151                             
##  long_covid_symptoms_after_infection_days_other lc_symptoms_fatigue_burden
##  Length:416                                     Min.   :1.000             
##  Class :character                               1st Qu.:4.000             
##  Mode  :character                               Median :4.000             
##                                                 Mean   :4.117             
##                                                 3rd Qu.:5.000             
##                                                 Max.   :5.000             
##                                                 NA's   :152               
##  lc_symptoms_poor_memory_burden
##  Min.   :1.000                 
##  1st Qu.:3.000                 
##  Median :3.000                 
##  Mean   :3.304                 
##  3rd Qu.:4.000                 
##  Max.   :5.000                 
##  NA's   :192                   
##  lc_symptoms_limitation_mental_performance_burden lc_symptoms_fever_burden
##  Min.   :1.000                                    Min.   :0.000           
##  1st Qu.:3.000                                    1st Qu.:1.000           
##  Median :3.000                                    Median :2.000           
##  Mean   :3.426                                    Mean   :1.892           
##  3rd Qu.:4.000                                    3rd Qu.:2.000           
##  Max.   :5.000                                    Max.   :5.000           
##  NA's   :207                                      NA's   :351             
##  lc_symptoms_loss_of_appetite_burden lc_symptoms_rattling_breathing_burden
##  Min.   :1.000                       Min.   :1.000                        
##  1st Qu.:2.000                       1st Qu.:1.000                        
##  Median :2.000                       Median :2.000                        
##  Mean   :2.538                       Mean   :2.043                        
##  3rd Qu.:3.000                       3rd Qu.:3.000                        
##  Max.   :5.000                       Max.   :5.000                        
##  NA's   :312                         NA's   :347                          
##  lc_symptoms_runny_nose_burden lc_symptoms_increased_temperature_burden
##  Min.   :1.000                 Min.   :1                               
##  1st Qu.:1.000                 1st Qu.:1                               
##  Median :2.000                 Median :1                               
##  Mean   :2.247                 Mean   :2                               
##  3rd Qu.:3.000                 3rd Qu.:3                               
##  Max.   :5.000                 Max.   :5                               
##  NA's   :319                   NA's   :355                             
##  lc_symptoms_dry_cough_burden lc_symptoms_vomiting_burden
##  Min.   :1.000                Min.   :1.00               
##  1st Qu.:2.000                1st Qu.:1.00               
##  Median :3.000                Median :1.00               
##  Mean   :2.901                Mean   :1.87               
##  3rd Qu.:4.000                3rd Qu.:2.75               
##  Max.   :5.000                Max.   :5.00               
##  NA's   :295                  NA's   :370                
##  lc_symptoms_sore_throat_burden lc_symptoms_diarrhoea_burden
##  Min.   :1.00                   Min.   :1.000               
##  1st Qu.:1.00                   1st Qu.:1.000               
##  Median :2.00                   Median :2.000               
##  Mean   :2.28                   Mean   :2.397               
##  3rd Qu.:3.00                   3rd Qu.:3.000               
##  Max.   :5.00                   Max.   :5.000               
##  NA's   :316                    NA's   :343                 
##  lc_symptoms_bloody_cough_burden lc_symptoms_chills_or_sweating_burden
##  Min.   :1.000                   Min.   :1.000                        
##  1st Qu.:1.000                   1st Qu.:2.000                        
##  Median :1.000                   Median :3.000                        
##  Mean   :1.227                   Mean   :2.922                        
##  3rd Qu.:1.000                   3rd Qu.:4.000                        
##  Max.   :3.000                   Max.   :5.000                        
##  NA's   :394                     NA's   :301                          
##  lc_symptoms_altered_taste_smell_burden lc_symptoms_sneeze_burden
##  Min.   :1.000                          Min.   :1.000            
##  1st Qu.:2.000                          1st Qu.:1.000            
##  Median :4.000                          Median :2.000            
##  Mean   :3.438                          Mean   :2.296            
##  3rd Qu.:5.000                          3rd Qu.:3.000            
##  Max.   :5.000                          Max.   :5.000            
##  NA's   :288                            NA's   :328              
##  lc_symptoms_difficulty_breathing_normal_oxy_sat_burden
##  Min.   :1.000                                         
##  1st Qu.:3.000                                         
##  Median :3.000                                         
##  Mean   :3.247                                         
##  3rd Qu.:4.000                                         
##  Max.   :5.000                                         
##  NA's   :266                                           
##  lc_symptoms_tightness_chest_burden lc_symptoms_shortness_of_breath_burden
##  Min.   :1.00                       Min.   :1.000                         
##  1st Qu.:2.00                       1st Qu.:2.000                         
##  Median :3.00                       Median :3.000                         
##  Mean   :3.16                       Mean   :3.298                         
##  3rd Qu.:4.00                       3rd Qu.:4.000                         
##  Max.   :5.00                       Max.   :5.000                         
##  NA's   :247                        NA's   :225                           
##  lc_symptoms_cough_mucus_burden lc_symptoms_nausea_burden
##  Min.   :1.000                  Min.   :1.000            
##  1st Qu.:1.000                  1st Qu.:1.000            
##  Median :2.000                  Median :2.000            
##  Mean   :2.494                  Mean   :2.459            
##  3rd Qu.:3.000                  3rd Qu.:3.000            
##  Max.   :5.000                  Max.   :5.000            
##  NA's   :339                    NA's   :342              
##  lc_symptoms_burning_chest_pain_burden
##  Min.   :1.000                        
##  1st Qu.:2.000                        
##  Median :3.000                        
##  Mean   :2.924                        
##  3rd Qu.:4.000                        
##  Max.   :5.000                        
##  NA's   :324                          
##  lc_symptoms_disorientation_confusion_burden lc_symptoms_muscle_pain_burden
##  Min.   :1.000                               Min.   :1.00                  
##  1st Qu.:2.000                               1st Qu.:3.00                  
##  Median :2.000                               Median :3.00                  
##  Mean   :2.571                               Mean   :3.37                  
##  3rd Qu.:3.000                               3rd Qu.:4.00                  
##  Max.   :5.000                               Max.   :5.00                  
##  NA's   :311                                 NA's   :281                   
##  lc_symptoms_dizziness_burden lc_symptoms_low_temp_burden
##  Min.   :1.00                 Min.   :1.000              
##  1st Qu.:2.00                 1st Qu.:1.000              
##  Median :3.00                 Median :2.000              
##  Mean   :3.06                 Mean   :1.938              
##  3rd Qu.:4.00                 3rd Qu.:3.000              
##  Max.   :5.00                 Max.   :5.000              
##  NA's   :248                  NA's   :368                
##  lc_symptoms_exhaustion_burden lc_symptoms_stomach_pain_burden
##  Min.   :1.000                 Min.   :1.000                  
##  1st Qu.:3.000                 1st Qu.:1.000                  
##  Median :4.000                 Median :2.000                  
##  Mean   :4.031                 Mean   :2.355                  
##  3rd Qu.:5.000                 3rd Qu.:3.000                  
##  Max.   :5.000                 Max.   :5.000                  
##  NA's   :189                   NA's   :354                    
##  lc_symptoms_other_sleep_symptoms_burden lc_symptoms_headache_burden
##  Min.   :1.000                           Min.   :1.000              
##  1st Qu.:3.000                           1st Qu.:3.000              
##  Median :4.000                           Median :3.000              
##  Mean   :3.439                           Mean   :3.381              
##  3rd Qu.:4.000                           3rd Qu.:4.000              
##  Max.   :5.000                           Max.   :5.000              
##  NA's   :302                             NA's   :256                
##  lc_symptoms_covidzeh_burden lc_symptoms_hallucinatoin_burden
##  Min.   :1.000               Min.   :1.000                   
##  1st Qu.:1.000               1st Qu.:1.000                   
##  Median :1.000               Median :1.000                   
##  Mean   :2.064               Mean   :1.533                   
##  3rd Qu.:3.000               3rd Qu.:2.000                   
##  Max.   :5.000               Max.   :4.000                   
##  NA's   :385                 NA's   :386                     
##  lc_symptoms_bone_pain_burden lc_symptoms_tachycardia_burden
##  Min.   :1.000                Min.   :1.000                 
##  1st Qu.:2.000                1st Qu.:2.000                 
##  Median :3.000                Median :3.000                 
##  Mean   :3.025                Mean   :2.989                 
##  3rd Qu.:4.000                3rd Qu.:4.000                 
##  Max.   :5.000                Max.   :5.000                 
##  NA's   :336                  NA's   :328                   
##  lc_symptoms_sleepapnoea_burden lc_symptoms_insomnia_burden
##  Min.   :1.000                  Min.   :1.000              
##  1st Qu.:1.000                  1st Qu.:2.000              
##  Median :2.000                  Median :3.000              
##  Mean   :2.333                  Mean   :3.263              
##  3rd Qu.:3.000                  3rd Qu.:4.000              
##  Max.   :5.000                  Max.   :5.000              
##  NA's   :371                    NA's   :264                
##  lc_symptoms_slurred_speech_burden lc_symptoms_joint_pain_burden
##  Min.   :1.000                     Min.   :1.000                
##  1st Qu.:2.000                     1st Qu.:3.000                
##  Median :2.000                     Median :3.000                
##  Mean   :2.318                     Mean   :3.328                
##  3rd Qu.:3.000                     3rd Qu.:4.000                
##  Max.   :5.000                     Max.   :5.000                
##  NA's   :350                       NA's   :294                  
##  lc_symptoms_heart_palpations_burden lc_symptoms_other_temp_deviations_burden
##  Min.   :1.000                       Min.   :1.000                           
##  1st Qu.:3.000                       1st Qu.:1.000                           
##  Median :3.000                       Median :3.000                           
##  Mean   :3.336                       Mean   :2.439                           
##  3rd Qu.:4.000                       3rd Qu.:3.000                           
##  Max.   :5.000                       Max.   :5.000                           
##  NA's   :291                         NA's   :375                             
##  lc_symptoms_other_eye_sympt_burden lc_symptoms_muscle_cramps_burden
##  Min.   :1.000                      Min.   :1.000                   
##  1st Qu.:2.000                      1st Qu.:2.000                   
##  Median :2.500                      Median :3.000                   
##  Mean   :2.585                      Mean   :2.838                   
##  3rd Qu.:3.000                      3rd Qu.:4.000                   
##  Max.   :5.000                      Max.   :5.000                   
##  NA's   :334                        NA's   :342                     
##  lc_symptoms_disturbed_neurological_sensations_burden
##  Min.   :1.000                                       
##  1st Qu.:2.000                                       
##  Median :3.000                                       
##  Mean   :3.021                                       
##  3rd Qu.:4.000                                       
##  Max.   :5.000                                       
##  NA's   :321                                         
##  lc_symptoms_peeling_skin_burden lc_symptoms_heartburn_reflux_burden
##  Min.   :1.000                   Min.   :1.000                      
##  1st Qu.:1.000                   1st Qu.:1.000                      
##  Median :2.000                   Median :2.000                      
##  Mean   :2.053                   Mean   :2.357                      
##  3rd Qu.:3.000                   3rd Qu.:3.000                      
##  Max.   :5.000                   Max.   :5.000                      
##  NA's   :378                     NA's   :360                        
##  lc_symptoms_skin_rash_burden lc_symptoms_constipation_burden
##  Min.   :1.000                Min.   :1.000                  
##  1st Qu.:1.000                1st Qu.:1.000                  
##  Median :2.000                Median :2.000                  
##  Mean   :2.255                Mean   :2.143                  
##  3rd Qu.:3.000                3rd Qu.:3.000                  
##  Max.   :5.000                Max.   :5.000                  
##  NA's   :365                  NA's   :367                    
##  lc_symptoms_bladder_control_problems_burden lc_symptoms_hearloss_burden
##  Min.   :1.000                               Min.   :1.000              
##  1st Qu.:1.000                               1st Qu.:1.000              
##  Median :2.000                               Median :2.000              
##  Mean   :2.389                               Mean   :2.079              
##  3rd Qu.:3.750                               3rd Qu.:3.000              
##  Max.   :5.000                               Max.   :5.000              
##  NA's   :362                                 NA's   :378                
##  lc_symptoms_bradycardia_burden lc_symptoms_nerve_pain_burden
##  Min.   :1.000                  Min.   :1.000                
##  1st Qu.:1.000                  1st Qu.:2.000                
##  Median :2.000                  Median :3.000                
##  Mean   :1.731                  Mean   :3.108                
##  3rd Qu.:2.000                  3rd Qu.:4.000                
##  Max.   :4.000                  Max.   :5.000                
##  NA's   :390                    NA's   :342                  
##  lc_symptoms_hearing_impairment_burden lc_symptoms_tremor_burden
##  Min.   :1.000                         Min.   :1.000            
##  1st Qu.:1.000                         1st Qu.:1.000            
##  Median :2.000                         Median :2.000            
##  Mean   :2.239                         Mean   :2.377            
##  3rd Qu.:3.000                         3rd Qu.:3.000            
##  Max.   :5.000                         Max.   :5.000            
##  NA's   :370                           NA's   :347              
##  lc_symptoms_dermographism_burden lc_symtpoms_petechiae_burden
##  Min.   :1.000                    Min.   :1.000               
##  1st Qu.:1.000                    1st Qu.:1.000               
##  Median :1.000                    Median :1.000               
##  Mean   :2.207                    Mean   :1.852               
##  3rd Qu.:3.000                    3rd Qu.:3.000               
##  Max.   :5.000                    Max.   :5.000               
##  NA's   :387                      NA's   :389                 
##  lc_symptoms_skin_abnormalities_allergies_burden
##  Min.   :1.000                                  
##  1st Qu.:2.000                                  
##  Median :2.000                                  
##  Mean   :2.579                                  
##  3rd Qu.:3.000                                  
##  Max.   :5.000                                  
##  NA's   :359                                    
##  lc_symptoms_discomfort_after_exertion_burden lc_symptoms_tinnitus_burden
##  Min.   :2.000                                Min.   :1.000              
##  1st Qu.:3.000                                1st Qu.:2.000              
##  Median :4.000                                Median :3.000              
##  Mean   :3.925                                Mean   :3.032              
##  3rd Qu.:5.000                                3rd Qu.:4.000              
##  Max.   :5.000                                Max.   :5.000              
##  NA's   :243                                  NA's   :353                
##  lc_symptoms_visual_disturbances_burden lc_symptoms_menstrual_disorders_burden
##  Min.   :1.000                          Min.   :1.000                         
##  1st Qu.:2.000                          1st Qu.:1.500                         
##  Median :2.000                          Median :2.000                         
##  Mean   :2.573                          Mean   :2.529                         
##  3rd Qu.:3.000                          3rd Qu.:3.000                         
##  Max.   :5.000                          Max.   :5.000                         
##  NA's   :334                            NA's   :365                           
##  lc_symptoms_anaphylactic_reaction_burden lc_symptoms_protruding_veins_burden
##  Min.   :1.000                            Min.   :1.000                      
##  1st Qu.:1.000                            1st Qu.:1.000                      
##  Median :1.000                            Median :2.500                      
##  Mean   :1.737                            Mean   :2.316                      
##  3rd Qu.:1.500                            3rd Qu.:3.000                      
##  Max.   :5.000                            Max.   :5.000                      
##  NA's   :397                              NA's   :378                        
##  lc_symptoms_new_allergies_burden lc_symptoms_weight_loss_burden
##  Min.   :1.000                    Min.   :1.000                 
##  1st Qu.:1.000                    1st Qu.:1.000                 
##  Median :2.000                    Median :2.000                 
##  Mean   :2.151                    Mean   :2.418                 
##  3rd Qu.:3.000                    3rd Qu.:3.000                 
##  Max.   :4.000                    Max.   :5.000                 
##  NA's   :383                      NA's   :361                   
##  relation_between_LongCovid_symptoms investigation_longcovid_symptoms
##  Length:416                          Min.   :1.000                   
##  Class :character                    1st Qu.:1.000                   
##  Mode  :character                    Median :1.000                   
##                                      Mean   :1.377                   
##                                      3rd Qu.:2.000                   
##                                      Max.   :2.000                   
##                                      NA's   :156                     
##  investigation_longcovid_symptoms_CT
##  Min.   :1                          
##  1st Qu.:1                          
##  Median :1                          
##  Mean   :1                          
##  3rd Qu.:1                          
##  Max.   :1                          
##  NA's   :359                        
##  investigation_longcovid_symptoms_CT_comment
##  Length:416                                 
##  Class :character                           
##  Mode  :character                           
##                                             
##                                             
##                                             
##                                             
##  investigation_longcovid_symptoms_MRI
##  Min.   :1                           
##  1st Qu.:1                           
##  Median :1                           
##  Mean   :1                           
##  3rd Qu.:1                           
##  Max.   :1                           
##  NA's   :354                         
##  investigation_longcovid_symptoms_MRI_comment
##  Length:416                                  
##  Class :character                            
##  Mode  :character                            
##                                              
##                                              
##                                              
##                                              
##  investigation_longcovid_symptoms_Xray
##  Min.   :1                            
##  1st Qu.:1                            
##  Median :1                            
##  Mean   :1                            
##  3rd Qu.:1                            
##  Max.   :1                            
##  NA's   :330                          
##  investigation_longcovid_symptoms_Xray_comment
##  Length:416                                   
##  Class :character                             
##  Mode  :character                             
##                                               
##                                               
##                                               
##                                               
##  investigation_longcovid_symptoms_LungFunctionTest
##  Min.   :1                                        
##  1st Qu.:1                                        
##  Median :1                                        
##  Mean   :1                                        
##  3rd Qu.:1                                        
##  Max.   :1                                        
##  NA's   :298                                      
##  investigation_longcovid_symptoms_LungFunctionTest_comment
##  Length:416                                               
##  Class :character                                         
##  Mode  :character                                         
##                                                           
##                                                           
##                                                           
##                                                           
##  investigation_longcovid_symptoms_NeuroTest
##  Min.   :1                                 
##  1st Qu.:1                                 
##  Median :1                                 
##  Mean   :1                                 
##  3rd Qu.:1                                 
##  Max.   :1                                 
##  NA's   :349                               
##  investigation_longcovid_symptoms_NeuroTest_comment
##  Length:416                                        
##  Class :character                                  
##  Mode  :character                                  
##                                                    
##                                                    
##                                                    
##                                                    
##  investigation_longcovid_symptoms_NeuroPsychTest
##  Min.   :1                                      
##  1st Qu.:1                                      
##  Median :1                                      
##  Mean   :1                                      
##  3rd Qu.:1                                      
##  Max.   :1                                      
##  NA's   :374                                    
##  investigation_longcovid_symptoms_NeuroPsychTest_comment
##  Length:416                                             
##  Class :character                                       
##  Mode  :character                                       
##                                                         
##                                                         
##                                                         
##                                                         
##  investigation_longcovid_symptoms_other
##  Length:416                            
##  Class :character                      
##  Mode  :character                      
##                                        
##                                        
##                                        
##                                        
##  investigation_longcovid_symptoms_other_comment long_covid_outpatient_dep
##  Length:416                                     Min.   :1.000            
##  Class :character                               1st Qu.:2.000            
##  Mode  :character                               Median :2.000            
##                                                 Mean   :1.823            
##                                                 3rd Qu.:2.000            
##                                                 Max.   :2.000            
##                                                 NA's   :156              
##  long_covid_reha Long_Covid_Symptoms_worse_after_physical_activity
##  Min.   :1.000   Min.   :1                                        
##  1st Qu.:2.000   1st Qu.:1                                        
##  Median :2.000   Median :1                                        
##  Mean   :1.781   Mean   :1                                        
##  3rd Qu.:2.000   3rd Qu.:1                                        
##  Max.   :2.000   Max.   :1                                        
##  NA's   :151     NA's   :230                                      
##  Long_Covid_Symptoms_better_after_physical_activity
##  Min.   :1                                         
##  1st Qu.:1                                         
##  Median :1                                         
##  Mean   :1                                         
##  3rd Qu.:1                                         
##  Max.   :1                                         
##  NA's   :394                                       
##  Long_Covid_Symptoms_worse_after_mental_activity
##  Min.   :1                                      
##  1st Qu.:1                                      
##  Median :1                                      
##  Mean   :1                                      
##  3rd Qu.:1                                      
##  Max.   :1                                      
##  NA's   :278                                    
##  Long_Covid_Symptoms_better_after_mental_activity
##  Min.   :1                                       
##  1st Qu.:1                                       
##  Median :1                                       
##  Mean   :1                                       
##  3rd Qu.:1                                       
##  Max.   :1                                       
##  NA's   :404                                     
##  Long_Covid_Symptoms_fluctuating Long_Covid_Symptoms_getting_better_overall
##  Min.   :1                       Min.   :1                                 
##  1st Qu.:1                       1st Qu.:1                                 
##  Median :1                       Median :1                                 
##  Mean   :1                       Mean   :1                                 
##  3rd Qu.:1                       3rd Qu.:1                                 
##  Max.   :1                       Max.   :1                                 
##  NA's   :274                     NA's   :347                               
##  Long_Covid_Symptoms_getting_worse_overall Long_Covid_Symptoms_staying_the_same
##  Min.   :1                                 Min.   :1                           
##  1st Qu.:1                                 1st Qu.:1                           
##  Median :1                                 Median :1                           
##  Mean   :1                                 Mean   :1                           
##  3rd Qu.:1                                 3rd Qu.:1                           
##  Max.   :1                                 Max.   :1                           
##  NA's   :395                               NA's   :341                         
##  Long_Covid_Symptoms_other Control_over_breathing Oxygen_therapy_at_home
##  Length:416                Min.   :1.000          Min.   :1.000         
##  Class :character          1st Qu.:1.000          1st Qu.:2.000         
##  Mode  :character          Median :1.000          Median :2.000         
##                            Mean   :1.413          Mean   :1.989         
##                            3rd Qu.:2.000          3rd Qu.:2.000         
##                            Max.   :2.000          Max.   :2.000         
##                            NA's   :174            NA's   :147           
##  Alteration_stress_resistance_since_covid
##  Min.   :1.000                           
##  1st Qu.:1.000                           
##  Median :1.000                           
##  Mean   :1.125                           
##  3rd Qu.:1.000                           
##  Max.   :2.000                           
##  NA's   :152                             
##  Alteration_stress_resistance_since_covid_specification
##  Min.   :1.000                                         
##  1st Qu.:1.000                                         
##  Median :1.000                                         
##  Mean   :1.018                                         
##  3rd Qu.:1.000                                         
##  Max.   :2.000                                         
##  NA's   :188                                           
##  Alteration_mood_since_covid Alteration_mood_since_covid_specification
##  Min.   :1.000               Min.   :1.000                            
##  1st Qu.:1.000               1st Qu.:2.000                            
##  Median :1.000               Median :2.000                            
##  Mean   :1.279               Mean   :1.956                            
##  3rd Qu.:2.000               3rd Qu.:2.000                            
##  Max.   :2.000               Max.   :2.000                            
##  NA's   :154                 NA's   :235                              
##    Need_help     Need_help_from_organisation Need_help_from_relatives
##  Min.   :1.000   Min.   :1                   Min.   :1               
##  1st Qu.:2.000   1st Qu.:1                   1st Qu.:1               
##  Median :2.000   Median :1                   Median :1               
##  Mean   :1.767   Mean   :1                   Mean   :1               
##  3rd Qu.:2.000   3rd Qu.:1                   3rd Qu.:1               
##  Max.   :2.000   Max.   :1                   Max.   :1               
##  NA's   :154     NA's   :412                 NA's   :355             
##  Need_help_from_organisation_specification
##  Length:416                               
##  Class :character                         
##  Mode  :character                         
##                                           
##                                           
##                                           
##                                           
##  Need_help_from_relatives_specification more_addictive_substances_or_drugs
##  Length:416                             Min.   :1.000                     
##  Class :character                       1st Qu.:1.000                     
##  Mode  :character                       Median :2.000                     
##                                         Mean   :1.554                     
##                                         3rd Qu.:2.000                     
##                                         Max.   :2.000                     
##                                         NA's   :156                       
##  more_addictive_substances_or_drugs_alcohol
##  Min.   :1                                 
##  1st Qu.:1                                 
##  Median :1                                 
##  Mean   :1                                 
##  3rd Qu.:1                                 
##  Max.   :1                                 
##  NA's   :410                               
##  more_addictive_substances_or_drugs_illegal_drugs
##  Min.   :1                                       
##  1st Qu.:1                                       
##  Median :1                                       
##  Mean   :1                                       
##  3rd Qu.:1                                       
##  Max.   :1                                       
##  NA's   :415                                     
##  more_addictive_substances_or_drugs_nicotin
##  Min.   :1                                 
##  1st Qu.:1                                 
##  Median :1                                 
##  Mean   :1                                 
##  3rd Qu.:1                                 
##  Max.   :1                                 
##  NA's   :410                               
##  more_addictive_substances_or_drugs_meds
##  Min.   :1                              
##  1st Qu.:1                              
##  Median :1                              
##  Mean   :1                              
##  3rd Qu.:1                              
##  Max.   :1                              
##  NA's   :310                            
##  more_addictive_substances_or_drugs_other Alteration_sexuality
##  Length:416                               Min.   :1.000       
##  Class :character                         1st Qu.:1.000       
##  Mode  :character                         Median :2.000       
##                                           Mean   :1.619       
##                                           3rd Qu.:2.000       
##                                           Max.   :2.000       
##                                           NA's   :185         
##  Alteration_sexuality_specification exercises_against_symptoms_breathing
##  Length:416                         Min.   :1                           
##  Class :character                   1st Qu.:1                           
##  Mode  :character                   Median :1                           
##                                     Mean   :1                           
##                                     3rd Qu.:1                           
##                                     Max.   :1                           
##                                     NA's   :291                         
##  exercises_against_symptoms_movement exercises_against_symptoms_cognitive
##  Min.   :1                           Min.   :1                           
##  1st Qu.:1                           1st Qu.:1                           
##  Median :1                           Median :1                           
##  Mean   :1                           Mean   :1                           
##  3rd Qu.:1                           3rd Qu.:1                           
##  Max.   :1                           Max.   :1                           
##  NA's   :278                         NA's   :330                         
##  exercises_against_symptoms_nothing exercises_against_symptoms_other
##  Min.   :1                          Length:416                      
##  1st Qu.:1                          Class :character                
##  Median :1                          Mode  :character                
##  Mean   :1                                                          
##  3rd Qu.:1                                                          
##  Max.   :1                                                          
##  NA's   :352                                                        
##  what_believe_would_help_breathing_exercises
##  Min.   :1                                  
##  1st Qu.:1                                  
##  Median :1                                  
##  Mean   :1                                  
##  3rd Qu.:1                                  
##  Max.   :1                                  
##  NA's   :299                                
##  what_believe_would_help_movement_exercises
##  Min.   :1                                 
##  1st Qu.:1                                 
##  Median :1                                 
##  Mean   :1                                 
##  3rd Qu.:1                                 
##  Max.   :1                                 
##  NA's   :272                               
##  what_believe_would_help_cognitive_exercises
##  Min.   :1                                  
##  1st Qu.:1                                  
##  Median :1                                  
##  Mean   :1                                  
##  3rd Qu.:1                                  
##  Max.   :1                                  
##  NA's   :287                                
##  what_believe_would_help_other_exercises considered_training_no
##  Length:416                              Min.   :1             
##  Class :character                        1st Qu.:1             
##  Mode  :character                        Median :1             
##                                          Mean   :1             
##                                          3rd Qu.:1             
##                                          Max.   :1             
##                                          NA's   :329           
##  considered_training_cognitive considered_training_physical
##  Min.   :1                     Min.   :1                   
##  1st Qu.:1                     1st Qu.:1                   
##  Median :1                     Median :1                   
##  Mean   :1                     Mean   :1                   
##  3rd Qu.:1                     3rd Qu.:1                   
##  Max.   :1                     Max.   :1                   
##  NA's   :327                   NA's   :278                 
##  considered_training_other motivation_to_train_better_physical_health
##  Length:416                Min.   :1                                 
##  Class :character          1st Qu.:1                                 
##  Mode  :character          Median :1                                 
##                            Mean   :1                                 
##                            3rd Qu.:1                                 
##                            Max.   :1                                 
##                            NA's   :212                               
##  motivation_to_train_better_mental_health
##  Min.   :1                               
##  1st Qu.:1                               
##  Median :1                               
##  Mean   :1                               
##  3rd Qu.:1                               
##  Max.   :1                               
##  NA's   :262                             
##  motivation_to_train_interested_learning_new_things
##  Min.   :1                                         
##  1st Qu.:1                                         
##  Median :1                                         
##  Mean   :1                                         
##  3rd Qu.:1                                         
##  Max.   :1                                         
##  NA's   :358                                       
##  motivation_to_train_training_from_home motivation_to_train_self_paced
##  Min.   :1                              Min.   :1                     
##  1st Qu.:1                              1st Qu.:1                     
##  Median :1                              Median :1                     
##  Mean   :1                              Mean   :1                     
##  3rd Qu.:1                              3rd Qu.:1                     
##  Max.   :1                              Max.   :1                     
##  NA's   :311                            NA's   :324                   
##  motivation_to_train_social_contacts motivation_to_train_other
##  Min.   :1                           Length:416               
##  1st Qu.:1                           Class :character         
##  Median :1                           Mode  :character         
##  Mean   :1                                                    
##  3rd Qu.:1                                                    
##  Max.   :1                                                    
##  NA's   :370
#Evaluamos posibles datos faltantes
nas_por_variable <- sort(colSums(is.na(covid)), decreasing = TRUE)
print(head(nas_por_variable[nas_por_variable > 0], 254))
##                                              com_dementia 
##                                                       416 
##                                             com_parkinson 
##                                                       416 
##                                              com_epilepsy 
##                                                       416 
##                                                    com_MS 
##                                                       416 
##                                              origin_other 
##                                                       415 
##          more_addictive_substances_or_drugs_illegal_drugs 
##                                                       415 
##                                                com_stroke 
##                                                       414 
##                 Need_help_from_organisation_specification 
##                                                       414 
##                                                  com_copd 
##                                                       412 
##                               Need_help_from_organisation 
##                                                       412 
##                                 com_cardiac_insufficiency 
##                                                       411 
##                                       current_job_Schüler 
##                                                       411 
##                                                com_cancer 
##                                                       410 
##                                           com_cancer_type 
##                                                       410 
##                more_addictive_substances_or_drugs_alcohol 
##                                                       410 
##                more_addictive_substances_or_drugs_nicotin 
##                                                       410 
##                                  current_job_Arbeitsloser 
##                                                       409 
##                      covid_infection_acute_duration_other 
##                                                       407 
##                  more_addictive_substances_or_drugs_other 
##                                                       407 
##                                              com_diabetes 
##                                                       406 
##                             changes_work_covid_job_change 
##                                                       406 
##                        changes_work_covid_no_work_anymore 
##                                                       404 
##          Long_Covid_Symptoms_better_after_mental_activity 
##                                                       404 
##                                      current_job_Arbeiter 
##                                                       400 
##                                           education_other 
##                                                       398 
##                               course_disease_asymptomatic 
##                                                       398 
##                              hospitalization_cov19_or_ICU 
##                                                       398 
##                            covid_hospitalization_duration 
##                                                       398 
##                  lc_symptoms_anaphylactic_reaction_burden 
##                                                       397 
##   investigation_longcovid_symptoms_NeuroPsychTest_comment 
##                                                       397 
##                 Long_Covid_Symptoms_getting_worse_overall 
##                                                       395 
##                                       current_job_Student 
##                                                       394 
##                                         current_job_other 
##                                                       394 
##                           lc_symptoms_bloody_cough_burden 
##                                                       394 
##        Long_Covid_Symptoms_better_after_physical_activity 
##                                                       394 
##                                    current_job_Pensionist 
##                                                       393 
##                                 considered_training_other 
##                                                       393 
##                                 motivation_to_train_other 
##                                                       393 
##                                  changes_work_covid_other 
##                                                       392 
##                            lc_symptoms_bradycardia_burden 
##                                                       390 
##                              lc_symtpoms_petechiae_burden 
##                                                       389 
##                               current_job_Selbstständiger 
##                                                       387 
##                          lc_symptoms_dermographism_burden 
##                                                       387 
##                                            com_hypertonia 
##                                                       386 
##                          lc_symptoms_hallucinatoin_burden 
##                                                       386 
##                    investigation_longcovid_symptoms_other 
##                                                       386 
##            investigation_longcovid_symptoms_other_comment 
##                                                       386 
##                          changes_work_covid_hours_reduced 
##                                                       385 
##                               lc_symptoms_covidzeh_burden 
##                                                       385 
##                                 Long_Covid_Symptoms_other 
##                                                       385 
##                          lc_symptoms_new_allergies_burden 
##                                                       383 
##                           lc_symptoms_peeling_skin_burden 
##                                                       378 
##                               lc_symptoms_hearloss_burden 
##                                                       378 
##                       lc_symptoms_protruding_veins_burden 
##                                                       378 
##            long_covid_symptoms_after_infection_days_other 
##                                                       377 
##        investigation_longcovid_symptoms_NeuroTest_comment 
##                                                       377 
##                  lc_symptoms_other_temp_deviations_burden 
##                                                       375 
##           investigation_longcovid_symptoms_NeuroPsychTest 
##                                                       374 
##               investigation_longcovid_symptoms_CT_comment 
##                                                       372 
##                            lc_symptoms_sleepapnoea_burden 
##                                                       371 
##                               lc_symptoms_vomiting_burden 
##                                                       370 
##                     lc_symptoms_hearing_impairment_burden 
##                                                       370 
##                       motivation_to_train_social_contacts 
##                                                       370 
##              investigation_longcovid_symptoms_MRI_comment 
##                                                       369 
##                               lc_symptoms_low_temp_burden 
##                                                       368 
##                           lc_symptoms_constipation_burden 
##                                                       367 
##                              lc_symptoms_skin_rash_burden 
##                                                       365 
##                    lc_symptoms_menstrual_disorders_burden 
##                                                       365 
##                     symptoms_anaphylactic_reaction_burden 
##                                                       364 
##                             symptoms_dermographism_burden 
##                                                       362 
##               lc_symptoms_bladder_control_problems_burden 
##                                                       362 
##                             symptoms_new_allergies_burden 
##                                                       361 
##                            lc_symptoms_weight_loss_burden 
##                                                       361 
##                    Need_help_from_relatives_specification 
##                                                       361 
##                       lc_symptoms_heartburn_reflux_burden 
##                                                       360 
##           lc_symptoms_skin_abnormalities_allergies_burden 
##                                                       359 
##                       investigation_longcovid_symptoms_CT 
##                                                       359 
##        motivation_to_train_interested_learning_new_things 
##                                                       358 
##                                     course_disease_severe 
##                                                       357 
##                                 symtpoms_petechiae_burden 
##                                                       356 
##                              symptoms_bloody_cough_burden 
##                                                       355 
##                             symptoms_hallucinatoin_burden 
##                                                       355 
##                  lc_symptoms_increased_temperature_burden 
##                                                       355 
##                                  Need_help_from_relatives 
##                                                       355 
##                           lc_symptoms_stomach_pain_burden 
##                                                       354 
##                      investigation_longcovid_symptoms_MRI 
##                                                       354 
##             investigation_longcovid_symptoms_Xray_comment 
##                                                       354 
##                               lc_symptoms_tinnitus_burden 
##                                                       353 
##                          symptoms_protruding_veins_burden 
##                                                       352 
## investigation_longcovid_symptoms_LungFunctionTest_comment 
##                                                       352 
##                        exercises_against_symptoms_nothing 
##                                                       352 
##                     symptoms_other_temp_deviations_burden 
##                                                       351 
##                               symptoms_bradycardia_burden 
##                                                       351 
##                                  lc_symptoms_fever_burden 
##                                                       351 
##                         lc_symptoms_slurred_speech_burden 
##                                                       350 
##                       symptoms_menstrual_disorders_burden 
##                                                       349 
##                investigation_longcovid_symptoms_NeuroTest 
##                                                       349 
##                                  symptoms_covidzeh_burden 
##                                                       348 
##                              symptoms_peeling_skin_burden 
##                                                       347 
##                                  symptoms_hearloss_burden 
##                                                       347 
##                     lc_symptoms_rattling_breathing_burden 
##                                                       347 
##                                 lc_symptoms_tremor_burden 
##                                                       347 
##                Long_Covid_Symptoms_getting_better_overall 
##                                                       347 
##                          exercises_against_symptoms_other 
##                                                       346 
##              symptoms_skin_abnormalities_allergies_burden 
##                                                       345 
##                              symptoms_constipation_burden 
##                                                       343 
##                  symptoms_bladder_control_problems_burden 
##                                                       343 
##                              lc_symptoms_diarrhoea_burden 
##                                                       343 
##                        symptoms_hearing_impairment_burden 
##                                                       342 
##                                 lc_symptoms_nausea_burden 
##                                                       342 
##                          lc_symptoms_muscle_cramps_burden 
##                                                       342 
##                             lc_symptoms_nerve_pain_burden 
##                                                       342 
##                      Long_Covid_Symptoms_staying_the_same 
##                                                       341 
##                        Alteration_sexuality_specification 
##                                                       341 
##                             changes_work_covid_sick_leave 
##                                                       339 
##                            lc_symptoms_cough_mucus_burden 
##                                                       339 
##                            symptoms_slurred_speech_burden 
##                                                       337 
##                              lc_symptoms_bone_pain_burden 
##                                                       336 
##                               symptoms_sleepapnoea_burden 
##                                                       335 
##                                 symptoms_skin_rash_burden 
##                                                       335 
##                        lc_symptoms_other_eye_sympt_burden 
##                                                       334 
##                    lc_symptoms_visual_disturbances_burden 
##                                                       334 
##                   what_believe_would_help_other_exercises 
##                                                       333 
##                     investigation_longcovid_symptoms_Xray 
##                                                       330 
##                      exercises_against_symptoms_cognitive 
##                                                       330 
##                                  symptoms_low_temp_burden 
##                                                       329 
##                          symptoms_heartburn_reflux_burden 
##                                                       329 
##                                    considered_training_no 
##                                                       329 
##                                 lc_symptoms_sneeze_burden 
##                                                       328 
##                            lc_symptoms_tachycardia_burden 
##                                                       328 
##                             considered_training_cognitive 
##                                                       327 
##                     lc_symptoms_burning_chest_pain_burden 
##                                                       324 
##                            motivation_to_train_self_paced 
##                                                       324 
##                                                 com_other 
##                                                       322 
##                                    symptoms_tremor_burden 
##                                                       322 
##                       symptoms_visual_disturbances_burden 
##                                                       322 
##                                  symptoms_tinnitus_burden 
##                                                       321 
##      lc_symptoms_disturbed_neurological_sensations_burden 
##                                                       321 
##                             symptoms_muscle_cramps_burden 
##                                                       319 
##                             lc_symptoms_runny_nose_burden 
##                                                       319 
##                            lc_symptoms_sore_throat_burden 
##                                                       316 
##                           vaccine_3rd_vaccination_comment 
##                                                       313 
##         symptoms_disturbed_neurological_sensations_burden 
##                                                       312 
##                       lc_symptoms_loss_of_appetite_burden 
##                                                       312 
##                                  symptoms_vomiting_burden 
##                                                       311 
##                                symptoms_nerve_pain_burden 
##                                                       311 
##                                   vaccine_3rd_vaccination 
##                                                       311 
##               lc_symptoms_disorientation_confusion_burden 
##                                                       311 
##                    motivation_to_train_training_from_home 
##                                                       311 
##                              symptoms_stomach_pain_burden 
##                                                       310 
##                   more_addictive_substances_or_drugs_meds 
##                                                       310 
##                           symptoms_other_eye_sympt_burden 
##                                                       304 
##                               symptoms_weight_loss_burden 
##                                                       303 
##                   lc_symptoms_other_sleep_symptoms_burden 
##                                                       302 
##                     lc_symptoms_chills_or_sweating_burden 
##                                                       301 
##               what_believe_would_help_breathing_exercises 
##                                                       299 
##         investigation_longcovid_symptoms_LungFunctionTest 
##                                                       298 
##                               symptoms_tachycardia_burden 
##                                                       296 
##                           vaccine_2nd_vaccination_comment 
##                                                       295 
##                              lc_symptoms_dry_cough_burden 
##                                                       295 
##                  symptoms_disorientation_confusion_burden 
##                                                       294 
##                             lc_symptoms_joint_pain_burden 
##                                                       294 
##                           vaccine_1st_vaccination_comment 
##                                                       293 
##                                   vaccine_2nd_vaccination 
##                                                       293 
##                        symptoms_burning_chest_pain_burden 
##                                                       292 
##                                   vaccine_1st_vaccination 
##                                                       291 
##                       lc_symptoms_heart_palpations_burden 
##                                                       291 
##                      exercises_against_symptoms_breathing 
##                                                       291 
##                                 symptoms_bone_pain_burden 
##                                                       288 
##                    lc_symptoms_altered_taste_smell_burden 
##                                                       288 
##                                    symptoms_nausea_burden 
##                                                       287 
##               what_believe_would_help_cognitive_exercises 
##                                                       287 
##                            lc_symptoms_muscle_pain_burden 
##                                                       281 
##           Long_Covid_Symptoms_worse_after_mental_activity 
##                                                       278 
##                       exercises_against_symptoms_movement 
##                                                       278 
##                              considered_training_physical 
##                                                       278 
##                                 symptoms_diarrhoea_burden 
##                                                       276 
##                           Long_Covid_Symptoms_fluctuating 
##                                                       274 
##                what_believe_would_help_movement_exercises 
##                                                       272 
##                               symptoms_cough_mucus_burden 
##                                                       269 
##                          symptoms_heart_palpations_burden 
##                                                       269 
##    lc_symptoms_difficulty_breathing_normal_oxy_sat_burden 
##                                                       266 
##                      symptoms_other_sleep_symptoms_burden 
##                                                       265 
##                                  symptoms_insomnia_burden 
##                                                       264 
##                               lc_symptoms_insomnia_burden 
##                                                       264 
##                       relation_between_LongCovid_symptoms 
##                                                       264 
##                  motivation_to_train_better_mental_health 
##                                                       262 
##                        symptoms_rattling_breathing_burden 
##                                                       257 
##                               lc_symptoms_headache_burden 
##                                                       256 
##                                           education_years 
##                                                       252 
##                              lc_symptoms_dizziness_burden 
##                                                       248 
##                                symptoms_joint_pain_burden 
##                                                       247 
##                        lc_symptoms_tightness_chest_burden 
##                                                       247 
##                                    symptoms_sneeze_burden 
##                                                       243 
##              lc_symptoms_discomfort_after_exertion_burden 
##                                                       243 
##                 symptoms_discomfort_after_exertion_burden 
##                                                       237 
##                 Alteration_mood_since_covid_specification 
##                                                       235 
##         Long_Covid_Symptoms_worse_after_physical_activity 
##                                                       230 
##                    lc_symptoms_shortness_of_breath_burden 
##                                                       225 
##                                 symptoms_dizziness_burden 
##                                                       224 
##                       symptoms_altered_taste_smell_burden 
##                                                       219 
##                     symptoms_increased_temperature_burden 
##                                                       218 
##       symptoms_difficulty_breathing_normal_oxy_sat_burden 
##                                                       215 
##                motivation_to_train_better_physical_health 
##                                                       212 
##                               symptoms_sore_throat_burden 
##                                                       210 
##                           symptoms_tightness_chest_burden 
##                                                       210 
##          lc_symptoms_limitation_mental_performance_burden 
##                                                       207 
##                       symptoms_shortness_of_breath_burden 
##                                                       201 
##                                             comorbidities 
##                                                       199 
##                        symptoms_chills_or_sweating_burden 
##                                                       199 
##                               symptoms_muscle_pain_burden 
##                                                       199 
##                                     symptoms_fever_burden 
##                                                       198 
##                          symptoms_loss_of_appetite_burden 
##                                                       197 
##                                  symptoms_headache_burden 
##                                                       197 
##                                       course_disease_mild 
##                                                       194 
##                                symptoms_runny_nose_burden 
##                                                       193 
##                            lc_symptoms_poor_memory_burden 
##                                                       192 
##                               symptoms_poor_memory_burden 
##                                                       189 
##                             lc_symptoms_exhaustion_burden 
##                                                       189 
##             symptoms_limitation_mental_performance_burden 
##                                                       188 
##    Alteration_stress_resistance_since_covid_specification 
##                                                       188 
##                                 symptoms_dry_cough_burden 
##                                                       186 
##                                      Alteration_sexuality 
##                                                       185 
##                                  current_job_Angestellter 
##                                                       177 
##                                    Control_over_breathing 
##                                                       174 
##                                           sick_leave_days 
##                                                       169 
##                                symptoms_exhaustion_burden 
##                                                       161 
##                          investigation_longcovid_symptoms 
##                                                       156 
##                                 long_covid_outpatient_dep 
##                                                       156 
##                        more_addictive_substances_or_drugs 
##                                                       156 
##                               Alteration_mood_since_covid 
##                                                       154 
##                                                 Need_help 
##                                                       154 
##                                lc_symptoms_fatigue_burden 
##                                                       152 
##                  Alteration_stress_resistance_since_covid 
##                                                       152 
##                  long_covid_symptoms_after_infection_days 
##                                                       151 
##                                           long_covid_reha 
##                                                       151 
##                                    Oxygen_therapy_at_home 
##                                                       147 
##                        duration_since_disease_by_10052022 
##                                                       141 
##                                   symptoms_fatigue_burden 
##                                                       134 
##                               covid_vaccination_after_inf 
##                                                       131 
##                                           hospitalization 
##                                                       120 
##                               covid_vaccinated_before_inf 
##                                                       120 
##                            covid_infection_acute_duration 
##                                                       117 
##                                          financial_losses 
##                                                       100 
##                                                       age 
##                                                        99 
##                                        changes_work_covid 
##                                                        92 
##                                                       BMI 
##                                                        89 
##                                                    height 
##                                                        88 
##                                                    gender 
##                                                        83 
##                                                    weight 
##                                                        83 
##                                                 education 
##                                                        81 
##                                                    origin 
##                                                        79 
##                                        com_hypertonia_new 
##                                                        76

• Realizad cinco gráficos básicos con las variables, explicad su significado y guardadlos como imágenes (jpeg o bmp).

# Gráficos descriptivos de edad, BMI, duración de síntomas, origen y género

# 1. Edad por género - Boxplot
jpeg("01_edad_por_genero.jpg", width = 800, height = 600, quality = 90)
boxplot(covid$age ~ covid$gender, 
        col = c("lightblue", "orange"),
        xlab = "Género", 
        ylab = "Edad (años)",
        main = "Distribución de Edad por Género")
dev.off()
## png 
##   2
# Estos datos muestran que no hay diferencias significativas en la edad entre géneros


# 2. BMI y duración de síntomas - Scatter plot
jpeg("02_bmi_vs_duracion_sintomas.jpg", width = 800, height = 600, quality = 90)
print(
  ggplot(data = covid) + 
    geom_point(aes(x = duration_since_disease_by_10052022, y = BMI)) + 
    labs(x = "Duración síntomas", 
         y = "BMI", 
         title = "Relación entre BMI y duración de síntomas")
)
## Warning: Removed 151 rows containing missing values or values outside the scale range
## (`geom_point()`).
dev.off()
## png 
##   2
# Esta imagen muestra la duración de los síntomas en relación al BMI de los participantes. 
# No muestra una correlación pero sí parece que existen 3 patrones de duración de síntomas: 
# aquellos con una duración menor a 10 meses, otros con una duración entre 12-20 y otros 
# con una duración de 25 meses o más


# 3. Duración de síntomas y edad por género - Scatter plot con color
jpeg("03_edad_vs_duracion_por_genero.jpg", width = 800, height = 600, quality = 90)
print(
  ggplot(data = covid) + 
    geom_point(aes(x = duration_since_disease_by_10052022, y = age, 
                   color = as.factor(gender)), alpha = 0.6) + 
    labs(x = "Duración síntomas", 
         y = "Edad", 
         title = "Relación entre edad y duración de síntomas",
         color = "Género")
)
## Warning: Removed 153 rows containing missing values or values outside the scale range
## (`geom_point()`).
dev.off()
## png 
##   2
# Similar al caso anterior, en esta imagen vemos la relación entre la duración de síntomas 
# y la edad, marcando además el género con diferentes colores. Por la dispersión, tampoco 
# parece que haya una correlación clara entre ambas variables, y sí que vemos que por lo 
# general hay más afectados de género masculino que femenino


# 4. Origen - Histograma
jpeg("04_origen_procedencia.jpg", width = 800, height = 600, quality = 90)
hist(covid$origin, 
     col = "lightblue", 
     xlab = "Origen", 
     main = "Procedencia de los participantes",
     breaks = 10)  # Ajusta el número de barras según necesites
dev.off()
## png 
##   2
# Con este gráfico vemos que la mayoría de la muestra procede del mismo lugar de origen


# 5. Edad y género - Violin + Boxplot + Jitter
jpeg("05_distribucion_edad_por_genero.jpg", width = 800, height = 600, quality = 90)
covid_sin_na <- covid[!is.na(covid$gender) & !is.na(covid$age), ]

print(
  ggplot(data = covid_sin_na, aes(x = as.factor(gender), y = age, fill = as.factor(gender))) +
    geom_violin(alpha = 0.5) +
    geom_boxplot(width = 0.2, fill = "white", alpha = 0.7) +
    geom_jitter(width = 0.1, alpha = 0.3) +
    labs(x = "Género", 
         y = "Edad", 
         title = "Distribución de Edad por Género",
         fill = "Género") +
    theme_minimal()
)
dev.off()
## png 
##   2
# En este caso primero hemos eliminado los valores NA de las variables género y edad, 
# y hemos realizado con ggplot un diagrama de violín + boxplot con los puntos individuales 
# de cada observación (jitter). Además hemos usado la variable gender como factor ya que 
# está codificada en la base de datos como numérica continua

• Realizad dos gráficos con el comando ggplot(), explicad su significado y guardadlos como imágenes (jpeg o bmp).

#GRÁFICO 1 
#Preparar los datos: education como factor (1-11) y eliminar NA
covid_edu_bmi <- covid %>%
  filter(!is.na(education) & !is.na(BMI)) %>%         
  mutate(education_factor = factor(education,           
                                   levels = 1:11,
                                   labels = c("1", "2", "3", "4", "5", "6", 
                                              "7", "8", "9", "10", "11")))

# Crear y guardar el gráfico
jpeg("01_education_vs_bmi.jpg", width = 900, height = 600, quality = 90)

print(
  ggplot(data = covid_edu_bmi, aes(x = education_factor, y = BMI)) +
    geom_boxplot(fill = "lightblue", alpha = 0.7) +
    geom_jitter(width = 0.2, alpha = 0.3, color = "darkblue") +
    labs(x = "Nivel Educativo (1-11)", 
         y = "Índice de Masa Corporal (BMI)",
         title = "Relación entre Nivel Educativo e Índice de Masa Corporal") +
    theme_minimal() +
    theme(axis.text.x = element_text(angle = 45, hjust = 1))
)

dev.off()
## png 
##   2
# GRÁFICO 2

jpeg("02_histograma_fatiga_por_genero.jpg", width = 900, height = 600, quality = 90)

covid_graf2 <- covid[!is.na(covid$symptoms_fatigue_burden) & !is.na(covid$gender), ]

print(
  ggplot(data = covid_graf2, aes(x = symptoms_fatigue_burden, fill = as.factor(gender))) +
    geom_histogram(binwidth = 1,
                   color = "white", 
                   alpha = 0.7,
                   position = "stack") +
    facet_wrap(~as.factor(gender), ncol = 1) +
    labs(x = "Carga de fatiga", 
         y = "Frecuencia",
         title = "Distribución de la Carga de Fatiga por Género",
         subtitle = paste("n =", nrow(covid_graf2), "observaciones")) +
    theme_minimal() +
    theme(legend.position = "none", 
          strip.text = element_text(size = 12, face = "bold"))
)

dev.off()
## png 
##   2

• Generad una regresión lineal entre dos de sus variables paso a paso y comentad los resultados obtenidos.

# Cargamos los datos y hacemos una inspección visual y estadística de los datos
view(covid)
summary(covid[, c("BMI", "duration_since_disease_by_10052022")])
##       BMI        duration_since_disease_by_10052022
##  Min.   :15.42   Min.   : 0.2736                   
##  1st Qu.:21.80   1st Qu.: 2.8034                   
##  Median :24.65   Median :12.1011                   
##  Mean   :25.96   Mean   :10.5355                   
##  3rd Qu.:28.37   3rd Qu.:17.3250                   
##  Max.   :62.50   Max.   :26.4913                   
##  NA's   :89      NA's   :141
# Inspección visual
grafico_visual <- pairs(~ BMI + duration_since_disease_by_10052022, data = covid)

print(grafico_visual)
## NULL
# Hacemos un estudio de correlación, ignorando NA`s
correlacion <- cor.test(covid$BMI, covid$duration_since_disease_by_10052022, 
                        use = "complete.obs")
print(correlacion)
## 
##  Pearson's product-moment correlation
## 
## data:  covid$BMI and covid$duration_since_disease_by_10052022
## t = -0.57136, df = 263, p-value = 0.5682
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.15505028  0.08565256
## sample estimates:
##         cor 
## -0.03520947
# Planteamos el modelo
covid_sin_na <- covid[!is.na(covid$BMI) & !is.na(covid$duration_since_disease_by_10052022), ]
regresion <- lm(BMI ~ duration_since_disease_by_10052022, data = covid_sin_na)
resumen_modelo <- summary(regresion)
print(resumen_modelo)
## 
## Call:
## lm(formula = BMI ~ duration_since_disease_by_10052022, data = covid_sin_na)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -10.325  -4.373  -1.277   2.547  36.482 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        26.47540    0.68289  38.770   <2e-16 ***
## duration_since_disease_by_10052022 -0.02989    0.05231  -0.571    0.568    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.628 on 263 degrees of freedom
## Multiple R-squared:  0.00124,    Adjusted R-squared:  -0.002558 
## F-statistic: 0.3264 on 1 and 263 DF,  p-value: 0.5682
# Graficamos el modelo
plot(covid$duration_since_disease_by_10052022, covid$BMI,
     xlab = "Duración desde la enfermedad (días)",
     ylab = "Índice de Masa Corporal (BMI)",
     main = "Regresión: BMI vs Duración de enfermedad",
     col = "steelblue")
abline(regresion, col = "red")

# Evaluamos residuos
# Eliminamos NA para los residuos
residuos <- rstandard(regresion)
valores_ajustados <- fitted(regresion)

# Gráfico de residuos vs valores ajustados
plot(valores_ajustados, residuos)

qqnorm(residuos)
qqline(residuos)

En este caso vemos que los resultados del análisis de correlación no indican un valor significativo (p=0.56), por lo que, cuando realiamos el modelo de regresión vemos los mismos resultados. Esto nos indica que no existe una correlación entre ambas variables. Además el supuesto de normalidad de los residuos tampoco se cumple como se observa con el diagrama QQ-plot