I have been asked to find the probability that a student passes the exam (which he does if the score is 55 ≤ X ≤ 100) and have been given a density function (see pic:
I have defined my limits and integrated over the density function which can be seen in the following code chunk in R
f1 <- function(x){
-(x/100)+(4*0.5/5)+(1/5)
}
integrate(f1,(80*p-25),(80*p+20))
I have inserted 0.5 instead of p when I define f1. I get the answer 27,76% if the student has not prepared very well (p=0.5)
I am doubting if this is done correctly, I have only used the second expression of f(x) without regards to the first, and when I type in the solution in an online integral calculator, I get a much lower value. Also, I'm not sure if the expressions of the limits, a and b, are defined correctly. I guess I would like to know how to derive the probability from a density function that has multiple expressions and what to do with those limits.
This can be done as shown below:
p <- function(x, p = 0.5){
i <- (80*p) < x & x <= (80*p + 10)
j <- (80*p + 10) < x & x <= (80*p + 20)
(x/100 - 4*p/5)^i * (-x/100 + 4*p/5 + 1/5)^j * 0^(1-i-j)
}
integrate(p, 55, 100)
0.1249993 with absolute error < 5.4e-05
You could also define p
as:
p1 <- function(x, p = 0.5){
i <- (80*p) < x & x <= (80*p + 10)
j <- (80*p + 10) < x & x <= (80*p + 20)
(x/100 - 4*p/5) * i + (-x/100 + 4*p/5 + 1/5) * j + 0 * (1-i-j)
}
integrate(p1, 55, 100)
0.1249993 with absolute error < 5.4e-05