| prob_solve {exams.forge} | R Documentation |
Total or Conditional Probability Computation
Description
The following functions are available:
-
prob_solvegiven a set of events it computes the total or conditional probability of the given event orNAif no solution could be found. For the naming of the events upper case letters must be used and the available operators are!(complementary event),|(conditional event), and^(intersection of events). The attributelatexof the return value contains the necessary computation steps for computation of the given event. IfgetprobisTRUEthen additionally the attributeprob, a vector with all computed probabilities, andcompute, which includes all computational steps, are generated. -
printshows the solution way in ASCII. -
toLatexshows the solution way in LaTeX/MathJax with analignenvironment. -
lprobconverts!Ato\\bar{A}andA^BtoA \\cap B.
Usage
prob_solve(target, ...)
## Default S3 method:
prob_solve(target, ..., partition = NULL, getprob = FALSE, quiet = TRUE)
lprob(txt)
## S3 method for class 'prob_solve'
toLatex(object, ...)
## S3 method for class 'prob_solve'
print(x, type = c("numeric", "latex", "prob", "compute"), ...)
latex_prob(txt)
probability_solution(target, ...)
sprob(target, ...)
Arguments
target |
character: target event |
... |
numeric: named events with given probabilities |
partition |
character or list: set of events which form a partition |
getprob |
logical: return all computed probabilities and used computation steps (default: |
quiet |
logical: show all computation steps (default: |
txt |
character: vector to convert |
object, x |
|
type |
character: what to print, either |
Details
The program applies iteratively the following rules to find a solution:
-
P(A) = 1-P(!A), -
P(A|B) = 1-P(!A|B), -
P(A^B) = P(B^A), -
P(B) = P(A^B)+P(!A^B), -
P(A|B) = P(A^B)/P(B), and -
P(A) = P(A|P1)+P(A|P2)+...+ P(A|Pn)for a partitionP1, P2, ..., Pn.
Value
An object of the class prob_solve with the resulting probability, including the steps for computing.
If NA is returned then no solution could be found.
Examples
prob_solve("!A", "A"=0.3)
prob_solve("!A|B", "A|B"=0.3)
prob_solve("B^A", "A^B"=0.3)
# P(B) = P(A^B)+P(!A^B)
prob_solve("B", "A^B"=0.3, "!A^B"= 0.4)
prob_solve("A^B", "B"=0.7, "!A^B"= 0.4)
prob_solve("!A^B", "B"=0.7, "A^B"= 0.3)
# P(A|B) = P(A^B)/P(B)
prob_solve("A|B", "A^B"=0.3, "B"= 0.6)
prob_solve("A^B", "B"=0.6, "A|B"= 0.5)
prob_solve("B", "A|B"=0.5, "A^B"= 0.3)
#' latex, prob and compute attributes
pmt <- prob_solve("M|T", "M"=0.6, "T|M"=0.75, "T|!M"=0.39, quiet=FALSE, getprob=TRUE)
toLatex(pmt)
attr(pmt, "latex")
pmt <- prob_solve("M|T", "M"=0.6, "T|M"=0.75, "T|!M"=0.39, quiet=FALSE, getprob=TRUE)
attr(pmt, "prob")
print(pmt, "latex")
print(pmt, "prob") # only if getprob=TRUE
print(pmt, "compute") # only if getprob=TRUE
# bayes theorem and total probability
prob_solve("Z", "Z|A"=0.1, "Z|B"=0.2, "Z|C"=0.3, partition=c("A", "B", "C"))
prob_solve("Z|A", "Z"=0.6, "Z|B"=0.2, "Z|C"=0.3, partition=c("A", "B", "C"))
prob_solve('A|K', "A"=0.55, "B"=0.35, "C"=0.1, "K|A"=0.4, "K|B"=0.1, "K|C"=0.1,
partition=c("A", "B", "C"))
prob_solve('K', "A"=0.55, "B"=0.35, "C"=0.1, "K|A"=0.4, "K|B"=0.1, "K|C"=0.1,
partition=c("A", "B", "C"))