Snippets

Atri Bhattacharya Confidence intervals for the mean of Poisson distribution

Created by Atri Bhattacharya last modified
## Copyright (C) 2019 Atri B.
##
## This program is free software: you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation, either version 3 of the
## License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {} [@var{lowlim}, @var{upplim}] = poisson_cl (@var{n}, @var{cl})
## For a given event @var{n}, compute the Poisson confidence limit interval
## corresponding to @var{cl} confidence level(s).
## 
## @var{cl} may be an array of multiple confidence levels.
##
## Returns lower limit (@var{lowlim}) and upper limit (@var{upplim}) as
## requested.
## @end deftypefn

## Author: Atri B <A.Bhattacharya@uliege.be>
## Description: Confidence intervals for the mean of Poisson distribution

# Reference: http://ms.mcmaster.ca/peter/s743/poissonalpha.html
function [lim_low, lim_up] = poisson_cl(num, cl)
  # Check if statistics pkg is loaded, otherwise load it
  if exist("chi2inv") != 2
    pkg load statistics
  endif
  
  q = (1 - cl) ./ 2.0;
  lim_low = ifelse(floor(num), chi2inv(q, 2 * floor(num)) ./ 2.0, 0.0);
  lim_up  = chi2inv(1.0 - q, 2 * floor(num) + 2) ./ 2.0;
endfunction

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.