PRÁCTICA FINAL DE ESTADÍSTICA

library(htmltab)
link= "https://es.wikipedia.org/wiki/%C3%8Dndice_global_de_felicidad"
linktab= "///div/table"
infelicidad= htmltab(doc = link, which = linktab)
str(infelicidad)
## 'data.frame':    156 obs. of  9 variables:
##  $ №                                     : chr  "1" "2" "3" "4" ...
##  $ País                                  : chr  "Finlandia" "Colombia" "Noruega" "Dinamarca" ...
##  $ Puntuación                            : chr  "7.633" "7.594" "7.560" "7.555" ...
##  $ PIB per cápita                        : chr  "1.305" "1.456" "1.372" "1.351" ...
##  $ Apoyo social                          : chr  "1.592" "1.582" "1.595" "1.590" ...
##  $ Esperanza de años de vida saludable   : chr  "0.874" "0.873" "0.870" "0.868" ...
##  $ Libertad para tomar decisiones vitales: chr  "0.681" "0.686" "0.685" "0.683" ...
##  $ Generosidad                           : chr  "0.192" "0.286" "0.285" "0.284" ...
##  $ Percepción de la corrupción           : chr  "0.393" "0.130" "0.410" "0.408" ...

Limpieza

library(readr)
infelicidad[,c(3:9)]=lapply(infelicidad[,c(3:9)], as.numeric)

ELIMINANDO ESPACIOS

library(stringr)
names(infelicidad)= str_split(names(infelicidad), " ", simplify = T)[,1]

COMPRUEBO…

str(infelicidad)
## 'data.frame':    156 obs. of  9 variables:
##  $ №          : chr  "1" "2" "3" "4" ...
##  $ País       : chr  "Finlandia" "Colombia" "Noruega" "Dinamarca" ...
##  $ Puntuación : num  7.63 7.59 7.56 7.55 7.5 ...
##  $ PIB        : num  1.3 1.46 1.37 1.35 1.34 ...
##  $ Apoyo      : num  1.59 1.58 1.59 1.59 1.64 ...
##  $ Esperanza  : num  0.874 0.873 0.87 0.868 0.914 0.927 0.878 0.896 0.876 0.913 ...
##  $ Libertad   : num  0.681 0.686 0.685 0.683 0.677 0.66 0.638 0.653 0.669 0.659 ...
##  $ Generosidad: num  0.192 0.286 0.285 0.284 0.353 0.256 0.333 0.321 0.365 0.285 ...
##  $ Percepción : num  0.393 0.13 0.41 0.408 0.138 0.357 0.295 0.291 0.389 0.383 ...

PREGUNTA 01 : La relación entre esperanza de años de vida saludable y percepcion de la corrupción es:

Primero : ¿Se comporta normal la variable? Respuesta en base al p-value:

library(dlookr)
## Loading required package: mice
## Loading required package: lattice
## 
## Attaching package: 'mice'
## The following objects are masked from 'package:base':
## 
##     cbind, rbind
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Registered S3 methods overwritten by 'car':
##   method                          from
##   influence.merMod                lme4
##   cooks.distance.influence.merMod lme4
##   dfbeta.influence.merMod         lme4
##   dfbetas.influence.merMod        lme4
## Warning in fun(libname, pkgname): couldn't connect to display ":0"
## 
## Attaching package: 'dlookr'
## The following object is masked from 'package:base':
## 
##     transform
normality(infelicidad[,c(6:9)])
## Warning: `cols` is now required.
## Please use `cols = c(statistic)`
## # A tibble: 4 x 4
##   vars        statistic  p_value sample
##   <chr>           <dbl>    <dbl>  <dbl>
## 1 Esperanza       0.954 5.15e- 5    156
## 2 Libertad        0.946 1.13e- 5    156
## 3 Generosidad     0.960 1.79e- 4    156
## 4 Percepción      0.814 8.49e-13    156
cor.test(infelicidad$Esperanza,infelicidad$Percepción, method = "spearman")
## Warning in cor.test.default(infelicidad$Esperanza, infelicidad
## $Percepción, : Cannot compute exact p-value with ties
## 
##  Spearman's rank correlation rho
## 
## data:  infelicidad$Esperanza and infelicidad$Percepción
## S = 497598, p-value = 0.007436
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.2135453

pregunta 02

no terminé, marqué para poder subir respuesta