tobit_gd.m
来自「用于做统计分析的matlab 程序包,各种基本统计分析的函数都有」· M 代码 · 共 52 行
M
52 行
% PURPOSE: An example using tobit_g()
% Gibbs sampling tobit censored regression
%
%---------------------------------------------------
% USAGE: tobit_gd
%---------------------------------------------------
clear all;
% generate uncensored data
n=100; k = 2; sige = 5;
evec = randn(n,1)*sqrt(sige);
tt=1:n;
x = randn(n,k);
x(1:n,1) = ones(n,1);
b = ones(k,1);
b(2,1) = 2.0;
b(1,1) = 0.5;
y = x*b + evec;
% add a few outliers
y(50,1) = 15;
y(75,1) = 15;
yc = zeros(n,1);
% now censor the data
ind = find(y >= 0);
yc(ind,1) = y(ind,1);
if length(ind) == n
error('no censored observations -- try again');
end;
Vnames = strvcat('y','constant','x1');
res1 = ols(yc,x);
res2 = tobit(yc,x);
prior.rval = 40; % heteroscedastic prior
ndraw = 1100;
nomit = 100;
result = tobit_g(yc,x,ndraw,nomit,prior);
plot(tt,result.vmean);
title('vi-estimates');
prt(res1,Vnames);
prt(res2,Vnames);
prt(result,Vnames);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?