]> Creatis software - CreaPhase.git/blob - octave_packages/statistics-1.1.3/jsupdf.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / statistics-1.1.3 / jsupdf.m
1 ## Copyright (C) 2006 Frederick (Rick) A Niles <niles@rickniles.com>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {} jsupdf (@var{x}, @var{alpha1}, @var{alpha2})
18 ## For each element of @var{x}, compute the probability density function
19 ## (PDF) at @var{x} of the Johnson SU distribution with shape parameters @var{alpha1}
20 ## and @var{alpha2}.
21 ##
22 ## Default values are @var{alpha1} = 1, @var{alpha2} = 1.
23 ## @end deftypefn
24
25 ## Author: Frederick (Rick) A Niles <niles@rickniles.com>
26 ## Description: PDF of Johnson SU distribution
27
28 ## This function is derived from normpdf.m
29
30 ## This is the TeX equation of this function:
31 ##
32 ## \[ f(x) = \frac{\alpha_2}{\sqrt{x^2+1}} \phi\left(\alpha_1+\alpha_2
33 ## \log{\left(x+\sqrt{x^2+1}\right)}\right) \]
34 ##
35 ## where \[ -\infty < x < \infty ; \alpha_2 > 0 \] and $\phi$ is the
36 ## standard normal probability distribution function.  $\alpha_1$ and
37 ## $\alpha_2$ are shape parameters.
38
39 function pdf = jsupdf (x, alpha1, alpha2)
40
41   if (nargin != 1 && nargin != 3)
42     print_usage;
43   endif
44
45   if (nargin == 1)
46     alpha1 = 1;
47     alpha2 = 1;
48   endif
49
50   if (!isscalar (alpha1) || !isscalar(alpha2))
51     [retval, x, alpha1, alpha2] = common_size (x, alpha1, alpha2);
52     if (retval > 0)
53       error ("normpdf: x, alpha1 and alpha2 must be of common size or scalars");
54     endif
55   endif
56
57   one = ones(size(x));
58   sr = sqrt(x.*x + one);
59   pdf = (alpha2 ./ sr) .* stdnormal_pdf (alpha1 .* one +
60                                          alpha2 .* log (x + sr));
61
62 endfunction