1
$\begingroup$

I have F = 1x44100 vector in Matlab. Based on how this was calculated, we have predicted that this fits the F-distribution with 16 degrees of freedom for both numerator and denominator.

I am really really new to doing anything with distributions, the first thing I am trying to do is

f = fcdf(F,16,16) and

f1 = fpdf(F,16,16) Now I am trying to visualise this so that I can see what it looks like and overlap it with the F distribution for the same number of degrees of freedom. For this I do:

x = 0:0.05:2 y = fpdf(x,16,16) figure; plot(x,y) But when I try to overlay this with the plot of f1 it gives me something very strange...

I am basically just trying to overlay the F-distribution of my data over the actual distribution... Once I verify that my data does follow the F-distribution (which it should) then I need to look at the corresponding values for 2.5% and do a significance test to threshold my data.

I am very confused and I am not even sure if what I'm doing is right... Can anyone help please? Or have advice for something better?

$\endgroup$

2 Answers 2

1
$\begingroup$

I think you are slightly confused about what will you actually plot. When you visualise your data to compare them against a theoretical distribution you want to have some sort of empirical estimate for your data to begin with. A standard thing to consider is a kernel density estimate (KDE); you can get those using the function ksdensity in MATLAB. After you obtain the KDE of your data you then overlay the "real" probability density function (PDF) estimates above them. The later can be given by simple evaluating the PDF over the space spanned by your sample; you can use the function pdf or fpdf in MATLAB to get those. At first instance because the F-distribution is continuous you can use as standard Kolmogorov-Smirnov to test if your data come from an F-distribution. Please see the following code for a quick example.

(Note: For the Kolmogorov-Smirnov test I just did a quick two sample comparison (kstest2). MATLAB allows you to define a distribution object (in this case a F-distribution) using makedist if you want to used the one-sample K-S test (kstest) against a non-normal distribution; you can ask about the use of that particular MATLAB functionality in StackOverflow, as it is purely a programming question.)

% Set the seed to have some reproducibility
rng(1234); 
F = random('f',16,16, [210^2, 1]);  % Generate data from your distribution
ksdensity(F, 'support', 'positive'); % Plot KDE (defining positive support)
hold on                            
x = linspace(min(F), max(F), 1000); % Define the support of your theoretical plot
plot(x, pdf('f',x, 16,16), 'r' ); % Plot the "real" PDF 

enter image description here

[h,p] = kstest2(F, random('f',16,16, [2^12,1]) )
% h = 0  % Fails to rejects the null hypothesis at default alpha = 0.05
% p = 0.694370575893602
[h,p] = kstest2(F, random('t',1, 2^12,1])) 
% h = 1  % Succeeds to rejects the null hypothesis at default alpha = 0.05
% p = 0
$\endgroup$
3
  • $\begingroup$ Thanks for the detailed explanation! I think its clearer now... I didn't understand the kernel density estimator before so I wasn't using that... or more I didn't really understand how to use it. I have one question though... F = random('f',16,16, [210^2, 1]); in this line you have generated a sample from the f-distribution... But I already have an array that I think follows the F-distribution, say K2. Then do I just skip this and say ksdensity(K2, 'support', 'positive'); ? When I do that the KDE and theoretical PDF are not the same/aligned as they are in your plot... $\endgroup$ Commented May 10, 2015 at 11:24
  • $\begingroup$ I think this was happening because I didn't specify with ksdensity that I wanted to plot the PDF thats why it didn't turn out right. I just plotted the CDF of my data's KDE against theoretical CDF of f-distribution spanning the same x space and its turned out decent. Thanks! $\endgroup$ Commented May 10, 2015 at 13:15
  • $\begingroup$ I am glad I could help. Yes, you can skip that line. I just did that for illustration purposes. :) $\endgroup$
    – usεr11852
    Commented May 10, 2015 at 17:13
0
$\begingroup$

You're better off using MATLAB's histogram function or histcounts function. You can plug your matrix F into the function, and it will get you histogram edges and counts. Next, you'll calculate the theoretical values for these edges based on F-distribution. Then you simply draw two histograms.

If you want to make it in Monte Carlo style, then simply generate 44100 values from your theoretical F-distribution into another array F1, then call histogram on both tables using hold on in between to overlay the charts.

$\endgroup$
1
  • $\begingroup$ For some reason when I try to use histogram it says Undefined function 'histogram' for input arguments of type 'double' $\endgroup$ Commented May 10, 2015 at 11:37

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.