Project one. Problem 2. Mathematics 502 Probability and Statistics

Nasser Abbasi, September 26,2007. California State University, Fullerton


Part 2 (a)

The mixed distribution is
                         "problem2_2.gif"  -∞≤x≤∞

Where "problem2_3.gif" is the density function for normal distribution with σ=1,μ=0, and "problem2_4.gif" is the density function for normal distribution with σ=1,μ=3
We need to generate random numbers from the above density function.
The following is the idea of how to solve this problem. Let us consider the case for γ=75% .Generate a r.v. from a uniform distribution, which will be between [0,1].  Let this number be called ζ. If ζ<.76 then now we will generate a random  number from the above "problem2_5.gif" normal distribution otherwise we will generate a random number from "problem2_6.gif" distribution. Hence this is the algorithm


Input: γ,"problem2_7.gif",n (where n is number of random number to generate for mixture f(x)
output: n random numbers that belong to mixture f(x)

seed the random number generator (010101)
Initialize array d of the size of the random numbers generated

For i in 1..n LOOP
    ζ = generate a r.v. from U[0,1]
    IF ζ<γ THEN
        d[i]= generate a random number from "problem2_8.gif"
        d[i]= generate a random number from "problem2_9.gif"

output d which will now contain n random variables drawn from the above probability density function.

Function to implement the mixture random variable algorithm





Now generate 2 sets of numbers each 10000 long, one for γ = .75 and the second for γ = .25



Part 2 (b)

Generate 2 plots, one for γ = .75 and one for γ=.25 for number of random variables=10000 generated in part (a) overlaid by histogram.
First define the mixture density function (the true density). Please see appendix for the code that overlays the histogram and the mixture function called postprocessPartTwo[]. Moved below to the appendix to reduce code clutter in the main report.



Now call the above on the 2 sets of 10000 numbers generated in part (a) and display the result

This function makes a histogram which is scaled to be used to overlay density plots, or other functions.
Input:  originalData: this is an array of numbers which represents the data to bin
          nBins: number of bins
output: the histogram itself but scaled such that area is ONE








Graphics:true f(x) vs. random variables generated γ=0.75  Number of random variables=10000 Graphics:true f(x) vs. random variables generated γ=0.25  Number of random variables=10000

Comment and analysis on result of part 2 (b) plots

In the left plot, γ=.75, hence 75% of the mixture comes from "problem2_19.gif" which has a mean of 0, hence we would expect that at zero the bulk of the concentration, which what the plots shows to be the case (since both concentration have the same variance). Hence there should be more random numbers generated from this mixture around x=0 as well, and we see from the histogram that this is the case.
In the right plot, now γ=.25, hence 75% of the concentration will come the "problem2_20.gif" distribution which has mean of 3. Hence again, we see that more random numbers are generated around 3 than anywhere else. These plots also show that the random numbers generated will have a probability density which will converge to the f(x) given as more and more random variables are generated.

Simulation program for problem 2

GUI to simulate part 2(b) of the project







Created by Wolfram Mathematica 6.0 for Students - Personal Use Only  (25 September 2007) Valid XHTML 1.1!