0
$\begingroup$

I have a sub-task of an assignment about the parametric bootstrap method. The subtask is to, given a students t-distribution with $5$ degrees of freedom, sample $10000$ draws using the fundamental theorem of simulation. The algorithm is:

Fundamental theorem of simulation

Then, I should produce a histogram of the simulated data and compare it to the exact pdf for the students t-distribution with $5$ degrees of freedom.

My plot "looks" like it has the same distribution but is seems as though it is not right somehow. I´ve inserted my code below for the algorithm, so feel free to comment if I´ve missed a crucial part or misunderstood something!

I guess the goal is to be able to use the histogram as approximation of the integral, but that doesn´t seem to work out for me.

I´ve tried to add more draws but that doesn´t seem to make the histogram any better at approximating the integral, it just adds more "bars" to the histogram. Is it just a scaling/normalizing problem in my code somehow or is there anything else I´m missing?

MATLAB CODE:

% Let X be the support of the tpdf, the support is thoeretically the set of
% all real numbers, for for this assignment, we let the support be the
% interval [a,b] as the absolute values of the y-values outside this interval gets very small.
a = -4;
b = 4;

% Plots the true tpdf to see where a possible max M is
X = linspace(a,b);
Y = tpdf(X,5);
plot(X,Y) % 0.4 will for as a max for the simulation
hold on

% max := M <= 0.4
M = 0.4;

% Number of draws
d = 10000;

% Matrix for storing accepted points under the curve
acc = NaN(d,1);

rng(1)
% We now want to sample d draws using the fundamental theorem of simulation
for k=1:d
    u1_star = unifrnd(a,b);
    f = tpdf(u1_star,5);
    u2_star = unifrnd(0.0,M);
    if (u2_star < f)
        acc(k,1) = u1_star;
    end
end

acc;
histogram(acc,"Normalization","pdf")

enter image description here

$\endgroup$
4
  • $\begingroup$ What are the bars intended to depict? They aren't a histogram, because their total area is approximately 0.1 (height) times 0.6 (base, approximately) times 1/2 (formula for a triangle), which is obviously far less than 1 as required by any valid histogram. $\endgroup$
    – whuber
    Commented Oct 21, 2021 at 21:32
  • $\begingroup$ I will edit the code or answer my own Q, I seem to have solved the issue! $\endgroup$
    – cittee
    Commented Oct 21, 2021 at 21:40
  • 1
    $\begingroup$ Also, how do you draw samples from a uniform distribution on the support of a Cauchy distribution? There doesn't exist such a thing. And more: what does any of this have to do with a parametric bootstrap? $\endgroup$
    – whuber
    Commented Oct 21, 2021 at 21:40
  • $\begingroup$ I don´t understand your first question. For the second one: It is just a sub-task to learn the method written above. In the next task, I will use this algorithm to produce bootstrap data. This specific problem had nothing specifically to do with the bootstrap method. I never claimed that either other than in the "tags". $\endgroup$
    – cittee
    Commented Oct 21, 2021 at 21:52

1 Answer 1

0
$\begingroup$

I have solved the issue I had. I substituted the for-loop with this code section below and it produced the histogram/integral-plot i wanted!

The problem was, I believe, that I did not have enough points e.i. 10000 "accepted" draws because the for-loop only did 10000 iterations and rejeted most of them and had mostly NaNs, but I wanted 10000 "accepted" draws, so I did the whole thing using a while-loop that keeps on iterating until the length of the vector acc is of the right length.

% We now want to sample d draws using the fundamental theorem of simulation
acc = NaN(1,1); % Creates a vector that we can concatenate with "accepted" draws with
% This while loop concatenates the d points with the NaN-vector to create a vector with accepted draws of length 10001
while length(acc) < d+1
    u1_star = unifrnd(a,b);
    f = tpdf(u1_star,5);
    u2_star = unifrnd(0.0,M);
    if (u2_star < f)
        acc = [acc u1_star];
    end
end

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.