diff --git a/ch04.r b/ch04.r index fd93c98..98c4c9d 100644 --- a/ch04.r +++ b/ch04.r @@ -57,3 +57,29 @@ V = unifstat(a, b)$var a = 0; b = 1; F = punif(0.3, a, b) - punif(0.2, a, b) + +## PDF and CDF of an exponential random variable + +# R code to plot the exponential PDF +lambda1 = 1/2 +lambda2 = 1/5 +x = seq(0, 1, (0+1)/1000) +f1 = dexp(x, 1/lambda1) +f2 = dexp(x, 1/lambda2) +plot(x, f2, type="n") +lines(x, f1, lwd=4, col="blue") +lines(x, f2, lwd=4, col="red") +legend(0, 1, legend=c(expression(paste(lambda, "=5")), expression(paste(lambda, "=2"))), col=c("red", "blue"), lty=1:1) + +# R code to plot the exponential CDF +lambda1 = 1/2 +lambda2 = 1/5 +x = seq(0, 1, (0+1)/1000) +F1 = pexp(x, 1/lambda1) +F2 = pexp(x, 1/lambda2) +plot(x, F2, type="n") +lines(x, F1, lwd=4, col="blue") +lines(x, F2, lwd=4, col="red") +legend(0, 1, legend=c(expression(paste(lambda, "=5")), expression(paste(lambda, "=2"))), col=c("red", "blue"), lty=1:1) + +