Skip to content

Instantly share code, notes, and snippets.

@omarfsosa
Created February 4, 2021 21:54
Show Gist options
  • Save omarfsosa/6416ac11e8035b04a4fa334da290e6b3 to your computer and use it in GitHub Desktop.
Save omarfsosa/6416ac11e8035b04a4fa334da290e6b3 to your computer and use it in GitHub Desktop.
Modelling poisson data with selection bias.
functions {
real normalisation(real lam, int lb, int ub) {
real result = 0;
for (x in lb:ub) {
result += (lam^x)/tgamma(x+1);
}
result *= exp(-lam);
return result;
}
}
data {
int N;
int L;
int U;
int<lower=L, upper=U> y[N];
}
parameters {
real<lower=0> beta;
}
model {
for (val in y) {
target += poisson_lpmf(val | beta) - log(normalisation(beta, L, U));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment