normrt_inv.m

来自「计量工具箱」· M 代码 · 共 37 行

M
37
字号
function result = normrt_inv(p,mu,sigma2,right)
% PURPOSE: compute inverse of cdf for right-truncated normal
%          distribution, p = prob(Y<y | mu,sigma2)
%          where: y is a realization of r.v. Y
% ------------------------------------------------------
% USAGE: y = normrt_inv(p,mu,sigma2,right)
% where: p = probability (scalar or vector)
%       mu = mean (scalar or vector)
%   sigma2 = variance (scalar or vector)
%    right = right truncation point (scalar)
% ------------------------------------------------------
% RETURNS: y = invp (a scalar or vector)
% ------------------------------------------------------

% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
% jpl@jpl.econ.utoledo.edu
    
if nargin ~= 4
error('normrt_inv: Wrong # of arguments');
end;


  crgt=norm_cdf(right,mu,sigma2);
  if length(p) == 1
  res=norm_inv(p*crgt,mu,sigma2);
  else
  res = norm_inv(p.*crgt,mu,sigma2);
  end;
  tR= (res > right);
  ok= (res <= right);
  res=res.*ok + right*tR;
result = res;

⌨️ 快捷键说明

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