Announcement

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

  • How to plot QQ-plot and customize it?

    Hi , I am trying to compare two series of data (with sufficiently large number of observations) in range [0, 1] to the uniform distribution on [0, 1]. I want to plot the Q-Q plot with empirical CDF being the on the y-axis and the CDF of the uniform distribution on the x-axis. I also want to plot the 45 degree line, make a scatter plot of the data, make both x and y axis into log_10 scale, and put the two series on the same plot being labled. I would really appreciate if someone can provide me with a sample code, I have been trying by myself for a long time. Thanks a lot!

  • #2
    You need to be clearer on what you want. A plot of empirical CDF versus theoretical CDF is a P-P plot, not a Q-Q plot.

    Using your text and not your title leads to the advice to push your variables through cdf and then just fire up your own plot.

    Comment


    • #3
      Here's a guess at what you want. Naturally I can't see your data.

      Using the convention that the CDF runs 1/n, 2/n, ..., (n - 1)/n, n/n given sample size n is not the only possibility.

      Some trickery is needed, evidently, as 0 can't be plotted on a logarithmic scale.

      Code:
      clear 
      set obs 100 
      set seed 2803 
      set scheme s1color 
      
      gen y1 = runiform() 
      sort y1 
      gen x1 = _n/_N 
      gen y2 = runiform()
      sort y2 
      gen x2 = _n/_N 
      local min = 1
      foreach v in y1 y2 x2 { 
          su `v', meanonly 
          local min = min(`min', r(min))
      } 
      scatter y1 x1, ms(Oh)|| scatter y2 x2, ms(+) || ///
      function equality=x, ra(`min' 1)                ///
      ysc(log) xsc(log) yla(1 0.1 0.01) xla(1 0.1 0.01) aspect(1) legend(pos(3) col(1)) ///
      ytitle(observed) xtitle(expected)
      If any of your values are << 0.01 you will need to adjust axis labels accordingly.

      Click image for larger version

Name:	ppplot.png
Views:	1
Size:	31.4 KB
ID:	1467852

      Comment

      Working...
      X