Mercurial > octave-nkf
annotate scripts/statistics/distributions/tinv.m @ 10549:95c3e38098bf
Untabify .m scripts
author | Rik <code@nomad.inbox5.com> |
---|---|
date | Fri, 23 Apr 2010 11:28:50 -0700 |
parents | 16f53d29049f |
children | 1740012184f9 |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007, 2008, 2009 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} {} tinv (@var{x}, @var{n}) |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7737
diff
changeset
|
21 ## For each probability value @var{x}, compute the inverse of the |
7737
15d3a35b8ff1
updated help for tcdf and tinv
jstickel@jstickel-10631s.nrel.gov
parents:
7017
diff
changeset
|
22 ## cumulative distribution function (CDF) of the t (Student) |
15d3a35b8ff1
updated help for tcdf and tinv
jstickel@jstickel-10631s.nrel.gov
parents:
7017
diff
changeset
|
23 ## distribution with degrees of freedom @var{n}. This function is |
9069
634274aaa183
Cleanup documentation for stats.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## analogous to looking in a table for the t-value of a single-tailed |
7737
15d3a35b8ff1
updated help for tcdf and tinv
jstickel@jstickel-10631s.nrel.gov
parents:
7017
diff
changeset
|
25 ## distribution. |
5410 | 26 ## @end deftypefn |
27 | |
28 ## For very large n, the "correct" formula does not really work well, | |
29 ## and the quantiles of the standard normal distribution are used | |
30 ## directly. | |
31 | |
5428 | 32 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 33 ## Description: Quantile function of the t distribution |
34 | |
5411 | 35 function inv = tinv (x, n) |
5410 | 36 |
37 if (nargin != 2) | |
6046 | 38 print_usage (); |
5410 | 39 endif |
40 | |
41 if (!isscalar (n)) | |
42 [retval, x, n] = common_size (x, n); | |
43 if (retval > 0) | |
5411 | 44 error ("tinv: x and n must be of common size or scalar"); |
5410 | 45 endif |
46 endif | |
47 | |
48 inv = zeros (size (x)); | |
49 | |
50 k = find ((x < 0) | (x > 1) | isnan (x) | !(n > 0)); | |
51 if (any (k)) | |
52 inv(k) = NaN; | |
53 endif | |
54 | |
55 k = find ((x == 0) & (n > 0)); | |
56 if (any (k)) | |
57 inv(k) = -Inf; | |
58 endif | |
59 | |
60 k = find ((x == 1) & (n > 0)); | |
61 if (any (k)) | |
62 inv(k) = Inf; | |
63 endif | |
64 | |
65 k = find ((x > 0) & (x < 1) & (n > 0) & (n < 10000)); | |
66 if (any (k)) | |
67 if (isscalar (n)) | |
68 inv(k) = (sign (x(k) - 1/2) | |
10549 | 69 .* sqrt (n .* (1 ./ betainv (2*min (x(k), 1 - x(k)), |
70 n/2, 1/2) - 1))); | |
5410 | 71 else |
72 inv(k) = (sign (x(k) - 1/2) | |
10549 | 73 .* sqrt (n(k) .* (1 ./ betainv (2*min (x(k), 1 - x(k)), |
74 n(k)/2, 1/2) - 1))); | |
5410 | 75 endif |
76 endif | |
77 | |
78 ## For large n, use the quantiles of the standard normal | |
79 k = find ((x > 0) & (x < 1) & (n >= 10000)); | |
80 if (any (k)) | |
81 inv(k) = stdnormal_inv (x(k)); | |
82 endif | |
83 | |
84 endfunction |