4-7. Geometric Distribution
library(Rstat)
# success : p, Range of X
p <- c(0.1, 0.3, 0.5); x <- 1:200
len <- length(p)
# Compute the Probability : dgeom() uses the number of failure.
fx <- list()
for ( i in 1:len) fx[[i]] <- dgeom(x-1, p[i])
# Sum(P(X)) == 1 ?
sapply(fx, sum)
# E(X) and Var(X)
disc.mexp(x, fx, plot=F)
# Plotting
mt <- paste0("Geometric(", p, ")")
win.graph(9,3); par(mfrow=c(1,3)); par(mar=c(3,4,4,2))
for (k in 1:len) plot(1:50, fx[[k]][1:50], type="h", main=mt[k],
ylab="f(x)", xlab="", lwd=3, col=2)
Last updated