Actividad 01

## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ 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
## 
## Attaching package: 'kableExtra'
## 
## 
## The following object is masked from 'package:dplyr':
## 
##     group_rows
## 
## 
## Loading required package: carData
## 
## 
## Attaching package: 'car'
## 
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## 
## The following object is masked from 'package:purrr':
## 
##     some
## 
## 
## 
## Attaching package: 'gridExtra'
## 
## 
## The following object is masked from 'package:dplyr':
## 
##     combine
## 
## 
## ------------------------------------------------------------------------------
## 
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## 
## ------------------------------------------------------------------------------
## 
## 
## Attaching package: 'plyr'
## 
## 
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## 
## 
## The following object is masked from 'package:purrr':
## 
##     compact
## 
## 
## 
## Attaching package: 'magrittr'
## 
## 
## The following object is masked from 'package:purrr':
## 
##     set_names
## 
## 
## The following object is masked from 'package:tidyr':
## 
##     extract

#PREGUNTA 1. Si la distribución de los datos es asimétrica, ¿qué estadístico(s) emplearías?

#RESPUESTA: Si tengo datos asimétricos, lo más factible es utilizar los estadísticos de medidas de centralidad (media, mediana y moda), posición (máxima, mínima, cuartiles y percentiles) y de dispersión (recorrido, rango intercuartílico, desviación típica y varianza).

#PREGUNTA 2. Cuando los datos presentan potenciales “outliers”, ¿qué estadístico(s) emplearías?

#RESPUESTA: Los datos que presentan potenciales “outliers”, es conveniente utilizar los estadísticos de posición como lo son los cuartiles, deciles y percentiles, que dan valores considerablemente más estables frente a valores extremos.

#PREGUNTA 3. Un boxplot, ¿permite identificar rápidamente la desviación estándar? ¿por qué?

#RESPUESTA: El gráfico boxplot no se puede identificar la desviación estándar, sino que este se centra es mostrar la distribución que tienen los datos a través del rango intercuartílico, mostrando con ello la mediana, primer y tercer cuartil, limites superiores e inferiores y aquellos datos atípicos.

#PREGUNTA 4. ¿Con qué otros nombres podemos referirnos a las variables cualitativas?

#RESPUESTA: A las variables cualitativas también se le nombran como variables categóricas y están medidas en una escala nominal.

#PREGUNTA 5.- Calcula los estadísticos de 1 de las variables numéricas y de 1 de las variables factor. #### NOTA:Para que no salga error se debe cargar siempre las librerias tidyverse, kableExtra , antes de entrar a configurar tablas

sex weight height repwt repht
M 77 182 77 180
F 58 161 51 159
F 53 161 54 158
M 68 177 70 175
F 59 157 59 155
M 76 170 76 165
## 'data.frame':    200 obs. of  5 variables:
##  $ sex   : Factor w/ 2 levels "F","M": 2 1 1 2 1 2 2 2 2 2 ...
##  $ weight: int  77 58 53 68 59 76 76 69 71 65 ...
##  $ height: int  182 161 161 177 157 170 167 186 178 171 ...
##  $ repwt : int  77 51 54 70 59 76 77 73 71 64 ...
##  $ repht : int  180 159 158 175 155 165 165 180 175 170 ...

Cambiar a variables numericas

## 'data.frame':    200 obs. of  5 variables:
##  $ sex   : Factor w/ 2 levels "F","M": 2 1 1 2 1 2 2 2 2 2 ...
##  $ weight: num  77 58 53 68 59 76 76 69 71 65 ...
##  $ height: num  182 161 161 177 157 170 167 186 178 171 ...
##  $ repwt : num  77 51 54 70 59 76 77 73 71 64 ...
##  $ repht : num  180 159 158 175 155 165 165 180 175 170 ...
## [1] 200   5
## 'data.frame':    200 obs. of  5 variables:
##  $ sex   : Factor w/ 2 levels "F","M": 2 1 1 2 1 2 2 2 2 2 ...
##  $ weight: num  77 58 53 68 59 76 76 69 71 65 ...
##  $ height: num  182 161 161 177 157 170 167 186 178 171 ...
##  $ repwt : num  77 51 54 70 59 76 77 73 71 64 ...
##  $ repht : num  180 159 158 175 155 165 165 180 175 170 ...

Ordenar por el peso y la altura

sex weight height repwt repht
F 39 157 41 153
F 43 154 NA NA
F 44 157 44 155
F 45 157 45 153
F 45 163 45 160
F 47 150 45 152
F 47 153 NA 154
F 47 162 47 160
F 47 163 47 160
F 48 163 44 160
F 49 161 NA NA
F 50 148 47 148
F 50 158 49 155
F 50 160 55 150
F 50 166 50 165
F 50 166 50 161
F 50 169 50 165
F 50 171 NA NA
F 51 156 51 158
F 51 161 52 158
F 51 163 50 160
F 52 152 51 150
F 52 158 51 155
F 52 159 52 153
F 52 163 57 160
F 52 163 53 160
F 52 164 52 161
F 52 169 56 NA
F 53 158 50 155
F 53 161 54 158
F 53 162 53 160
F 53 162 52 158
F 53 164 51 160
F 53 165 53 165
F 53 165 55 163
F 53 169 52 175
F 54 160 55 158
F 54 161 54 160
F 54 163 NA NA
F 54 164 53 160
M 54 169 58 165
F 54 171 59 168
F 54 174 56 173
F 54 176 55 176
F 55 155 NA 154
F 55 160 55 155
F 55 162 NA NA
F 55 164 55 163
F 55 165 54 163
F 55 165 55 163
F 55 165 55 165
M 55 168 56 170
F 55 174 57 171
F 56 160 53 158
F 56 161 56 161
F 56 162 56 160
F 56 163 57 159
M 56 163 58 161
F 56 165 57 163
F 56 165 57 160
F 56 166 54 165
F 56 170 56 170
F 57 162 56 160
F 57 163 59 160
F 57 167 55 164
F 57 167 56 165
F 57 168 58 165
M 57 173 58 170
F 58 161 51 159
F 58 166 60 160
F 58 169 NA NA
F 58 169 54 166
F 59 157 59 155
F 59 157 55 158
F 59 159 59 155
F 59 164 59 165
F 59 166 55 163
F 59 170 NA NA
F 59 172 58 171
M 59 182 61 183
F 60 162 59 160
F 60 167 55 163
F 60 172 55 168
F 60 174 NA NA
F 61 165 60 163
F 61 170 61 170
M 61 170 61 170
F 61 175 61 171
F 62 164 61 161
F 62 166 61 163
F 62 167 NA NA
F 62 168 62 165
F 62 168 62 163
M 62 168 64 168
F 62 175 61 171
F 62 175 63 173
M 62 178 66 175
F 63 160 64 158
F 63 163 59 159
F 63 165 59 160
F 63 169 61 168
F 63 170 62 168
M 63 178 63 175
F 64 164 62 161
F 64 165 63 163
F 64 166 64 165
F 64 168 64 165
F 64 171 66 171
F 64 172 62 168
M 64 176 65 175
M 64 177 NA NA
F 65 166 66 165
M 65 171 64 170
M 65 175 66 173
M 65 176 64 172
M 65 178 66 178
M 65 187 67 188
F 66 166 66 165
F 66 170 65 NA
M 66 170 67 165
M 66 173 70 170
M 66 173 66 175
M 66 175 68 175
M 67 179 67 179
M 67 179 NA NA
M 68 165 69 165
F 68 169 63 170
F 68 171 68 169
M 68 174 68 173
M 68 177 70 175
F 68 178 68 175
M 69 167 73 165
M 69 172 68 174
M 69 174 69 171
M 69 180 71 180
M 69 182 70 180
M 69 183 70 183
M 69 186 73 180
M 70 173 68 170
F 70 173 67 170
M 70 173 70 173
M 70 175 75 174
F 71 166 71 165
M 71 177 71 170
M 71 178 71 175
M 71 178 68 178
M 71 180 76 175
M 73 180 NA NA
M 73 183 74 180
M 74 169 73 170
M 74 175 71 175
F 75 162 75 158
M 75 169 76 165
M 75 172 70 169
M 75 178 73 175
M 76 167 77 165
F 76 167 77 165
M 76 169 75 165
M 76 170 76 165
M 76 183 75 180
M 76 197 75 200
M 77 182 77 180
F 78 173 75 169
M 78 178 77 175
M 78 183 80 180
M 79 173 76 173
M 79 177 81 178
M 79 179 79 171
M 80 176 78 175
M 80 178 80 178
M 80 178 76 175
M 81 175 NA NA
M 81 178 82 175
M 82 176 NA NA
M 82 181 NA NA
M 82 182 85 183
M 83 177 84 175
M 83 180 80 180
M 83 184 83 181
M 84 183 90 183
M 84 184 86 183
M 85 179 82 175
M 85 191 83 188
M 87 185 89 185
M 88 178 86 175
M 88 184 86 183
M 88 185 93 188
M 88 189 87 185
M 89 173 86 173
M 90 181 91 178
M 90 188 91 185
M 92 187 101 185
M 96 184 94 183
M 96 191 95 188
M 97 189 98 185
M 101 183 100 180
M 102 185 107 185
M 103 185 101 182
M 119 180 124 178
F 166 57 56 163

Ver el resumen como factores

##  sex    
##  F:112  
##  M: 88

Ver el resumen como números

##      weight          height          repwt            repht      
##  Min.   : 39.0   Min.   : 57.0   Min.   : 41.00   Min.   :148.0  
##  1st Qu.: 55.0   1st Qu.:164.0   1st Qu.: 55.00   1st Qu.:160.5  
##  Median : 63.0   Median :169.5   Median : 63.00   Median :168.0  
##  Mean   : 65.8   Mean   :170.0   Mean   : 65.62   Mean   :168.5  
##  3rd Qu.: 74.0   3rd Qu.:177.2   3rd Qu.: 73.50   3rd Qu.:175.0  
##  Max.   :166.0   Max.   :197.0   Max.   :124.00   Max.   :200.0  
##                                  NA's   :17       NA's   :17

MODA

## [1] ">1 mode"
## Registered S3 method overwritten by 'rmutil':
##   method         from
##   print.response httr
## [1] 55 56 62
## weight
##  39  43  44  45  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62 
##   1   1   1   2   4   1   1   7   3   7   8   8   9   9   6   4   8   4   4   9 
##  63  64  65  66  67  68  69  70  71  73  74  75  76  77  78  79  80  81  82  83 
##   6   8   6   6   2   6   7   4   5   2   2   4   6   1   3   3   3   2   3   3 
##  84  85  87  88  89  90  92  96  97 101 102 103 119 166 
##   2   2   1   4   1   2   1   2   1   1   1   1   1   1
## [1] 65.8
## [1] 63
## [1] "178"
## [1] 178
## height
##  57 148 150 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 
##   1   1   1   1   1   1   1   1   5   3   2   5   6   8  11   7  11  10   7   6 
## 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 
##  11   8   5   5   9   5   8   5   5  12   4   5   2   4   6   4   4   1   2   1 
## 189 191 197 
##   2   2   1
## [1] 170.02
## [1] 169.5

PREGUNTA 6. Dataset “Davis”: Comprueba gráficamente, para las variables numéricas, si existen potenciales outliers.

Detectar datos Outliers

Nos muestra la gráfica boxplot y nos entrega los cuales son los valores outliers de la variable “weight”

## 
## Attaching package: 'plotly'
## The following objects are masked from 'package:plyr':
## 
##     arrange, mutate, rename, summarise
## 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

## [1] 166 119 103

Con esta grafica nos muestra por sexo, la distintas distribuciones de los datos de la variable y los datos outliers que hay entre los datos.

PREGUNTA 7.- Comprueba si las variables numéricas siguen una distribución normal.

Histograma

Comprobar la Normalidad Quantile-Quantile (Q-Q) Plot