?? to_liked.m
字號:
function like = to_liked(b,y,x);% PURPOSE: evaluate tobit log-likelihood% to demonstrate optimization routines%-----------------------------------------------------% USAGE: like = to_liked(b,y,x) % where: b = parameter vector (k x 1)% y = dependent variable vector (n x 1)% x = explanatory variables matrix (n x m)%-----------------------------------------------------% NOTE: this function returns a scalar equal to the% negative of the log likelihood function% or a scalar sum of the vector depending% on the value of the flag argument% k ~= m because we may have additional parameters% in addition to the m bhat's (e.g. sigma)%-----------------------------------------------------% error checkif nargin ~= 3,error('wrong # of arguments to to_like1'); end;[m1 m2] = size(b);if m1 == 1 b = b';end; h = .000001; % avoid sigma = 0 [m junk] = size(b); beta = b(1:m-1); % pull out bhat sigma = max([b(m) h]); % pull out sigma xb = x*beta; llf1 = -(y-xb).^2./(2*sigma) - .5*log(2*pi*sigma); xbs = xb./sqrt(sigma); cdf = .5*(1+erf(xbs./sqrt(2))); llf2 = log(h+(1-cdf)); llf = (y > 0).*llf1 + (y <= 0).*llf2; like = -sum(llf); % scalar result
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -