Announcement

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

  • Crop part of a graph (lpolyci) where the confidence interval includes impossible values

    Dear Statalist,

    I am trying to plot local polynomial smooths (twoway lpolyci [y) to display the evolution of probabilities/percentages over time.

    However, when the value is close to 0, the confidence interval includes negative values which is impossible. I would like to crop the graph in order to not show the negative values, and so that the lower CI would start at an x-value that is such that the probability (y-axis) is non-negative.

    I know that yscale and ylabel do not work since those can only expend the range of values but not crop it. The closest I could get was by specifying a plot range such that the bottom margin is negative : plotregion(margin(0 0 -10 0)) for example. However, the confidence interval is still displayed and super-imposed to the legend. I also have vertical lines, and they start from those negative y-values that I don't want thus they are also superimposed to the legend.

    So, how can I find a way to crop the lower part of the graph (where the CI includes negative probabilities) ? Is that even possible ?

    Thank you a lot --G

  • #2
    If you make the graph manually, you can redefine the lower limit of the confidence interval to be zero when it falls below zero.

    Code:
    clear
    * Generate some example data
    set seed 642
    set obs 100
    gen x=runiform()
    replace x=max(0,x-0.6)
    gen id = _n
    * Twoway lpolyci gives confidence bands below zero in some regions
    twoway lpolyci x id
    * Make graph with lpoly
    lpoly x id, gen(lx ly) se(se)
    gen ul = ly + 1.96*se
    gen ll = ly - 1.96*se
    twoway (rarea ul ll lx, color(bluishgray)) (line ly lx) 
    * Replace lower ci limit to zero if below zero
    replace ll=0 if ll<0
    twoway (rarea ul ll lx, color(bluishgray)) (line ly lx)


    The smoother doesn't know your data are probabilities, it just gives you the point estimate and confidence intervals as if the data were continuous over the real line. Someone else in the list may know about a smoother for data that is constrained to an interval.



    Jorge Eduardo Pérez Pérez
    www.jorgeperezperez.com

    Comment


    • #3
      Thanks a lot !! It works perfectly.

      Comment


      • #4
        We can't see your data or know your project but smoothing on a logit or logit-like scale might be a better bet.

        Comment

        Working...
        X