7017
|
1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 Kurt Hornik |
5410
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
5410
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
5410
|
18 |
|
19 ## -*- texinfo -*- |
5411
|
20 ## @deftypefn {Function File} {} tpdf (@var{x}, @var{n}) |
5410
|
21 ## For each element of @var{x}, compute the probability density function |
|
22 ## (PDF) at @var{x} of the @var{t} (Student) distribution with @var{n} |
|
23 ## degrees of freedom. |
|
24 ## @end deftypefn |
|
25 |
5428
|
26 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410
|
27 ## Description: PDF of the t distribution |
|
28 |
5411
|
29 function pdf = tpdf (x, n) |
5410
|
30 |
|
31 if (nargin != 2) |
6046
|
32 print_usage (); |
5410
|
33 endif |
|
34 |
|
35 if (!isscalar (n)) |
|
36 [retval, x, n] = common_size (x, n); |
|
37 if (retval > 0) |
5411
|
38 error ("tpdf: x and n must be of common size or scalar"); |
5410
|
39 endif |
|
40 endif |
|
41 |
|
42 pdf = zeros (size (x)); |
|
43 |
|
44 k = find (isnan (x) | !(n > 0) | !(n < Inf)); |
|
45 if (any (k)) |
|
46 pdf(k) = NaN; |
|
47 endif |
|
48 |
|
49 k = find (!isinf (x) & !isnan (x) & (n > 0) & (n < Inf)); |
|
50 if (any (k)) |
|
51 if (isscalar (n)) |
|
52 pdf(k) = (exp (- (n + 1) .* log (1 + x(k) .^ 2 ./ n)/2) |
|
53 / (sqrt (n) * beta (n/2, 1/2))); |
|
54 else |
|
55 pdf(k) = (exp (- (n(k) + 1) .* log (1 + x(k) .^ 2 ./ n(k))/2) |
|
56 ./ (sqrt (n(k)) .* beta (n(k)/2, 1/2))); |
|
57 endif |
|
58 endif |
|
59 |
|
60 endfunction |