prob_solve | R Documentation |
The following functions are available:
prob_solve
given a set of events it computes the total or conditional probability of the given event or
NA
if 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 attribute latex
of the return value contains the necessary computation steps for computation of the given event.
If getprob
is TRUE
then additionally the attribute prob
, a vector with all computed probabilities, and compute
,
which includes all computational steps, are generated.
print
shows the solution way in ASCII.
toLatex
shows the solution way in LaTeX/MathJax with an align
environment.
lprob
converts !A
to \\bar{A}
and A^B
to A \\cap B
.
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, ...)
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 |
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 partition P1, P2, ..., Pn
.
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.
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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.