Probabilidad en R
Enviado por Angela Ramirez • 15 de Septiembre de 2015 • Apuntes • 1.326 Palabras (6 Páginas) • 140 Visitas
# Simulación de datos de una distribución Binomial
# Generación de números aleatorios
rbinom(10,8,0.7)
#Gráfica función de densidad con n=10 y p=0.8
x <- 1:10
plot(x, dbinom(x, size=10, prob=0.8), xlab="Number of Successes",
ylab="Probability Mass", main="Binomial Distribution: Trials = 10, Probability of
success = 0.8", type="h")
points(x, dbinom(x, size=10, prob=0.8), pch=16)
abline(h=0, col="gray")
#Grafica función de distribución n=10 y p=0.8
x <- 1:10
pbinom(x, size=10, prob=0.8)
cbind(x, round(pbinom(x, size=10, prob=0.8), 4))
plot(x, pbinom(x, size=10, prob=0.8), type="p", pch=16)
x <- rep(x, rep(2, length(x)))
plot(x[-1], pbinom(x, size=10, prob=0.8)[-length(x)], xlab="Number of Successes",
ylab="Cumulative Probability", main="Binomial Distribution: Trials = 10, Probability
of success = 0.8", type="l")
abline(h=0, col=1, lty=2)
x <- 3:10
points(x, pbinom(x, size=10, prob=0.8), pch=16)
#Gráfica función de densidad con n=10 y p=0.5
x <- 0:10
plot(x, dbinom(x, size=10, prob=0.5), xlab="Number of Successes",
ylab="Probability Mass", main="Binomial Distribution: Trials = 10, Probability of
success = 0.5", type="h")
points(x, dbinom(x, size=10, prob=0.5), pch=16)
abline(h=0, col="gray")
#Grafica función de distribución n=10 y p=0.5
x <- 0:10
x <- rep(x, rep(2, length(x)))
plot(x[-1], pbinom(x, size=10, prob=0.5)[-length(x)], xlab="Number of Successes",
ylab="Cumulative Probability", main="Binomial Distribution: Trials = 10, Probability
of success = 0.5", type="l")
points(x, pbinom(x, size=10, prob=0.5), pch=16)
abline(h=0, col="gray")
#Gráfica función de densidad con n=20 y p=0.2
x <- 0:11
plot(x, dbinom(x, size=20, prob=0.2), xlab="Number of Successes",
ylab="Probability Mass", main="Binomial Distribution: Trials = 20, Probability of
success = 0.2", type="h")
points(x, dbinom(x, size=20, prob=0.2), pch=16)
abline(h=0, col="gray")
#Grafica función de distribución n=20 y p=0.2
x <- 0:11
x <- rep(x, rep(2, length(x)))
plot(x[-1], pbinom(x, size=20, prob=0.2)[-length(x)], xlab="Number of Successes",
ylab="Cumulative Probability", main="Binomial Distribution: Trials = 20, Probability
of success = 0.2", type="l")
abline(h=0, col="gray")
points(x, pbinom(x, size=20, prob=0.2), pch=16)
#####################################################
# Simulación de datos de una distribución Poisson #
#####################################################
#Generación de números aleatorios
rpois(5,2)
#Gráfica función de densidad media=2
x <- 0:8
plot(x, dpois(x, lambda=2), xlab="x", ylab="Probability Mass", main="Poisson
Distribution: Mean = 2", type="h")
points(x, dpois(x, lambda=2), pch=16)
abline(h=0, col="gray")
#Grafica función de distribución media=2
x <- 0:8
x <- rep(x, rep(2, length(x)))
plot(x[-1], ppois(x, lambda=2)[-length(x)], xlab="x", ylab="Probability Mass",
main="Poisson Distribution: Mean = 2", type="l")
abline(h=0, col="gray")
points(x, ppois(x, lambda=2), pch=16)
#Gráfica función de densidad media=4
x <- 0:8
plot(x, dpois(x, lambda=4), xlab="x", ylab="Probability Mass", main="Poisson
Distribution: Mean = 4", type="h")
points(x, dpois(x, lambda=4), pch=16)
abline(h=0, col="gray")
#Grafica función de distribución media=4
x <- 0:12
x <- rep(x, rep(2, length(x)))
plot(x[-1], ppois(x, lambda=4)[-length(x)], xlab="x", ylab="Probability Mass",
main="Poisson Distribution: Mean = 4", type="l")
abline(h=0, col="gray")
#Gráfica función de densidad media=10
x <- 2:22
plot(x, dpois(x, lambda=10), xlab="x", ylab="Probability Mass", main="Poisson
Distribution: Mean = 10", type="h")
points(x, dpois(x, lambda=10), pch=16)
abline(h=0, col="gray")
points(x, ppois(x, lambda=4), pch=16)
#Grafica función de distribución media=10
x <- 2:22
x <- rep(x, rep(2, length(x)))
plot(x[-1], ppois(x, lambda=10)[-length(x)], xlab="x", ylab="Probability Mass",
main="Poisson Distribution: Mean = 10", type="l")
abline(h=0, col="gray")
points(x, ppois(x, lambda=10), pch=16)
########################################################
# Simulación de datos de una distribución Geométrica #
########################################################
#Generación de números aleatorios
rgeom(10,0.5)
#Gráfica función de probabilidad p=0.5
x <- 0:10
plot(x, dgeom(x, prob=0.5), xlab="Number of Failures until Success",
ylab="Probability Mass", main="Geometric Distribution: Prob of success = 0.5",
type="h")
points(x, dgeom(x, prob=0.5), pch=16)
abline(h=0, col="gray")
#Grafica función de distribución p=0.5
x <- 0:10
x <- rep(x, rep(2, length(x)))
plot(x[-1], pgeom(x, prob=0.5)[-length(x)],
xlab="Number of Failures until Success", ylab="Cumulative Probability",
main="Geometric Distribution: Probability of success = 0.5", type="l")
abline(h=0, col="gray")
#Gráfica función de densidad p=0.95
x <- 0:2
plot(x, dgeom(x, prob=0.95), xlab="Number of Failures until Success",
...