pmf method

  1. @override
double pmf(
  1. int k
)
override

Probability mass function (PMF) tells probability of specific event.

Example

In this example, we use Frequencies.

import 'package:calc/calc.dart';

void main() {
  // Two cats and two other animals
  final frequencies = Frequencies<String>.from([
    'dog',
    'cat',
    'rabbit',
    'cat',
  ]);

  final catPmf = frequencies.pmf('cat'); // --> 0.5
  print('Likelihood of cats based on the seen data: $catPmf');
}

Implementation

@override
double pmf(int k) {
  if (k > n) {
    return 0.0;
  }
  return binomialCoefficient(n, k).toDouble() * pow(p, k) * pow(1 - p, n - k);
}