FastPrepBayesian Posterior From Error Rates

Bayesian Posterior From Error Rates

Microsoft logoMicrosoft● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

A binary condition has prevalence priorPercent among the population. A test has a falsePositivePercent chance of returning positive when the condition is absent, and a falseNegativePercent chance of returning negative when the condition is present. A randomly selected person tests positive.

Compute the probability that the person has the condition given this positive result. Return that probability exactly as an integer array [numerator, denominator] in lowest terms, with a positive denominator. For example, a posterior of one half is [1,2]. All rates are integer percentages.

Function

posteriorAfterPositive(priorPercent: int, falsePositivePercent: int, falseNegativePercent: int) → int[]

Examples

Example 1

priorPercent = 1falsePositivePercent = 1falseNegativePercent = 0return = [100,199]

A rare condition with one percent false positives has a posterior just above one half after a positive result.

Example 2

priorPercent = 10falsePositivePercent = 5falseNegativePercent = 20return = [16,25]

Of the positive tests in a 10,000-person cohort, 800 are true positives and 450 are false positives.

Example 3

priorPercent = 50falsePositivePercent = 0falseNegativePercent = 25return = [1,1]

With no false positives, every observed positive comes from an affected person.

Constraints

  • 1 <= priorPercent <= 99.
  • 0 <= falsePositivePercent <= 100.
  • 0 <= falseNegativePercent <= 99.
  • The probability of a positive result is nonzero under these bounds.

More Microsoft problems

See Microsoft hiring insights
public int[] posteriorAfterPositive(int priorPercent, int falsePositivePercent, int falseNegativePercent) {
    // Return the exact reduced posterior fraction.
}
priorPercent1
falsePositivePercent1
falseNegativePercent0
expected[100,199]
Checking account…