Let’s load the Mosaic package:
require(mosaic)
Let’s define the cdf and plot it:
# We define the function and then set L=0.44
f <- makeFun(1 - exp(-L*x) ~ x, L=0.44)
# Plot the function
plotFun(1 - exp(-L*x) ~ x, L=0.44, x.lim=range(0,11))
We can do this in a couple ways. Since we already have the CDF defined, we can simply plug in the endpoints:
# P(X<3)
f(x=3)-f(x=0)
## [1] 0.7329
# P(2<x<8)
f(x=8)-f(x=2)
## [1] 0.3852
To get the last one, P(X>3), we can do either of the following:
# P(X>3) from 3 to infinity
f(x=Inf)-f(x=3)
## [1] 0.2671
# The complement of P(X<3)
1-(f(x=3)-f(x=0))
## [1] 0.2671
pexp(q, rate = 1, lower.tail = TRUE, log.p = FALSE)
Let’s find P(X<3) using pexp():
pexp(3, rate=0.44, lower.tail=TRUE, log.p=FALSE)
## [1] 0.7329
We can find the other probabilities just as easily:
# P(2<x<8)
pexp(8, rate=0.44, lower.tail=TRUE, log.p=FALSE) -
pexp(2, rate=0.44, lower.tail=TRUE, log.p=FALSE)
## [1] 0.3852
# P(X>3) using lower.tail=FALSE
pexp(3, rate=0.44, lower.tail=FALSE, log.p=FALSE)
## [1] 0.2671
Let’s use the built-in exponential distribution function:
# P(x>20) with lambda = 1/10
pexp(20, rate=1/10, lower.tail=FALSE, log.p=FALSE)
## [1] 0.1353
# Plot this distribution and shade-in the probability
x=seq(0,40,length=150)
y=dexp(x,rate=1/10)
plot(x,y,type="l",lwd=2,col="steelblue",ylab="p")
x=seq(20,40,length=150)
y=dexp(x,rate=1/10)
polygon(c(20,x,40),c(0,y,0),col="lightgray")
# P(x<30) with lambda = 1/26
pexp(30, rate=1/26, lower.tail=TRUE, log.p=FALSE)
## [1] 0.6846
# Plot this distribution and shade-in the probability
x=seq(0,60,length=150)
y=dexp(x,rate=1/26)
plot(x,y,type="l",lwd=2,col="steelblue",ylab="p")
x=seq(0,30,length=150)
y=dexp(x,rate=1/26)
polygon(c(0,x,30),c(0,y,0),col="lightgray")