Realizar cálculos de probabilida bajo la distribución Normal
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(mosaic)
## Warning: package 'mosaic' was built under R version 3.6.3
## Loading required package: lattice
## Loading required package: ggformula
## Warning: package 'ggformula' was built under R version 3.6.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.6.3
## Loading required package: ggstance
## Warning: package 'ggstance' was built under R version 3.6.3
##
## Attaching package: 'ggstance'
## The following objects are masked from 'package:ggplot2':
##
## geom_errorbarh, GeomErrorbarh
##
## New to ggformula? Try the tutorials:
## learnr::run_tutorial("introduction", package = "ggformula")
## learnr::run_tutorial("refining", package = "ggformula")
## Loading required package: mosaicData
## Warning: package 'mosaicData' was built under R version 3.6.3
## Loading required package: Matrix
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## The 'mosaic' package masks several functions from core packages in order to add
## additional features. The original behavior of these functions should not be affected by this.
##
## Note: If you use the Matrix package, be sure to load it BEFORE loading mosaic.
##
## Have you tried the ggformula package for your plots?
##
## Attaching package: 'mosaic'
## The following object is masked from 'package:Matrix':
##
## mean
## The following object is masked from 'package:ggplot2':
##
## stat
## The following objects are masked from 'package:dplyr':
##
## count, do, tally
## The following objects are masked from 'package:stats':
##
## binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
## quantile, sd, t.test, var
## The following objects are masked from 'package:base':
##
## max, mean, min, prod, range, sample, sum
library(readr)
library(ggplot2)
library(knitr)
datos <- read.table("https://raw.githubusercontent.com/rpizarrog/probabilidad-y-estad-stica/master/datos/body.dat.txt", quote="\"", comment.char="")
colnames(datos)[23:25] <- c("peso", "estatura", "genero")
kable(head(datos))
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 | V12 | V13 | V14 | V15 | V16 | V17 | V18 | V19 | V20 | V21 | V22 | peso | estatura | genero |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 42.9 | 26.0 | 31.5 | 17.7 | 28.0 | 13.1 | 10.4 | 18.8 | 14.1 | 106.2 | 89.5 | 71.5 | 74.5 | 93.5 | 51.5 | 32.5 | 26.0 | 34.5 | 36.5 | 23.5 | 16.5 | 21 | 65.6 | 174.0 | 1 |
| 43.7 | 28.5 | 33.5 | 16.9 | 30.8 | 14.0 | 11.8 | 20.6 | 15.1 | 110.5 | 97.0 | 79.0 | 86.5 | 94.8 | 51.5 | 34.4 | 28.0 | 36.5 | 37.5 | 24.5 | 17.0 | 23 | 71.8 | 175.3 | 1 |
| 40.1 | 28.2 | 33.3 | 20.9 | 31.7 | 13.9 | 10.9 | 19.7 | 14.1 | 115.1 | 97.5 | 83.2 | 82.9 | 95.0 | 57.3 | 33.4 | 28.8 | 37.0 | 37.3 | 21.9 | 16.9 | 28 | 80.7 | 193.5 | 1 |
| 44.3 | 29.9 | 34.0 | 18.4 | 28.2 | 13.9 | 11.2 | 20.9 | 15.0 | 104.5 | 97.0 | 77.8 | 78.8 | 94.0 | 53.0 | 31.0 | 26.2 | 37.0 | 34.8 | 23.0 | 16.6 | 23 | 72.6 | 186.5 | 1 |
| 42.5 | 29.9 | 34.0 | 21.5 | 29.4 | 15.2 | 11.6 | 20.7 | 14.9 | 107.5 | 97.5 | 80.0 | 82.5 | 98.5 | 55.4 | 32.0 | 28.4 | 37.7 | 38.6 | 24.4 | 18.0 | 22 | 78.8 | 187.2 | 1 |
| 43.3 | 27.0 | 31.5 | 19.6 | 31.3 | 14.0 | 11.5 | 18.8 | 13.9 | 119.8 | 99.9 | 82.5 | 80.1 | 95.3 | 57.5 | 33.0 | 28.0 | 36.6 | 36.1 | 23.5 | 16.9 | 21 | 74.8 | 181.5 | 1 |
datos$genero <- as.factor(datos$genero)
summary(datos)
## V1 V2 V3 V4
## Min. :32.40 Min. :18.70 Min. :24.70 Min. :14.30
## 1st Qu.:36.20 1st Qu.:26.50 1st Qu.:30.60 1st Qu.:17.30
## Median :38.70 Median :28.00 Median :32.00 Median :19.00
## Mean :38.81 Mean :27.83 Mean :31.98 Mean :19.23
## 3rd Qu.:41.15 3rd Qu.:29.25 3rd Qu.:33.35 3rd Qu.:20.90
## Max. :47.40 Max. :34.70 Max. :38.00 Max. :27.50
## V5 V6 V7 V8
## Min. :22.20 Min. : 9.90 Min. : 8.10 Min. :15.70
## 1st Qu.:25.65 1st Qu.:12.40 1st Qu.: 9.80 1st Qu.:17.90
## Median :27.80 Median :13.30 Median :10.50 Median :18.70
## Mean :27.97 Mean :13.39 Mean :10.54 Mean :18.81
## 3rd Qu.:29.95 3rd Qu.:14.40 3rd Qu.:11.20 3rd Qu.:19.60
## Max. :35.60 Max. :16.70 Max. :13.30 Max. :24.30
## V9 V10 V11 V12
## Min. : 9.90 Min. : 85.90 Min. : 72.60 Min. : 57.90
## 1st Qu.:13.00 1st Qu.: 99.45 1st Qu.: 85.30 1st Qu.: 68.00
## Median :13.80 Median :108.20 Median : 91.60 Median : 75.80
## Mean :13.86 Mean :108.20 Mean : 93.33 Mean : 76.98
## 3rd Qu.:14.80 3rd Qu.:116.55 3rd Qu.:101.15 3rd Qu.: 84.50
## Max. :17.20 Max. :134.80 Max. :118.70 Max. :113.20
## V13 V14 V15 V16
## Min. : 64.00 Min. : 78.80 Min. :46.30 Min. :22.40
## 1st Qu.: 78.85 1st Qu.: 92.00 1st Qu.:53.70 1st Qu.:27.60
## Median : 84.60 Median : 96.00 Median :56.30 Median :31.00
## Mean : 85.65 Mean : 96.68 Mean :56.86 Mean :31.17
## 3rd Qu.: 91.60 3rd Qu.:101.00 3rd Qu.:59.50 3rd Qu.:34.45
## Max. :121.10 Max. :128.30 Max. :75.70 Max. :42.40
## V17 V18 V19 V20 V21
## Min. :19.60 Min. :29.00 Min. :28.40 Min. :16.40 Min. :13.0
## 1st Qu.:23.60 1st Qu.:34.40 1st Qu.:34.10 1st Qu.:21.00 1st Qu.:15.0
## Median :25.80 Median :36.00 Median :36.00 Median :22.00 Median :16.1
## Mean :25.94 Mean :36.20 Mean :36.08 Mean :22.16 Mean :16.1
## 3rd Qu.:28.40 3rd Qu.:37.95 3rd Qu.:38.00 3rd Qu.:23.30 3rd Qu.:17.1
## Max. :32.50 Max. :49.00 Max. :47.70 Max. :29.30 Max. :19.6
## V22 peso estatura genero
## Min. :18.00 Min. : 42.00 Min. :147.2 0:260
## 1st Qu.:23.00 1st Qu.: 58.40 1st Qu.:163.8 1:247
## Median :27.00 Median : 68.20 Median :170.3
## Mean :30.18 Mean : 69.15 Mean :171.1
## 3rd Qu.:36.00 3rd Qu.: 78.85 3rd Qu.:177.8
## Max. :67.00 Max. :116.40 Max. :198.1
ggplot(datos, aes(genero, peso)) +
geom_boxplot(colour = c("deeppink", "dodgerblue4"))
ggplot(datos, aes(genero, estatura)) +
geom_boxplot(colour = c("deeppink", "dodgerblue4"))
masculinos <- filter(datos, genero == 1)
summary(masculinos)
## V1 V2 V3 V4
## Min. :34.10 Min. :19.40 Min. :27.50 Min. :14.40
## 1st Qu.:40.00 1st Qu.:26.80 1st Qu.:31.40 1st Qu.:19.35
## Median :41.20 Median :28.00 Median :32.40 Median :20.60
## Mean :41.24 Mean :28.09 Mean :32.53 Mean :20.81
## 3rd Qu.:42.60 3rd Qu.:29.45 3rd Qu.:33.80 3rd Qu.:22.10
## Max. :47.40 Max. :34.70 Max. :38.00 Max. :27.50
## V5 V6 V7 V8
## Min. :24.70 Min. :12.40 Min. : 9.80 Min. :16.90
## 1st Qu.:28.65 1st Qu.:13.80 1st Qu.:10.80 1st Qu.:18.80
## Median :29.90 Median :14.40 Median :11.20 Median :19.50
## Mean :29.95 Mean :14.46 Mean :11.25 Mean :19.56
## 3rd Qu.:31.40 3rd Qu.:15.10 3rd Qu.:11.65 3rd Qu.:20.40
## Max. :35.60 Max. :16.70 Max. :13.30 Max. :23.00
## V9 V10 V11 V12
## Min. :12.30 Min. :100.2 Min. : 79.30 Min. : 67.10
## 1st Qu.:14.20 1st Qu.:112.2 1st Qu.: 95.95 1st Qu.: 77.90
## Median :14.80 Median :116.5 Median :101.00 Median : 83.40
## Mean :14.74 Mean :116.5 Mean :100.99 Mean : 84.53
## 3rd Qu.:15.30 3rd Qu.:121.0 3rd Qu.:106.05 3rd Qu.: 90.00
## Max. :17.20 Max. :134.8 Max. :118.70 Max. :113.20
## V13 V14 V15 V16
## Min. : 67.00 Min. : 81.50 Min. :46.80 Min. :25.6
## 1st Qu.: 81.55 1st Qu.: 93.25 1st Qu.:53.70 1st Qu.:32.5
## Median : 87.30 Median : 97.40 Median :56.00 Median :34.4
## Mean : 87.66 Mean : 97.76 Mean :56.50 Mean :34.4
## 3rd Qu.: 92.70 3rd Qu.:101.55 3rd Qu.:59.15 3rd Qu.:36.4
## Max. :111.80 Max. :118.70 Max. :70.00 Max. :42.4
## V17 V18 V19 V20
## Min. :22.70 Min. :31.10 Min. :28.90 Min. :16.40
## 1st Qu.:27.10 1st Qu.:35.75 1st Qu.:35.50 1st Qu.:22.00
## Median :28.40 Median :37.00 Median :37.30 Median :23.00
## Mean :28.24 Mean :37.20 Mean :37.21 Mean :23.16
## 3rd Qu.:29.40 3rd Qu.:38.45 3rd Qu.:38.95 3rd Qu.:24.30
## Max. :32.50 Max. :45.70 Max. :47.70 Max. :29.30
## V21 V22 peso estatura genero
## Min. :14.60 Min. :18.00 Min. : 53.90 Min. :157.2 0: 0
## 1st Qu.:16.50 1st Qu.:24.00 1st Qu.: 70.95 1st Qu.:172.9 1:247
## Median :17.10 Median :29.00 Median : 77.30 Median :177.8
## Mean :17.19 Mean :31.67 Mean : 78.14 Mean :177.7
## 3rd Qu.:17.85 3rd Qu.:37.00 3rd Qu.: 85.50 3rd Qu.:182.7
## Max. :19.60 Max. :65.00 Max. :116.40 Max. :198.1
femeninos <- filter(datos, genero == 0)
summary(femeninos)
## V1 V2 V3 V4 V5
## Min. :32.40 Min. :18.70 Min. :24.70 Min. :14.30 Min. :22.2
## 1st Qu.:35.17 1st Qu.:26.20 1st Qu.:30.00 1st Qu.:16.50 1st Qu.:24.9
## Median :36.40 Median :27.80 Median :31.50 Median :17.50 Median :25.9
## Mean :36.50 Mean :27.58 Mean :31.46 Mean :17.72 Mean :26.1
## 3rd Qu.:37.80 3rd Qu.:29.20 3rd Qu.:32.90 3rd Qu.:18.70 3rd Qu.:27.1
## Max. :42.60 Max. :33.30 Max. :37.80 Max. :26.80 Max. :33.2
## V6 V7 V8 V9
## Min. : 9.90 Min. : 8.100 Min. :15.7 Min. : 9.90
## 1st Qu.:11.80 1st Qu.: 9.400 1st Qu.:17.3 1st Qu.:12.40
## Median :12.40 Median : 9.800 Median :18.0 Median :13.00
## Mean :12.37 Mean : 9.874 Mean :18.1 Mean :13.03
## 3rd Qu.:12.90 3rd Qu.:10.400 3rd Qu.:18.7 3rd Qu.:13.72
## Max. :15.00 Max. :12.200 Max. :24.3 Max. :15.50
## V10 V11 V12 V13
## Min. : 85.9 Min. : 72.60 Min. : 57.90 Min. : 64.00
## 1st Qu.: 96.1 1st Qu.: 81.97 1st Qu.: 64.75 1st Qu.: 76.65
## Median : 99.5 Median : 85.50 Median : 68.30 Median : 82.35
## Mean :100.3 Mean : 86.06 Mean : 69.80 Mean : 83.75
## 3rd Qu.:103.9 3rd Qu.: 89.50 3rd Qu.: 72.75 3rd Qu.: 90.03
## Max. :129.5 Max. :109.00 Max. :101.50 Max. :121.10
## V14 V15 V16 V17
## Min. : 78.80 Min. :46.30 Min. :22.4 Min. :19.60
## 1st Qu.: 90.75 1st Qu.:53.77 1st Qu.:26.4 1st Qu.:22.68
## Median : 94.95 Median :56.40 Median :27.8 Median :23.60
## Mean : 95.65 Mean :57.20 Mean :28.1 Mean :23.76
## 3rd Qu.: 99.50 3rd Qu.:59.80 3rd Qu.:29.8 3rd Qu.:24.70
## Max. :128.30 Max. :75.70 Max. :40.3 Max. :30.80
## V18 V19 V20 V21
## Min. :29.00 Min. :28.40 Min. :17.40 Min. :13.00
## 1st Qu.:33.50 1st Qu.:33.10 1st Qu.:20.30 1st Qu.:14.50
## Median :35.00 Median :34.85 Median :21.10 Median :15.00
## Mean :35.26 Mean :35.01 Mean :21.21 Mean :15.06
## 3rd Qu.:36.80 3rd Qu.:36.60 3rd Qu.:22.00 3rd Qu.:15.60
## Max. :49.00 Max. :45.40 Max. :26.00 Max. :18.20
## V22 peso estatura genero
## Min. :18.00 Min. : 42.0 Min. :147.2 0:260
## 1st Qu.:22.00 1st Qu.: 54.5 1st Qu.:160.0 1: 0
## Median :26.00 Median : 59.0 Median :164.5
## Mean :28.77 Mean : 60.6 Mean :164.9
## 3rd Qu.:34.00 3rd Qu.: 65.6 3rd Qu.:169.5
## Max. :67.00 Max. :105.2 Max. :182.9
media.peso.m <- mean(masculinos$peso)
desv.std.peso.m <- sd(masculinos$peso)
media.peso.f <- mean(femeninos$peso)
desv.std.peso.f <- sd(femeninos$peso)
media.peso.m
## [1] 78.14453
desv.std.peso.m
## [1] 10.51289
media.peso.f
## [1] 60.60038
desv.std.peso.f
## [1] 9.615699
media.estatura.m <- mean(masculinos$estatura)
desv.std.estatura.m <- sd(masculinos$estatura)
media.estatura.f <- mean(femeninos$estatura)
desv.std.estatura.f <- sd(femeninos$estatura)
media.estatura.m
## [1] 177.7453
desv.std.estatura.m
## [1] 7.183629
media.estatura.f
## [1] 164.8723
desv.std.estatura.f
## [1] 6.544602
plotDist("norm", mean = media.peso.m, sd = desv.std.peso.m, groups = x > 60, type = "h", xlab = "Peso Hombres", ylab = "Densidad" )
pnorm(q = 60, mean = media.peso.m, sd = desv.std.peso.m, lower.tail = FALSE)
## [1] 0.9578202
1 - pnorm(q = 60, mean = media.peso.m, sd = desv.std.peso.m)
## [1] 0.9578202
plotDist("norm", mean = media.peso.m, sd = desv.std.peso.m, groups = x > 70, type = "h", xlab = "Peso Hombres", ylab = "Densidad" )
plotDist("norm", mean = media.peso.m, sd = desv.std.peso.m, groups = x < 80, type = "h", xlab = "Peso Hombres", ylab = "Densidad" )
pnorm(q = 70, mean = media.peso.m, sd = desv.std.peso.m, lower.tail = FALSE) - pnorm(q = 80, mean = media.peso.m, sd = desv.std.peso.m, lower.tail = FALSE)
## [1] 0.3507943
plotDist("norm", mean = media.peso.m, sd = desv.std.peso.m, groups = x < 75, type = "h", xlab = "Peso Hombres", ylab = "Densidad" )
pnorm(q = 75, mean = media.peso.f, sd = desv.std.peso.f, lower.tail = FALSE)
## [1] 0.06713016
-Se requieren los datos de femeninos -Visulizando la curva de campan
plotDist("norm", mean = media.peso.f, sd = desv.std.peso.f, groups = x > 55, type = "h", xlab = "Peso Mujeres", ylab = "Densidad" )
pnorm(q = 55, mean = media.peso.f, sd = desv.std.peso.f, lower.tail = FALSE)
## [1] 0.7198584
-Se requieren los datos de femeninos -Visulizando la curva de campana
plotDist("norm", mean = media.peso.m, sd = desv.std.peso.m, groups = x > 50, type = "h", xlab = "Peso Hombres", ylab = "Densidad" )
plotDist("norm", mean = media.peso.m, sd = desv.std.peso.m, groups = x < 60, type = "h", xlab = "Peso Hombres", ylab = "Densidad" )
pnorm(q = 50, mean = media.peso.m, sd = desv.std.peso.m, lower.tail = FALSE) - pnorm(q = 60, mean = media.peso.m, sd = desv.std.peso.m, lower.tail = FALSE)
## [1] 0.03846719
plotDist("norm", mean = media.peso.m, sd = desv.std.peso.m, groups = x < 45, type = "h", xlab = "Peso Hombres", ylab = "Densidad" )
pnorm(q = 45, mean = media.peso.f, sd = desv.std.peso.f, lower.tail = FALSE)
## [1] 0.9476397
plotDist("norm", mean = media.estatura.m, sd = desv.std.estatura.m, groups = x > 165, type = "h", xlab = "Estatura Hombres", ylab = "Densidad")
pnorm(q = 165, mean = media.estatura.m, sd = desv.std.estatura.m, lower.tail = FALSE)
## [1] 0.9619867
-Se requieren los datos de masculinos -Visulizando la curva de campana
plotDist("norm", mean = media.estatura.m, sd = desv.std.estatura.m, groups = x > 175, type = "h", xlab = "Estatura Hombres", ylab = "Densidad")
plotDist("norm", mean = media.estatura.m, sd = desv.std.estatura.m, groups = x < 185, type = "h", xlab = "Estatura Hombres", ylab = "Densidad")
pnorm(q = 175, mean = media.estatura.m, sd = desv.std.estatura.m, lower.tail = FALSE)- pnorm(q = 185, mean = media.estatura.m, sd = desv.std.estatura.m, lower.tail = FALSE)
## [1] 0.4925565
plotDist("norm", mean = media.estatura.m, sd = desv.std.estatura.m, groups = x > 170, type = "h", xlab = "Estatura Hombres", ylab = "Densidad")
pnorm(q = 170, mean = media.estatura.m, sd = desv.std.estatura.m, lower.tail = FALSE)
## [1] 0.8595264
plotDist("norm", mean = media.estatura.f, sd = desv.std.estatura.f, groups = x > 155, type = "h", xlab = "Estatura Mujeres", ylab = "Densidad")
pnorm(q = 155, mean =media.estatura.f, sd = desv.std.estatura.f, lower.tail = FALSE)
## [1] 0.9342823
plotDist("norm", mean = media.estatura.m, sd = desv.std.estatura.m, groups = x > 165, type = "h", xlab = "Estatura Hombres", ylab = "Densidad")
plotDist("norm", mean = media.estatura.m, sd = desv.std.estatura.m, groups = x < 170, type = "h", xlab = "Estatura Hombres", ylab = "Densidad")
pnorm(q = 155, mean = media.estatura.m, sd = desv.std.estatura.m, lower.tail = FALSE)- pnorm(q = 170, mean = media.estatura.m, sd = desv.std.estatura.m, lower.tail = FALSE)
## [1] 0.1397016
plotDist("norm", mean = media.estatura.m, sd = desv.std.estatura.m, groups = x > 155, type = "h", xlab = "Estatura Hombres", ylab = "Densidad")
pnorm(q = 155, mean = media.estatura.m, sd = desv.std.estatura.m, lower.tail = FALSE)
## [1] 0.999228