From: D. G. <de...@gl...> - 2002-09-18 20:24:38
|
hello i would like to contribute to the statistics repository, this GPLed norminv.m, which (with the aid of normal_inv.m), completelty replicates matlab's norminv.m. I have tested every possible case (there are lots of easy-to-miss possibilities, will go into details if you like). I am not on the mailing-list yet, so please Cc me on any follow-up. # Copyright (C) 1995, 1996, 1997 Kurt Hornik, ## Copyright (C) 2002 Elliott Wave International, Inc. ## Author(s): Deepak Goel, Kurt Hornik. ## This file is derived from (and also calls) normal_niv.m, and hence ## GPLed. This function seeks to mirror matlab's norminv.m, so that ## one ## can run Kanzler's bdssig.m tests. ## 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 2, 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 file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} normal_inv (@var{x}, @var{m}, ## @var{sig}) ## For each element of @var{x}, compute the quantile (the inverse of ## the ## CDF) at @var{x} of the normal distribution with mean @var{m} and ## variance @var{sig}. ## ## Default values are @var{m} = 0, @var{sig} = 1. ## @end deftypefn ## Author: KH <Kur...@ci...> ## Description: Quantile function of the normal distribution function inv = norminv (x, m, sig) if (! ((nargin == 1) || (nargin == 2) || (nargin == 3))) usage ("normal_inv (x, m, sig)"); endif if (nargin == 2) sig = 1; endif if (nargin == 1) m = 0; sig = 1; endif numrows= rows (sig); numcols = columns(sig); var=sig.^2; ## If var was negative or 0, that's an absurdity, so matlab returns ## NaN.. So, make sig absurd (-1) in that case.. for i=1:numrows for j=1:numcols if (sig(i,j) <= 0); var(i,j) = -1; endif end end ### if (sig <= 0) ### inv = NaN; ### elseif ### inv = normal_inv (x, m, sig.^2); ### endif inv = normal_inv (x, m, var); endfunction |