forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdis_rnd.m
36 lines (32 loc) · 945 Bytes
/
tdis_rnd.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function t = tdis_rnd (n,df)
% PURPOSE: returns random draws from the t(n) distribution
%---------------------------------------------------
% USAGE: rnd = tdis_rnd(n,df)
% where: n = size of vector
% df = a scalar dof parameter
% NOTE: mean=0, std=1
%---------------------------------------------------
% RETURNS:
% a vector of random draws from the t(n) distribution
% --------------------------------------------------
% SEE ALSO: tdis_cdf, tdis_rnd, tdis_pdf, tdis_prb
%---------------------------------------------------
% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
if nargin ~= 2
error('Wrong # of arguments to tdis_rnd');
end;
if is_scalar(df)
if (df<=0)
error('tdis_rnd dof is wrong');
end
z = randn(n,1);
x = chis_rnd(n,df);
t = (z*sqrt(df))./sqrt(x);
else
error('tdis_rnd: df must be a scalar');
end;