Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 1 / 37
Modelos de probabilidad
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 2 / 37
Modelos de probabilidad
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 3 / 37
Distribución Exponencial
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 4 / 37
Distribución Exponencial
Ejemplo:
Si X ∼ Exp(ν = 3):
Calcule fX (1)
dexp(1,rate=3)
## [1] 0.1493612
Calcule P(X ≤ 1.5) = FX (1.5)
pexp(1.5,rate=3)
## [1] 0.988891
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 5 / 37
Distribución Exponencial
Ejemplo:
Si X ∼ Exp(ν = 3):
Si P(X ≤ k) = 0.5, obtenga el valor de k.
qexp(0.5,rate=3)
## [1] 0.2310491
Genere una muestra de tamaño n = 1000.
rexp(1000,rate=3)
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 7 / 37
Distribución Uniforme
Calcule fX (0)
dunif(0,min=-2,max=8)
## [1] 0.1
Calcule P(X ≤ 0) = FX (0)
punif(0,min=-2,max=8)
## [1] 0.2
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 8 / 37
Distribución Uniforme
Ejemplo: Si X ∼ Uniforme(a = −2, b = 8):
## [1] 1
Genere una muestra de tamaño n = 1000.
runif(1000,min=-2,max=8)
Si X ∼ Normal(µ, σ 2 ), x ∈ R, entonces:
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 10 / 37
Distribución Log-Normal
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 11 / 37
La distribución Gamma
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 12 / 37
La distribución Chi-cuadrado
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 13 / 37
Función curve()
Tal como vimos anteriormente, la función curve sirve para graficar una función con
respecto a x. Es por esto, que podemos graficar las funciones de densidad respecto
a x, de nuestras funciones de densidad contínuas con su respectiva densidad d_(x).
Un ejemplo, graficaremos la densidad de una variable aleatoria X que distribuye
Normal con µ = 550 y σ = 50, entre 400 y 700:
curve(dnorm(x, mean=550, sd=50), from=400, to=700) 0.008
0.006
dnorm(x, mean = 550, sd = 50)
0.004
0.002
0.000
Esta curva la podemos añadir sobre otro gráfico con el argumento add=TRUE.
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 14 / 37
Ejercicios
1 Simule 100 variables aleatorias provenientes de una distribución
exponencial con tasa 2. Grafique el histograma de densidad empírica
de la muestra junto con la curva de densidad teórica.
muestra <- rexp(100, rate = 2)
hist(muestra, freq=FALSE)
curve(dexp(x, rate = 2), from=0, to=3, lty=2, add=TRUE,
lwd=3, col="red")
Histogram of muestra
1.0
0.8
Density
0.6
0.4
0.2
0.0
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 16 / 37
Semilla
set.seed(1113)
x <- rnorm(10,mean=10,sd=2)
x
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 17 / 37
Distribución Hipergeométrica
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 18 / 37
Distribución Hipergeométrica
En R se define como una urna con m bolas blancas y n bolas negras. Se
realiza una extracción de tamaño k y x representa el número de bolas
blancas extraídas (ver la ayuda ?dhyper). En este caso:
N = m+n
n=k
Aquí el X : cantidad de bolas blancas que obtengo y X = 0, 1, ..., min(m,k).
Los comandos en R correspondientes a esta distribución son:
dhyper(x,m,n,k)
phyper(q,m,n,k)
qhyper(p,m,n,k)
rhyper(nn,m,n,k) # Ojo: nn
m
La media teórica en este caso es E (X ) = k · p, con p = m+n y la varianza
teórica es Var (X ) = k · p · (1-p) · m+n-k
m+n-1 .
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 19 / 37
Medidas Descriptivas Teóricas y Empíricas
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 21 / 37
Medidas Descriptivas Teóricas vs Empíricas
## [1] 15
table(X)
## X
## 2 3 4 5 6 7 8 9 10 11
## 1 4 6 19 43 22 20 3 1 1
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 22 / 37
Medidas Descriptivas Teóricas vs Empíricas
round(prop.table(table(X)),3)
## X
## 2 3 4 5 6 7 8 9 10
## 0.008 0.033 0.050 0.158 0.358 0.183 0.167 0.025 0.008
## 11
## 0.008
proptable <- prop.table(table(X))
sum(proptable)
## [1] 1
La función prop.table(X) divide a la tabla por la suma total de ésta. Así
en este ejemplo sum(proptable) debe ser 1, obteniendo las probabilidades
empíricas.
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 23 / 37
Medidas Descriptivas Teóricas vs Empíricas
par(mai = c(1,1,0.1,0.1))
plot(proptable,xlim=c(0,maximo),col="orange",lwd=4)
x <- 0:maximo
axis(side=1,at=x)
# dhyper(x,m=m,n=n,k=k) # Probabilidades teóricas
# sum(dhyper(x,m=m,n=n,k=k))
points(x,dhyper(x,m=m,n=n,k=k),lwd=10,pch=16,col="darkblue")
proptable
0.00 0.20
0 2 4 6 8 10 12 14
X
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 24 / 37
Medidas Centrales
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 25 / 37
Medidas Centrales
## [1] 6.275
# Media teórica
p <- m/(m+n)
k*p
## [1] 6.375
Agregue estas lineas al gráfico
abline(v=mean(X),col="red",lty=2,lwd=2)
abline(v=k*p,col="darkgreen",lty=2,lwd=2)
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 26 / 37
Medidas Centrales
## [1] 6
# Moda teórica
x[which.max(dhyper(x,m=m,n=n,k=k))]
## [1] 6
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 27 / 37
Medidas Centrales
FX (Xmed ) = 0.5
# Mediana muestral
median(X)
## [1] 6
# Mediana teórica
qhyper(0.5,m=m,n=n,k=k)
## [1] 6
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 28 / 37
Esperanza matemática
La noción del valor esperado como un promedio ponderado puede ser
generalizado para funciones de la variable aleatoria X .
Dada una función g(x ), entonces el valor esperado de esta puede ser
obtenido como:
X
g(x ) · pX (x ), caso discreto
x ∈Θ
E (g(X )) = Z ∞X
g(x ) · fX (x )dx , caso contínuo
−∞
## [1] 41.50833
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 29 / 37
Medidas de Posición
Percentil: Valor en los reales, llamemos Xp , que es superior al p × 100% de
la información.
FX (xp ) = p
En R las siguientes funciones entregan percentiles empíricos.
"quantile": Percentil
"min": Mínimo
"max": Máximo
quantile(X,seq(from=0,to=1,by=0.1)) # Muestrales
qhyper(seq(from=0,to=1,by=0.1),m=m,n=n,k=k) # Teóricos
## 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
## 2 5 5 6 6 6 6 7 8 8 11
## [1] 0 4 5 6 6 6 7 7 8 8 15
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 30 / 37
Medidas de Dispersión
## [1] 2.15063
# Varianza teórica
k*p*(1-p)*(m+n-k)/(m+n-1)
## [1] 2.34976
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 31 / 37
Medidas de Dispersión
## [1] 1.466503
# Desviación estándar teórica
sqrt(k*p*(1-p)*(m+n-k)/(m+n-1))
## [1] 1.532893
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 32 / 37
Medidas de Dispersión
Rango: Max - Min
# Rango muestral
Rango <- function(X){ max(X)-min(X) }
Rango(X)
## [1] 9
range(X)
## [1] 2 11
range(X)[2]-range(X)[1]
## [1] 9
# Rango teórico
maximo-0
## [1] 15
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 33 / 37
Medidas de Dispersión
## 75%
## 1.25
# Rango intercuartíl teórico
qhyper(0.75,m=m,n=n,k=k)-qhyper(0.25,m=m,n=n,k=k)
## [1] 2
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 34 / 37
Medidas de Dispersión
En términos de dimensionalidad, es conveniente utilizar la desviación
estándar, es decir, q
σX = Var (X )
Ahora, si µX > 0, una medida adimensional de la variabilidad es el
coeficiente de variación (COV):
σX
δX =
µX
# Coeficiente de variación muestral
sd(X)/mean(X)
## [1] 0.2337056
# Coeficiente de variación teórico
sqrt(k*p*(1-p)*(m+n-k)/(m+n-1))/(k*p)
## [1] 0.2404537
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 35 / 37
Medidas de Asimetría y Forma
Se define una medida de asimetría (skewness) como al tercer momento
central:
P (xi −µX )3 ·pX (xi ), caso discreto
E [(X − µX )3 ] = i x ∈Θ
X
R ∞ (x −µX )3 ·fX (x )dx , caso contínuo
−∞
## [1] -0.001695663
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 36 / 37
Medidas de Asimetría y Forma
El cuarto momento central se conoce como la kurtosis:
P (xi −µX )4 ·pX (xi ), caso discreto
3
E [(X − µX ) ] = R ∞xi ∈ΘX
4
(x −µX ) ·fX (x )dx , caso contínuo
−∞
## [1] 0.7464909
Felipe Ossa y Pilar Tello Probabilidad y Estadística: Laboratorio 04 Segundo Semestre 2022 37 / 37