📄 cmlparet.src
字号:
/*
** cmlparet.src CMLPareto - Constrained Pareto Regression Model for
** Duration Data (Censoring Optional)
**
** (C) Copyright 1994-1995 Aptech Systems, Inc.
** All Rights Reserved.
**
** This Software Product is PROPRIETARY SOURCE CODE OF APTECH
** SYSTEMS, INC. This File Header must accompany all files using
** any portion, in whole or in part, of this Source Code. In
** addition, the right to create such files is strictly limited by
** Section 2.A. of the GAUSS Applications License Agreement
** accompanying this Software Product.
**
** If you wish to distribute any portion of the proprietary Source
** Code, in whole or in part, you must first obtain written
** permission from Aptech Systems.
**
**-------------------**------------------**-------------------**-----------**
**-------------------**------------------**-------------------**-----------**
**
** FORMAT { bg,vc,llik } = cmlpareto(dataset,dep,ind);
**
** INPUT
**
** dataset = name of Gauss dataset or name of matrix in memory
** dep = dependent variable (duration) name or column number
** ind = vector of independent variable names or column numbers
**
** OUTPUT
**
** bg = vector of effect parameters that maximize the likelihood
** on top of parameter(s) corresponding to vind.
** PARAMETERIZATION: bg=b|g;
** E(Y) = exp(ind*b)
** V(Y) = E(Y)*(1+exp(g))
** vc = variance-covariance matrix of b
** llik = value of the log-likelihood at the maximum
**
** GLOBALSg
**
** _cmlc_Inference = CML for constrained maximum likelihood (default)
** = BOOT for bootstrapped estimates
** = BAYES for Bayesian inference
**
** _cmlc_Censor 0 = pareto model, no censoring (default).
** symbol = use this variable from dataset to censor. Code
** each row as 0 if censored or 1 if not.
** integer = use this column of input matrix to censor. Code
** each row as 0 if censored or 1 if not.
**
** _cmlc_Start choose method of calculating starting values.
** 0 = LS (default),
** 1 = set to vector stored in _cmlc_StartValues,
** 2 = rndu-0.5,
** 3 = zeros, or set to vector
**
** _cmlc_Dispersion starting value for scalar dispersion parameter.
** Default = 3.
**
** __output 1 = print output to screen (default),
** 0 = do not print to screen
**
** OTHER GLOBALS
**
** see CML
**
** EXAMPLE
** dep = { time };
** ind = { age, party, unem };
** dataset = "sample";
** call cmlpareto(dataset,dep,ind,0);
**
*/
#include cmlcount.ext
#include gauss.ext
#include cml.ext
proc _cmlc_svpar(dataset,dep,ind);
local res,b0,b1,b,pars;
if _cmlc_Dispersion == 3;
_cmlc_Dispersion = .5;
endif;
pars = 2;
if ind/=0;
pars = pars+rows(ind);
endif;
if _cmlc_start==0;
if ind==0;
b0 = 0;
else;
b0 = -clols(dataset,dep,ind);
endif;
res = b0|_cmlc_Dispersion;
elseif _cmlc_start==1;
b = _cmlc_startvalues;
res = b;
if rows(b)/=pars;
"b is the wrong size for _cmlc_start\g";
end;
endif;
elseif _cmlc_Start == 2;
res = rndu(pars,1) - 0.5;
elseif _cmlc_Start == 3;
res = zeros(pars,1);
else;
res = _cmlc_Start;
if rows(res) /= pars;
errorlog "\nERROR: Wrong number of rows in _cmlc_Start.\n";
end;
endif;
endif;
retp(res);
endp;
proc _cmlc_lipar(b,dta);
local y,n,x,ezg,xb,ps,res,resc,aa,exb,dd,z,g,bb;
y = dta[.,1];
n = rows(y);
x = ones(n,1);
if ((_cmlc_Censor /= 0) and (cols(dta) > 2));
x = x~dta[.,2:cols(dta)-1];
elseif (_cmlc_Censor == 0) and (cols(dta) > 1);
x = x~dta[.,2:cols(dta)];
endif;
dd = ones(n,1);
if _cmlc_Censor/=0;
dd = dta[.,cols(dta)];
endif;
z = 1; /* use for variance function */
g = trimr(b,cols(x),0);
b = trimr(b,0,1);
xb = x*b;
exb = exp(xb);
ezg = exp(g);
ps = exb./ezg;
aa = 1+(y./exb)./(1+2*ps);
if _cmlc_Censor/=0;
resc = ln(1-(aa^(-2-2*ps)));
else;
resc = 1;
endif;
res = ln(1+ps)-xb-ln(1+2*ps)-(3+2*ps).*ln(aa);
res = dd.*res+(1-dd).*resc;
retp(res);
endp;
proc 3 = cmlpareto(dataset,dep,ind);
local vars,b,logl,g,vc,se,parnames,st,ret;
_cml_CovPar = 3;
_cmlc_fn = dataset;
if dep $== 0;
errorlog "\nERROR: DEP must be variable name or number.\n";
end;
endif;
if type(dataset) /= 13;
if (maxc(ind) > cols(dataset)) or (dep > cols(dataset));
if not trapchk(4);
errorlog "\nERROR: If dataset is a matrix, DEP and IND "\
"must be column numbers of the input matrix.\n";
end;
endif;
retp(error(0),error(0),error(0));
endif;
endif;
if (type(dataset)==13) and (type(_cmlc_Censor)==13);
_cmlc_Censor = indcv(_cmlc_Censor,getname(dataset));
endif;
vars = dep;
if ind /= 0;
vars = vars|ind;
endif;
st = _cmlc_svpar(dataset,dep,ind);
if __title $== "";
if _cmlc_Censor/=0;
__title = "Censored ";
endif;
__title = __title$+"Pareto Regression Model of Duration Data";
endif;
if _cmlc_Censor/=0;
vars = vars|_cmlc_Censor;
endif;
local infm,inf0,lcInf;
infm = { CML, BOOT, BAYES };
inf0 = { 1, 2, 3 };
LcInf = _cml_check(_cmlc_Inference,1,infm,inf0,1);
if LcInf == 1;
{ b,logl,g,vc,ret } = cml(dataset,vars,&_cmlc_lipar,st);
elseif LcInf == 2;
{ b,logl,g,vc,ret } = cmlboot(dataset,vars,&_cmlc_lipar,st);
elseif LcInf == 3;
{ b,logl,g,vc,ret } = cmlbayes(dataset,vars,&_cmlc_lipar,st);
endif;
if ret /= 0;
errorlog "ERROR: Model estimation failed.";
end;
endif;
if type(dataset)==13;
vars = "beta0";
if ind/=0;
vars = vars|ind;
endif;
vars = vars|"gamma";
else;
vars = "beta0";
if ind/=0;
vars = vars|
((0 $+ "Col." $+ zeros(rows(ind),1))$+_cmlc_ftosm(ind,2));
endif;
vars = vars|"gamma";
endif;
_cmlc_vr = vars;
_cmlc_dp = dep;
ndpclex;
retp(b,vc,logl*_cml_NumObs);
endp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -