Skip to content

Instantly share code, notes, and snippets.

@fernandomayer
Created February 8, 2019 20:17
Show Gist options
  • Save fernandomayer/547baa8cad07c09ed98f4665a4b58396 to your computer and use it in GitHub Desktop.
Save fernandomayer/547baa8cad07c09ed98f4665a4b58396 to your computer and use it in GitHub Desktop.
```{r expo, echo=FALSE, results='hide'}
na <- 5
explanations <- questions <- character(na)
solutions <- logical(na)
## Auxilar function to calculate exponencial probabilities
probexp <- function(alfa, a, b){
exp(-alfa * a) - exp(-alfa * b)
}
##----------------------------------------------------------------------
## Alternative 1
pexp(5, 0.1)
a1 <- round(probexp(0.1, 0, 5), 3)
r1 <- round(sample(c(a1, probexp(0.1, 0, 4)), size = 1), 3)
questions[1] <- paste0("$P(X < 5) = ", r1, "$")
solutions[1] <- a1 == r1
explanations[1] <- paste0("$P(X < 5) = ", a1, "$")
##----------------------------------------------------------------------
## Alternative 2
pexp(6, 0.1) - pexp(4, 0.1)
a2 <- round(probexp(0.1, 4, 6), 3)
r2 <- round(sample(c(a2, probexp(0.1, 4, 5)), size = 1), 3)
questions[2] <- paste0("$P(4 \\leq X < 6) = ", r2, "$")
solutions[2] <- a2 == r2
explanations[2] <- paste0("$P(4 \\leq X < 6) = ", a2, "$")
##----------------------------------------------------------------------
## Alternative 3
pexp(5, 0.1) - pexp(2, 0.1)
a3 <- round(probexp(0.1, 2, 5), 3)
r3 <- round(sample(c(a3, probexp(0.1, 3, 5)), size = 1), 3)
questions[3] <- paste0("$P(2 < X \\leq 5) = ", r3, "$")
solutions[3] <- a3 == r3
explanations[3] <- paste0("$P(2 < X \\leq 5) = ", a3, "$")
##----------------------------------------------------------------------
## Alternative 4
(pexp(7, 0.1) - pexp(2, 0.1))/(1 - pexp(2, 0.1))
a4 <- round(probexp(0.1, 2, 7)/(1 - probexp(0.1, 0, 2)), 3)
r4 <- round(sample(c(a4, probexp(0.1, 3, 7)/(1 - probexp(0.1, 0, 2))),
size = 1), 3)
questions[4] <- paste0("$P(X \\leq 7 \\, | \\, X > 2) = ", r4, "$")
solutions[4] <- a4 == r4
explanations[4] <-
paste0("$P(X \\leq 7 \\, | \\, X > 2) = \\frac{P(X \\leq 7 \\cap X > 2)}{P(X > 2)} = \\frac{P(2 < X < 7)}{P(X > 2)} = \\frac{",
round(probexp(0.1, 2, 7),3), "}{",
round(1 - probexp(0.1, 0, 2),3), "} = ", a4, "$")
##----------------------------------------------------------------------
## Alternative 5
pexp(4, 0.1, lower.tail = FALSE)
a5 <- round(1 - probexp(0.1, 0, 4), 3)
r5 <- round(sample(c(a5, probexp(0.1, 0, 4)), size = 1), 3)
questions[5] <- paste0("$P(X \\geq 4) = ", r5, "$")
solutions[5] <- a5 == r5
explanations[5] <- paste0("$P(X \\geq 4) = ", a5, "$")
```
Question
========
Let $X \sim \text{Exp}(1/10)$. Select the correct alternative(s):
```{r questionlist, echo=FALSE, results='asis'}
answerlist(questions, markup='markdown')
```
Solution
========
```{r solutionslist, echo=FALSE, results='asis'}
answerlist(ifelse(solutions, 'True', 'False'), explanations, markup='markdown')
```
Meta-information
================
exname: Probabilities from the exponential distribution
extype: mchoice
exsolution: `r mchoice2string(solutions)`
exshuffle: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment