###############################################################################
### EJERCICIO 5.53 - Distribución de Poisson (λ = 5)
###############################################################################
# SOLUCIÓN NUMÉRICA
lambda_53 <- 5
prob_mas_5 <- 1 - ppois(5, lambda_53)
prob_ninguna <- dpois(0, lambda_53)
cat("EJERCICIO 5.53 - SOLUCIÓN:\n")
## EJERCICIO 5.53 - SOLUCIÓN:
cat("a) P(X > 5) =", round(prob_mas_5, 4), "\n")
## a) P(X > 5) = 0.384
cat("b) P(X = 0) =", round(prob_ninguna, 4), "\n\n")
## b) P(X = 0) = 0.0067
# GRÁFICA
library(ggplot2)
x_vals_53 <- 0:15
probabilidades_53 <- dpois(x_vals_53, lambda_53)
datos_53 <- data.frame(x = x_vals_53, y = probabilidades_53)
ggplot(datos_53, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos_53, x > 5), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_53, x == 0), aes(x, y),
fill = "darkgreen", width = 0.7, stat = "identity") +
labs(title = "Distribucion Poisson (lambda = 5) - Ejercicio 5.53",
subtitle = paste("P(X > 5) =", round(prob_mas_5, 4),
"| P(X = 0) =", round(prob_ninguna, 4)),
x = "Numero de solicitudes por dia",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = x_vals_53) +
theme(plot.title = element_text(hjust = 0.5))

###############################################################################
### EJERCICIO 5.56 - Distribución de Poisson (λ = 3)
###############################################################################
# SOLUCIÓN NUMÉRICA
lambda_56 <- 3
prob_exactamente_5 <- dpois(5, lambda_56)
prob_menos_3 <- ppois(2, lambda_56)
prob_al_menos_2 <- 1 - ppois(1, lambda_56)
cat("EJERCICIO 5.56 - SOLUCIÓN:\n")
## EJERCICIO 5.56 - SOLUCIÓN:
cat("a) P(X = 5) =", round(prob_exactamente_5, 4), "\n")
## a) P(X = 5) = 0.1008
cat("b) P(X < 3) =", round(prob_menos_3, 4), "\n")
## b) P(X < 3) = 0.4232
cat("c) P(X >= 2) =", round(prob_al_menos_2, 4), "\n\n")
## c) P(X >= 2) = 0.8009
# GRÁFICA
x_vals_56 <- 0:10
probabilidades_56 <- dpois(x_vals_56, lambda_56)
datos_56 <- data.frame(x = x_vals_56, y = probabilidades_56)
ggplot(datos_56, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos_56, x == 5), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_56, x <= 2), aes(x, y),
fill = "orange", alpha = 0.7, width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_56, x >= 2), aes(x, y),
fill = "green", alpha = 0.5, width = 0.7, stat = "identity") +
labs(title = "Distribucion Poisson (lambda = 3) - Ejercicio 5.56",
subtitle = paste("P(X=5) =", round(prob_exactamente_5, 4),
"| P(X<3) =", round(prob_menos_3, 4),
"| P(X>=2) =", round(prob_al_menos_2, 4)),
x = "Accidentes por mes",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = x_vals_56) +
theme(plot.title = element_text(hjust = 0.5))

###############################################################################
### EJERCICIO 5.57 - Distribución de Poisson (λ = 2)
###############################################################################
# SOLUCIÓN NUMÉRICA
lambda_57 <- 2
prob_4_o_mas <- 1 - ppois(3, lambda_57)
prob_ningun_error <- dpois(0, lambda_57)
cat("EJERCICIO 5.57 - SOLUCIÓN:\n")
## EJERCICIO 5.57 - SOLUCIÓN:
cat("a) P(X >= 4) =", round(prob_4_o_mas, 4), "\n")
## a) P(X >= 4) = 0.1429
cat("b) P(X = 0) =", round(prob_ningun_error, 4), "\n\n")
## b) P(X = 0) = 0.1353
# GRÁFICA
x_vals_57 <- 0:10
probabilidades_57 <- dpois(x_vals_57, lambda_57)
datos_57 <- data.frame(x = x_vals_57, y = probabilidades_57)
ggplot(datos_57, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos_57, x >= 4), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_57, x == 0), aes(x, y),
fill = "darkgreen", width = 0.7, stat = "identity") +
labs(title = "Distribucion Poisson (lambda = 2) - Ejercicio 5.57",
subtitle = paste("P(X>=4) =", round(prob_4_o_mas, 4),
"| P(X=0) =", round(prob_ningun_error, 4)),
x = "Errores por pagina",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = x_vals_57) +
theme(plot.title = element_text(hjust = 0.5))

###############################################################################
### EJERCICIO 5.58 - Distribución de Poisson (λ = 6)
###############################################################################
# SOLUCIÓN NUMÉRICA
lambda_58 <- 6
prob_menos_4 <- ppois(3, lambda_58)
prob_entre_6_8 <- ppois(8, lambda_58) - ppois(5, lambda_58)
cat("EJERCICIO 5.58 - SOLUCIÓN:\n")
## EJERCICIO 5.58 - SOLUCIÓN:
cat("a) P(X < 4) =", round(prob_menos_4, 4), "\n")
## a) P(X < 4) = 0.1512
cat("b) P(6 <= X <= 8) =", round(prob_entre_6_8, 4), "\n\n")
## b) P(6 <= X <= 8) = 0.4016
# GRÁFICA
x_vals_58 <- 0:15
probabilidades_58 <- dpois(x_vals_58, lambda_58)
datos_58 <- data.frame(x = x_vals_58, y = probabilidades_58)
ggplot(datos_58, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos_58, x <= 3), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_58, x >= 6 & x <= 8), aes(x, y),
fill = "darkgreen", width = 0.7, stat = "identity") +
labs(title = "Distribucion Poisson (lambda = 6) - Ejercicio 5.58",
subtitle = paste("P(X<4) =", round(prob_menos_4, 4),
"| P(6<=X<=8) =", round(prob_entre_6_8, 4)),
x = "Huracanes por año",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = x_vals_58) +
theme(plot.title = element_text(hjust = 0.5))

###############################################################################
### EJERCICIO 5.5 - Distribución Binomial (n = 20, p = 0.3)
###############################################################################
# SOLUCIÓN NUMÉRICA
n_5 <- 20
p_5 <- 0.3
prob_al_menos_10 <- 1 - pbinom(9, n_5, p_5)
prob_no_mas_4 <- pbinom(4, n_5, p_5)
cat("EJERCICIO 5.5 - SOLUCIÓN:\n")
## EJERCICIO 5.5 - SOLUCIÓN:
cat("a) P(X >= 10) =", round(prob_al_menos_10, 4), "\n")
## a) P(X >= 10) = 0.048
cat("b) P(X <= 4) =", round(prob_no_mas_4, 4), "\n\n")
## b) P(X <= 4) = 0.2375
# GRÁFICA
x_vals_5 <- 0:20
probabilidades_5 <- dbinom(x_vals_5, n_5, p_5)
datos_5 <- data.frame(x = x_vals_5, y = probabilidades_5)
ggplot(datos_5, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos_5, x >= 10), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_5, x <= 4), aes(x, y),
fill = "darkgreen", width = 0.7, stat = "identity") +
labs(title = "Distribucion Binomial (n=20, p=0.3) - Ejercicio 5.5",
subtitle = paste("P(X>=10) =", round(prob_al_menos_10, 4),
"| P(X<=4) =", round(prob_no_mas_4, 4)),
x = "Fallas por error del operador",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = seq(0, 20, 2)) +
theme(plot.title = element_text(hjust = 0.5))

###############################################################################
### EJERCICIO 5.7 - Distribución Binomial (p = 0.7)
###############################################################################
# SOLUCIÓN NUMÉRICA
p_7 <- 0.7
# Para n = 10
n1_7 <- 10
prob_menos_mitad_10 <- pbinom(4, n1_7, p_7)
# Para n = 20
n2_7 <- 20
prob_menos_mitad_20 <- pbinom(9, n2_7, p_7)
cat("EJERCICIO 5.7 - SOLUCIÓN:\n")
## EJERCICIO 5.7 - SOLUCIÓN:
cat("a) Para n=10, P(X < 5) =", round(prob_menos_mitad_10, 4), "\n")
## a) Para n=10, P(X < 5) = 0.0473
cat("b) Para n=20, P(X < 10) =", round(prob_menos_mitad_20, 4), "\n\n")
## b) Para n=20, P(X < 10) = 0.0171
# GRÁFICA para n=10
x_vals1_7 <- 0:n1_7
probabilidades1_7 <- dbinom(x_vals1_7, n1_7, p_7)
datos1_7 <- data.frame(x = x_vals1_7, y = probabilidades1_7)
ggplot(datos1_7, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos1_7, x <= 4), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
labs(title = "Distribucion Binomial (n=10, p=0.7) - Ejercicio 5.7a",
subtitle = paste("P(X < 5) =", round(prob_menos_mitad_10, 4)),
x = "Fumadores empedernidos",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = x_vals1_7) +
theme(plot.title = element_text(hjust = 0.5))

# GRÁFICA para n=20
x_vals2_7 <- 0:n2_7
probabilidades2_7 <- dbinom(x_vals2_7, n2_7, p_7)
datos2_7 <- data.frame(x = x_vals2_7, y = probabilidades2_7)
ggplot(datos2_7, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos2_7, x <= 9), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
labs(title = "Distribucion Binomial (n=20, p=0.7) - Ejercicio 5.7b",
subtitle = paste("P(X < 10) =", round(prob_menos_mitad_20, 4)),
x = "Fumadores empedernidos",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = seq(0, 20, 2)) +
theme(plot.title = element_text(hjust = 0.5))

###############################################################################
### EJERCICIO 5.8 - Distribución Binomial (n = 8, p = 0.6)
###############################################################################
# SOLUCIÓN NUMÉRICA
n_8 <- 8
p_8 <- 0.6
prob_exactamente_3 <- dbinom(3, n_8, p_8)
prob_al_menos_5_no_psico <- 1 - pbinom(4, n_8, 0.4) # p = 0.4 para no psicológicos
cat("EJERCICIO 5.8 - SOLUCIÓN:\n")
## EJERCICIO 5.8 - SOLUCIÓN:
cat("a) P(X = 3) =", round(prob_exactamente_3, 4), "\n")
## a) P(X = 3) = 0.1239
cat("b) P(X >= 5) para problemas no psicológicos =", round(prob_al_menos_5_no_psico, 4), "\n\n")
## b) P(X >= 5) para problemas no psicológicos = 0.1737
# GRÁFICA
x_vals_8 <- 0:n_8
probabilidades_8 <- dbinom(x_vals_8, n_8, p_8)
datos_8 <- data.frame(x = x_vals_8, y = probabilidades_8)
ggplot(datos_8, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos_8, x == 3), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
labs(title = "Distribucion Binomial (n=8, p=0.6) - Ejercicio 5.8",
subtitle = paste("P(X = 3) =", round(prob_exactamente_3, 4)),
x = "Consumidores por problemas psicologicos",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = x_vals_8) +
theme(plot.title = element_text(hjust = 0.5))

###############################################################################
### EJERCICIO 5.9 - Distribución Binomial (n = 15, p = 0.25)
###############################################################################
# SOLUCIÓN NUMÉRICA
n_9 <- 15
p_9 <- 0.25
prob_3_a_6 <- pbinom(6, n_9, p_9) - pbinom(2, n_9, p_9)
prob_menos_4 <- pbinom(3, n_9, p_9)
prob_mas_5 <- 1 - pbinom(5, n_9, p_9)
cat("EJERCICIO 5.9 - SOLUCIÓN:\n")
## EJERCICIO 5.9 - SOLUCIÓN:
cat("a) P(3 <= X <= 6) =", round(prob_3_a_6, 4), "\n")
## a) P(3 <= X <= 6) = 0.7073
cat("b) P(X < 4) =", round(prob_menos_4, 4), "\n")
## b) P(X < 4) = 0.4613
cat("c) P(X > 5) =", round(prob_mas_5, 4), "\n\n")
## c) P(X > 5) = 0.1484
# GRÁFICA
x_vals_9 <- 0:n_9
probabilidades_9 <- dbinom(x_vals_9, n_9, p_9)
datos_9 <- data.frame(x = x_vals_9, y = probabilidades_9)
ggplot(datos_9, aes(x, y)) +
geom_bar(stat = "identity", fill = "lightblue", width = 0.7) +
geom_bar(data = subset(datos_9, x >= 3 & x <= 6), aes(x, y),
fill = "red", width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_9, x <= 3), aes(x, y),
fill = "orange", alpha = 0.7, width = 0.7, stat = "identity") +
geom_bar(data = subset(datos_9, x > 5), aes(x, y),
fill = "green", alpha = 0.7, width = 0.7, stat = "identity") +
labs(title = "Distribucion Binomial (n=15, p=0.25) - Ejercicio 5.9",
subtitle = paste("P(3<=X<=6) =", round(prob_3_a_6, 4),
"| P(X<4) =", round(prob_menos_4, 4),
"| P(X>5) =", round(prob_mas_5, 4)),
x = "Camiones con ponchaduras",
y = "Probabilidad") +
theme_minimal() +
scale_x_continuous(breaks = seq(0, n_9, 2)) +
theme(plot.title = element_text(hjust = 0.5))
