Skip to content

Commit

Permalink
Add PDF and CDF of exponential RV
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaakshat committed Oct 21, 2021
1 parent 8afad09 commit d85ba28
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ch04.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)


0 comments on commit d85ba28

Please sign in to comment.