tdis_d.m

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

M
46
字号
% PURPOSE: demo of Student t-distribution functions
%          prints mean and variance of 1000 draws
%          plots pdf,cdf,inverse
% 
%---------------------------------------------------
% USAGE: tdis_d
%---------------------------------------------------

n = 1000;
a = 10;


tic;
tst = tdis_rnd(n,a);
toc;

% mean should equal 0 for large a
fprintf('mean should   = %16.8f \n',0);
fprintf('mean of draws = %16.8f \n',mean(tst));

% variance should equal (1/(a-2))*a;
fprintf('variance should   = %16.8f \n',(1/(a-2))*a);
fprintf('variance of draws = %16.8f \n',std(tst)*std(tst));


tst = unif_rnd(n,-3,3);
tsort = sort(tst);

pdf = tdis_pdf(tsort,a);
plot(tsort,pdf);
title('T pdf with a=10');
pause;

cdf = tdis_cdf(tsort,a);
plot(tsort,cdf);
title('T cdf with a=10');
pause;

tst = rand(n,1);
tsort = sort(tst);

x = tdis_inv(tsort,a);
plot(tsort,x);
title('T quantiles with a=10');

⌨️ 快捷键说明

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