qhypg.m

来自「一个非常实用的统计工具箱」· M 代码 · 共 36 行

M
36
字号
function  k = qhypg(p,n,K,N)%QHYPGEO  The hypergeometric inverse cdf%%        k = qhypg(p,n,K,N)%%        Gives the smallest integer k so that P(X <= k) >= p.%       Anders Holtsberg, 18-11-93%       Copyright (c) Anders Holtsberg% The algorithm contains a nice vectorization trick which% relies on the fact that if two elements in a vector% are exactely the same then matlab's routine SORT sorts them% into the order they had. Do not change this, Mathworks!if max([length(n) length(K) length(N)]) > 1   error('Sorry, this is not implemented');endif any(any(abs(2*p-1)>1))   error('A probability should be 0<=p<=1, please!')endlowerlim = max(0,n-(N-K));upperlim = min(n,K);kk = (lowerlim:upperlim)';nk = length(kk);cdf = max(0,min(1,cumsum(dhypg(kk,n,K,N))));cdf(length(cdf)) = 1;[pp,j] = sort(p(:));np = length(pp);[S,i] = sort([pp;cdf]);i = find(i<=np) - (1:np)' + lowerlim; j(j) = (1:np)';p(:) = i(j);k = p;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?