qbinom.m

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

M
31
字号
function  k = qbinom(pr,n,p)%QBINOM  The binomial inverse cdf%%        k = qbinom(pr,n,p)%       Anders Holtsberg, 16-03-95%       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(p)]) > 1   error('Sorry, this is not implemented');endif any(pr(:)>1) | any(pr(:)<0)   error('A probability should be 0<=p<=1, please!')endkk = (0:n)';cdf = max(0,min(1,cumsum(dbinom(kk,n,p))));cdf(n+1) = 1;[pp,J] = sort(pr(:));np = length(pp);[S,I] = sort([pp;cdf]);I = find(I<=np) - (1:np)'; J(J) = (1:np)';pr(:) = I(J);k = pr;

⌨️ 快捷键说明

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