+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 16 to 30 of 31

Thread: A question about the distribution of random numbers

  1. #16
    Wrokin' for the Raptors
    Points: 6,456, Level: 52
    Level completed: 53%, Points required for next Level: 94
    spunky's Avatar
    Location
    vancouver, canada
    Posts
    953
    Thanks
    43
    Thanked 184 Times in 142 Posts

    Re: A question about the distribution of random numbers



    Quote Originally Posted by Dason View Post
    No it actually does mean division in this case. But the fact is that you don't get 0. You get \Phi(0)^{-1} = .5^{-1} = 2
    fail on my part for not reading the order of operations properly. CDF FIRST, then INVERSE.

    darn it, but thanks for the correction!
    Dason on the Cauchy distribution:
    "YOU BETTER LOOK OUT BECAUSE THIS IS SOMETHING THAT IS GOING TO GET YOU"

  2. #17
    Points: 1,023, Level: 17
    Level completed: 23%, Points required for next Level: 77

    Posts
    40
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by Dragan View Post
    I believe your original question can be thought of equivalently as the maximum of A,B.

    Therefore take the product of the two CDFs (in one variable, say, X) and then take the derivative of the resulting product with respect to X and that should be your PDF.
    My skill at statistics could be much better, and I am working on it, but right now, I don't know how to arrive at the PDF. I bought a licence for Mathematica, and I am working on learning that skill. If anyone on here would be kind enough to write the Mathematica code for the solution give by either Dragan above or BGM (or both), I would be extremely appreciative. That way, I know I haven't made an error, and I will be able to study the code and learn exactly what is going on.

    And thank you for all the help so far!

  3. #18
    Super Moderator
    Points: 8,567, Level: 62
    Level completed: 39%, Points required for next Level: 183
    Dragan's Avatar
    Location
    Illinois, US
    Posts
    1,724
    Thanks
    0
    Thanked 127 Times in 113 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by BigBugBuzzz View Post
    My skill at statistics could be much better, and I am working on it, but right now, I don't know how to arrive at the PDF. I bought a licence for Mathematica, and I am working on learning that skill. If anyone on here would be kind enough to write the Mathematica code for the solution give by either Dragan above or BGM (or both), I would be extremely appreciative. That way, I know I haven't made an error, and I will be able to study the code and learn exactly what is going on.

    And thank you for all the help so far!

    This is what I mean in Mathematica. A hypothetical with MuA=10, Sigma=3; and MuB=9, Sigma=2

    phiA=CDF[NormalDistribution[10,3], X]
    phiB=CDF[NormalDistribution[9,2], X]
    u=phiA*PhiB
    v=D[u,X]

    v is the derivative of u (the product of the two CDFs) and should be you probability density function.

  4. The Following User Says Thank You to Dragan For This Useful Post:

    BigBugBuzzz (09-18-2012)

  5. #19
    Points: 1,023, Level: 17
    Level completed: 23%, Points required for next Level: 77

    Posts
    40
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: A question about the distribution of random numbers

    Thank you Dragan. I have implemented the code in Mathematica and plotted the PDF:

    phiA = CDF[NormalDistribution[10, 1], X]
    phiB = CDF[NormalDistribution[10, 5], X]
    u = phiA*phiB
    v = D[u, X]

    Plot[(E^((12*(-10 + X)^2)/25)*Erfc[-((-10 + X)/Sqrt[2])] +
    5*Erfc[-((-10 + X)/(5*Sqrt[2]))])/(10*E^((-10 + X)^2/2)*
    Sqrt[2*Pi]), {X, 4.6, 15}]

    The result is the "Dragan" plot attached.

    Comparing that to the distribution derived from simulation, I think there is something wrong with the proposed solution. This distribution is also attached, and called "Simulation".

    Is BGM correct? What would his Mathematica code look like? I realize this is asking a lot...
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Dragan.gif‎
Views:	15
Size:	3.0 KB
ID:	2664   Click image for larger version

Name:	Simulation.gif‎
Views:	27
Size:	22.6 KB
ID:	2665  

  6. #20
    Points: 1,023, Level: 17
    Level completed: 23%, Points required for next Level: 77

    Posts
    40
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by BGM View Post
    f_C(a) = 
\Phi\left(\frac {\mu_A - \mu_B} {\sqrt{\sigma^2_A + \sigma^2_B}}\right)^{-1}
\Phi\left(\frac {a - \mu_B} {\sigma_B}\right)\frac {1} {\sigma_A}\phi\left(\frac {a - \mu_A} {\sigma_A}\right)
    I would very much appreciate it if someone would post the Mathematica code for this...

  7. #21
    Super Moderator
    Points: 8,567, Level: 62
    Level completed: 39%, Points required for next Level: 183
    Dragan's Avatar
    Location
    Illinois, US
    Posts
    1,724
    Thanks
    0
    Thanked 127 Times in 113 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by BigBugBuzzz View Post

    phiA = CDF[NormalDistribution[10, 1], X]
    phiB = CDF[NormalDistribution[10, 5], X]

    This distribution is also attached, and called "Simulation".

    Is BGM correct? What would his Mathematica code look like? I realize this is asking a lot...
    I'm not getting the empirical (or simulation) result that your getting...How are you performing your data generation and selection process?

    Note: The approach I gave for the MAX(A,B) is correct - the simulation matches the theoretical.

  8. #22
    Points: 1,023, Level: 17
    Level completed: 23%, Points required for next Level: 77

    Posts
    40
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by Dragan View Post
    I'm not getting the empirical (or simulation) result that your getting...How are you performing your data generation and selection process?
    I generate two vectors of random numbers, one columns from the Normal Distribution A and one columns from the Normal Distribution B.
    Then I identify all those instances where A > B (pair-wise).
    I finally import these to SPSS and draw the histogram shown.

    Example:

    A B
    2 1*
    3 2*
    1 2

    So, 2 and 3 form part of the distribution examined...
    Last edited by BigBugBuzzz; 09-18-2012 at 04:47 PM.

  9. #23
    RotParaTon
    Points: 46,181, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,068
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: A question about the distribution of random numbers

    @Dragan - I don't think max(A, B) is really the same thing as what they're doing. I didn't check all of the steps but BGMs derivation of the pdf looked reasonable to me.
    "His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich

  10. #24
    Super Moderator
    Points: 8,567, Level: 62
    Level completed: 39%, Points required for next Level: 183
    Dragan's Avatar
    Location
    Illinois, US
    Posts
    1,724
    Thanks
    0
    Thanked 127 Times in 113 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by BigBugBuzzz View Post
    I would very much appreciate it if someone would post the Mathematica code for this...
    Okay, I just looked at BGM's post, which I think is correct. What I suggested is a special case of what BGM proposed when both distributions are the same.

    Anyway, here's the Mathematica code - it should work.

    ma=10;
    mb=10;
    sa=1;
    sb=5;

    con=(ma-mb)/(Sqrt[sa^2 + sb^2];

    cmp=CDF[NormalDistribution[0,1],con];

    FB=CDF[NormalDistribution[mb,sb],x];

    fA=PDF[NormalDistribution[ma,sa],x];

    fx=(cmp^-1)*(1/sa)*FB*fA

    Plot[fx,{x,6,14}]

  11. The Following User Says Thank You to Dragan For This Useful Post:

    BigBugBuzzz (09-19-2012)

  12. #25
    Points: 1,023, Level: 17
    Level completed: 23%, Points required for next Level: 77

    Posts
    40
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by Dragan View Post

    Anyway, here's the Mathematica code - it should work.
    I really appreciate you taking the time Dragan. Unfortunately, while the code works, this does not match the simulated distribution either. I guess BGM's solution was not correct after all.

    I have attached the image of the distribution for the means and variances values you set , which match the means and variances used to generate the simulated distribution. As you will see, the distributions are not the same.

    Perhaps this nut is too hard to crack...

    Here is the reason why I think the simulated distribution is correct: The negative skew in the simulated distribution makes sense when the variance of A > B and means are equal, because larger values of A are allowed to "pass" at greater rate - even if smaller than muA - compared to the situation where the distributions are equal. The skewness of the distribution is intuitively determined by the relation between means and variance:

    muA = muB, sA = sB --> No Skew
    muA = muB, sA > sB --> Negative Skew

    I am yet to examine:

    muA > muB, sA = sB
    muA > muB, sA > sB

    I think the problem is interesting and I wish I had the capabilities to formalize, rather than just simulate! :-)
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Simulation.gif‎
Views:	1
Size:	22.6 KB
ID:	2667   Click image for larger version

Name:	Dragam - BGM.gif‎
Views:	2
Size:	2.9 KB
ID:	2666  
    Last edited by BigBugBuzzz; 09-19-2012 at 03:32 AM.

  13. #26
    TS Contributor
    Points: 14,821, Level: 78
    Level completed: 93%, Points required for next Level: 29

    Posts
    2,296
    Thanks
    8
    Thanked 372 Times in 351 Posts

    Re: A question about the distribution of random numbers

    I think we may misunderstand your original problem set up.

    Here is what I try with R:

    Code: 
    mA<-10
    mB<-10
    sA<-1
    sB<-5
    
    con<-(mA-mB)/sqrt(sA^2+sB^2)
    cmp<-pnorm(con)
    FB<-function(x) pnorm(x,mB,sB)
    fA<-function(x) dnorm(x,mA,sA)
    f<-function(x) FB(x)*fA(x)/cmp
    
    n<-100000
    d<-1:n
    for (i in 1:n) {
    	A<-0
    	B<-1
    	while (A < B) {
    		A<-rnorm(1,mA,sA)
    		B<-rnorm(1,mB,sB)
    	}
    	d[i]<-A
    }
    
    hist(d,freq=F)
    curve(f,add=T)
    And the resulting empirical distribution seems match with the proposed density.
    Attached Images  

  14. The Following User Says Thank You to BGM For This Useful Post:

    BigBugBuzzz (09-19-2012)

  15. #27
    Super Moderator
    Points: 8,567, Level: 62
    Level completed: 39%, Points required for next Level: 183
    Dragan's Avatar
    Location
    Illinois, US
    Posts
    1,724
    Thanks
    0
    Thanked 127 Times in 113 Posts

    Re: A question about the distribution of random numbers

    Quote Originally Posted by BGM View Post
    I think we may misunderstand your original problem set up.
    Yes, BGM, I suspected (yesterday) that there's a problem "somewhere" when I could not match BigBugBuzz's simulation result. I cannot say for sure where the problem is.

  16. The Following User Says Thank You to Dragan For This Useful Post:

    BigBugBuzzz (09-19-2012)

  17. #28
    Points: 1,023, Level: 17
    Level completed: 23%, Points required for next Level: 77

    Posts
    40
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: A question about the distribution of random numbers

    Perhaps I am not so clear in my formulation. But consider that B is just a line below the mean of A. Then C would surely not be symmetrical but would be cut sharply at B. Now consider that B is almost a line, but is in fact a very thin probability distribution, then C would still not be symmetrical, but would not be cut so sharply at the left, and so on. Does that make sense?

    Attached is a visual example of the selection of values for C, in case that makes things more clear.
    Attached Images  

  18. #29
    Points: 1,023, Level: 17
    Level completed: 23%, Points required for next Level: 77

    Posts
    40
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: A question about the distribution of random numbers

    HOLD THE PRESS!! You guys appear to be right after all! Note that if sA > sB we get asymmetry. If sB > sA symmetry. Beautiful! Thank you so much for the help! :-)

    I used Dragan's code and just switched sA and sB....

    Dragan's solutions appears to be correct. Do you agree BGM?

  19. #30
    TS Contributor
    Points: 14,821, Level: 78
    Level completed: 93%, Points required for next Level: 29

    Posts
    2,296
    Thanks
    8
    Thanked 372 Times in 351 Posts

    Re: A question about the distribution of random numbers


    From the pdf derived we can see that it is asymmetric - the (normal) CDF is a monotonic increasing function.

+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats