Announcement

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

  • Graph: Define axis although some data point of the scatterplot are omitted

    Hello stata commune,

    i plot my data with the lowess command "lowess yvar xvar". Hence, i receive a graph with a scatterplot and the smoothed curve. The range of the x-axis is from 0 to 1, Thats fine. Indeed, the range of the y-axis is from -1 to +2. The reason is that the largest y-value is +2 and the smallest -1, but they are outliers. Hence, i would like to have a y-axis range from -0.1 to +0.5 so that the figure illustrates predominatly the smoothed curve. I would like to avoid to delete the outliers!

    I tried to solve the probelm with the graph editor. When i try to define the desired range in the editor, it does not work due to the outliers.
    I did not find a solution for the relatively easy problem.
    Thank you for help!

    Best regards
    Marian

  • #2
    Welcome to the Stata Forum / Statalist,

    I'm not saying this is the correct approach, I mean, to exclude information concerning the outliers. More so, considering that weighted smoothing is sort of a nonparametric process.

    That said, you may use the regular commands and options for - graph twoway -, such as yscale(range(-0.1 0.5)) plus ylabel(-0.1(0,1)0.5).

    Hopefully that helps.

    Best regards,

    Marcos

    Comment


    • #3
      I agree with Marcos Almeida that outliers are to be omitted at your own risk.

      My experience - limited, and not well informed - is that I have not been able to use the range() option to reduce the extent of a graph. From help axis_scale_options##remarks2

      range() never narrows the scale of an axis or causes data to be omitted from the plot
      So what I typically do is restrict the range of my data, something like
      Code:
      scatter yvar xvar if inrange(yvar,-0.1,0.5)
      But as Marcos points out, that will affect the curve fit by lowess.
      Last edited by William Lisowski; 14 Jan 2018, 11:06.

      Comment


      • #4
        Without necessarily approving I will add that you can

        1. Use lowess, generate() to put results in a new variable.

        2. Plot the data without outliers and the lowess curve too.

        3. Document that the graph omits two points.

        Code:
        lowess yvar xvar, gen(svar)
        scatter yvar xvar if inrange(yvar,-0.1,0.5) || line svar xvar
        Last edited by Nick Cox; 15 Jan 2018, 05:45.

        Comment


        • #5
          Thank you everbybody for the fast help.
          I would like to avoid to exclude the outliers. Therefore the smoothed curve consider the outliers. The problem is in the next step, i only would like to illustrate the smoothed curve with the desired axis range. It would be great if someone has an answer according to this problem.

          Best regards
          Marian

          Comment


          • #6
            #4 does precisely what you ask.

            Comment


            • #7
              Thank you Nick!

              Comment


              • #8
                Unfortunately iam not sure with approach. I want to avoid your second point "2. Plot the data without outliers and the lowess curve too." I want to generate the smoothed curve with all data points. Then i would like to illustrate the resulting smoothed curve with a range from -0.1 to +0.5! Then, it is not necessary to show the data points, only the smoothed curve...
                I hope i understand you correctly.

                Best regards
                Marian

                Comment


                • #9
                  So, all you need is

                  Code:
                   
                   line svar xvar
                  if I understand you correctly.

                  Comment


                  • #10
                    Ok, sorry! Now it works...Thanks a lot!

                    Comment

                    Working...
                    X