EpiNow2 Stan Functions
Loading...
Searching...
No Matches

Functions for probability mass function handling. More...

+ Collaboration diagram for PMF Handlers:

Functions

vector discretised_pmf (vector params, int n, int dist)
 

Description

Functions for probability mass function handling.

Functions from pmfs.stan for handling and manipulating probability mass functions.

Function Documentation

◆ discretised_pmf()

vector discretised_pmf ( vector params,
int n,
int dist )

#include </github/workspace/inst/stan/functions/pmfs.stan>

Probability Mass Function (PMF) Utilities

This file contains functions for creating and manipulating probability mass functions, particularly for discretizing continuous distributions for use in delay modeling. Discretise a continuous distribution

This function discretizes continuous distributions (lognormal or gamma) to create a probability mass function over discrete time points (days). Adapted from https://github.com/epiforecasts/epinowcast (MIT License, copyright: epinowcast authors)

Parameters
paramsVector of distribution parameters ([mu, sigma] for lognormal or [shape, rate] for gamma)
nNumber of days to calculate PMF for
distDistribution type (0: lognormal, 1: gamma)
Returns
A vector of length n containing the discretized probability mass function

Definition at line 26 of file pmfs.stan.

26 {
27 vector[n] lpmf;
28 vector[n] upper_lcdf;
29 if (dist == 0) {
30 for (i in 1:n) {
31 upper_lcdf[i] = lognormal_lcdf(i | params[1], params[2]);
32 }
33 } else if (dist == 1) {
34 for (i in 1:n) {
35 upper_lcdf[i] = gamma_lcdf(i | params[1], params[2]);
36 }
37 } else {
38 reject("Unknown distribution function provided.");
39 }
40 // discretise
41 if (n > 1) {
42 lpmf[1] = upper_lcdf[1];
43 lpmf[2] = upper_lcdf[2];
44 if (n > 2) {
45 lpmf[3:n] = log_diff_exp(upper_lcdf[3:n], upper_lcdf[1:(n - 2)]);
46 }
47 // normalize
48 lpmf = lpmf - log_sum_exp(upper_lcdf[(n - 1):n]);
49 } else {
50 lpmf[1] = 0;
51 }
52 return(exp(lpmf));
53}

Referenced by get_delay_rev_pmf().

+ Here is the caller graph for this function: