Matlab estimate PDF from random variable X

Click For Summary
SUMMARY

The discussion focuses on estimating the probability density function (PDF) of a random variable \(X\) defined as \(X = U_1 - U_2\), where \(U_i\) are uniform random variables generated using Matlab's unifrnd(-5, 5, 1000, 1). The participants clarify that the resulting distribution is a symmetric triangular distribution with support from -10 to 10, negating the need for estimation. For more advanced density estimation, suggestions include using Matlab's ksdensity function or exploring kernel density estimation techniques.

PREREQUISITES
  • Understanding of random variables and their distributions
  • Familiarity with Matlab programming and functions
  • Knowledge of uniform distribution properties
  • Basic concepts of probability density functions
NEXT STEPS
  • Explore Matlab's ksdensity for kernel density estimation
  • Study the properties of the symmetric triangular distribution
  • Learn about stochastic processes and their applications
  • Investigate advanced statistical methods for density estimation
USEFUL FOR

Matlab users, statisticians, data analysts, and students studying stochastic processes or probability theory.

Dustinsfl
Messages
2,217
Reaction score
5
How do I estimate the pdf from a random variable \(X\) where \(X = U_1 - U_2\) and \(U_i\) are uniform random variables?

In the code below, I used unifrnd(-5, 5, 1000, 1) which generated a 1000x1 vector of uniform random number between -5 and 5.

How do I estimate the PDF for X?

Code:
rng;
X = unifrnd(-5, 5, 1000, 1) - unifrnd(-5, 5, 1000, 1);
bincenters = (-5:0.5:5);
bins = length(bincenters);

h = zeros(bins, 1);              %  pre-allocating h

for i = 1:length(X)
    for k = 1:bins
        if X(i) > bincenters(k) - 0.5/2 && X(i) <= bincenters(k) + 0.5/2
            h(k, 1) = h(k, 1) + 1;
        end
    end
end

pxest = h/(1000*0.5);

bar(bincenters, pxest)
 
Physics news on Phys.org
dwsmith said:
How do I estimate the pdf from a random variable \(X\) where \(X = U_1 - U_2\) and \(U_i\) are uniform random variables?

In the code below, I used unifrnd(-5, 5, 1000, 1) which generated a 1000x1 vector of uniform random number between -5 and 5.

How do I estimate the PDF for X?

Code:
rng;
X = unifrnd(-5, 5, 1000, 1) - unifrnd(-5, 5, 1000, 1);
bincenters = (-5:0.5:5);
bins = length(bincenters);

h = zeros(bins, 1);              %  pre-allocating h

for i = 1:length(X)
    for k = 1:bins
        if X(i) > bincenters(k) - 0.5/2 && X(i) <= bincenters(k) + 0.5/2
            h(k, 1) = h(k, 1) + 1;
        end
    end
end

pxest = h/(1000*0.5);

bar(bincenters, pxest)

What are you really trying to do?

There is no need to "estimate" this distribution you know it, it is the symmetric triangular distribution with support (-10,10).

Otherwise google "kernel density estimation", or "matlab ksdensity".

.
 
zzephod said:
What are you really trying to do?

There is no need to "estimate" this distribution you know it, it is the symmetric triangular distribution with support (-10,10).

Otherwise google "kernel density estimation", or "matlab ksdensity".

.

I just doing a problem out of a book on stochastic processes.
 
dwsmith said:
I just doing a problem out of a book on stochastic processes.

What is the exact wording of the problem.

.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 44 ·
2
Replies
44
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
3K
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K