The probability that a single continuous random variable lies in an interval [55,100]

Viewed 136

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.

3 Answers

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

The density function is a little grainy but you can solve it easily by first defining a vector x, which ranges from 0 to 100 and then conditionally computing the score as a function of x and p.

Just set the score to 0 by default and replace the values for which certain conditions apply by the function given in the assignment:

x = seq(0,100,.1)

p = 0.5

score = rep(0,length(x))
score[80*p<x & x <= (80*p+10)]=x[80*p<x & x <= (80*p+10)]/100-4*p/5
score[(80*p + 10)<x & x <= (80*p+20)]=-x[(80*p + 10)<x & x <= (80*p+20)]/100+4*p/5+1/5

You now have a density function that you can plot:

plot(x,score,type="l")

enter image description here

The probability that a score is 55 or higher is the area under the curve after 55, divided by the total are under the curve. Luckily, the area under the curve may be obtained by summing up the values:

prob55 = sum(score[x>=55])/sum(score)
prob55

In this case, the result is 12.5%

Although Onyambu's solution is correct, I think it's better written as follows:

f <- function(x,p = 0.5){
  dplyr::case_when(
    #         Condition        --------      Function
    (80*p) < x      & x <= (80*p + 10) ~ x/100 - 4*p/5,
    (80*p + 10) < x & x <= (80*p + 20) ~ -x/100 + 4*p/5 + 1/5,
    TRUE                               ~ 0
  )
}

The reasons being:

  • It's easier to read
  • Doesn't require the reader to know how coercion works.
  • It's more scalable: doesn't get worse as the number of regions increases.
Related