Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can you propose a graph on which I can compare a couple of Uniform distributions?

    Good morning,

    Nick Cox or anybody else with interests in graphing: Can you please propose a graph which is convenient for comparing a couple of standard uniform distributions on the same graph? Or more precisely a couple of distributions with support on [0,1] which I want to compare to one another, and I want to see which is close to the standard uniform and which is not?

    When I compare a couple of distributions that tapper off at both tails, -twoway kdensity- is great. However I do not know whether there is a way to use -kdensity- on a distribution like the uniform that does not tapper off. (Is there a way to tell -kdensity- that the distribution has a limited support on [0,1]?)

    Histograms serve when you are looking at one (allegedly) uniform distribution, but become horrible if you want to put two distributions on the same picture. Once I looked up on the internet and with a lot of pain produced a graph overlaying two histograms, and I was not happy with the results because the one on the front covers the one on the back, and generally a mess results.

    So in short, do you have any suggestions of how to graph a couple of distributions with limited support on [0,1] that do not tapper off at the tail on the same picture?


  • #2
    Interesting question. My suggestion would be to stay with histogram but change the plottype from bar to line and then overlay the two graphs with twoway. Depending on the number of observations you have and the number of bins you generate this looks rather clean.
    Best wishes

    Stata 18.0 MP | ORCID | Google Scholar

    Comment


    • #3
      Very good, Felix, but can you please show sample code? I do not know how to make historgrams of line plot type...

      About the observations, I have plenty of observations. And I can produce more if I want. I am simulating the set of statistics that are supposed to be uniformly distributed, so the longer I let the computer run, the more observations I get to produce the picture.
      Originally posted by Felix Bittmann View Post
      Interesting question. My suggestion would be to stay with histogram but change the plottype from bar to line and then overlay the two graphs with twoway. Depending on the number of observations you have and the number of bins you generate this looks rather clean.

      Comment


      • #4
        I would use qplot from the Stata Journal, which (one detail aside) is in effect a generalization of quantile.


        Code:
         clear 
        
        . set obs 100
        Number of observations (_N) was 0, now 100.
        
        . set seed 2803
        
        . gen u1 = rbeta(1, 1)
        
        . gen u2 = rbeta(0.8, 1.2)
        
        . qplot u1 u2
        
         . qplot u1 u2, addplot(function equality=x) aspect(1)
        Click image for larger version

Name:	kolev.png
Views:	1
Size:	34.4 KB
ID:	1629092


        See also ideas at https://www.stata-journal.com/articl...article=gr0027

        Comment


        • #5
          Here some code how I could imagine this.

          Code:
          clear all
          set seed 123
          set obs 9999
          
          gen x1 = runiform()
          gen x2 = runiform()
          
          
          local bins = 25
          twoway (histogram x1, bin(`bins') type(line) color(black)) ///
              (histogram x2, bin(`bins') type(line) color(red)) ///
              (scatteri 1 0 1 1, recast(line))
          Best wishes

          Stata 18.0 MP | ORCID | Google Scholar

          Comment

          Working...
          X