Announcement

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

  • Want to apply a linear prediction line that is forced through 0,0 / has an intercept of 0.

    Hello,

    I have data that concerns the linear (x variable) and contour (y variable) length of coral colonies. These is a well established linear and positive relationship between these variables.
    I am aiming to establish the linear equations that will allow the prediction of the coral contour from a best fit line applied to the x variable. So far I have used a twoway plot with lfit and lfitci to gain the equation and also look at the confidence intervals of the data.
    However, as is common with the data I have I need to force the prediction line through 0,0 and take the equation from this line.
    I have so far been unable to set the intercept as 0 or suppress it. If anyone has any method for solving this I would be most appreciative.

    Many thanks,
    Amelia



  • #2
    Hello Amelia,

    I assume you are running a linear regression. In such a regression, the intercept is the value your outcome (contour) has when your predictor (linear) is zero. One thing you could do is to subtract the intercept form the contour value (such as the code below does). See that the intercept in the last linear regression is zero to most practical purposes.

    Code:
    set obs 100
    gen linear = runiform()
    gen noise = runiform()
    gen contour = (linear*4) + (noise*2)
    drop noise
    regress contour linear
    display _b[_cons]
    gen contour2 = contour - _b[_cons]
    regress contour2 linear
    An obvious problem with this approach is that you are not modelling the contour of your corals anymore, you are modelling the contours minus the intercept (or the value contour has when linear==0). The intercept is set at zero, as you wanted, but you I wouldn't use this last model to predict values of contour as a function of linear, since they will, on average, by off exactly by the value of the intercept that you subtracted. The beta of the linear variable is the same on both models, and this represents the average rate of change of your contour for a one unit increase on your predictor.

    Best;

    Comment


    • #3
      Here is a reproducible example. I can't easily suggest code for your data because I can't see example data.

      Code:
      sysuse auto, clear
      gen gpm = 1000/mpg
      label var gpm "Gallons/1000 miles"
      regress gpm weight, noconst
      local slope = _b[weight]
      su gpm weight
      
      scatter gpm weight || function fitted = `slope' * x, ///
      ra(weight) legend(order(2) pos(5) ring(0))           ///
      xsc(r(0 4840)) ysc(r(0 84))                          ///
      ytitle(Consumption in gallons/1000 miles) xtitle(Weight in pounds)
      EDIT Igor's code in #2 has some similarities but he misses the noconstant option on regress. I don't feel queasy about forcing a line through the origin with good grounds. After all, many of the laws one learns in elementary physics are straight lines through the origin.
      Last edited by Nick Cox; 29 May 2018, 08:26.

      Comment


      • #4
        Hello,

        Thank you both for your solutions! Nick yours works a treat for the scatter and prediction line. However, I do not seem to be able to get my confidence intervals to surround this prediction line. Is there a way to edit the lfitci command so that too is relevant for the 0 intercept prediction line?

        To double check as well, am I right in my assumption that the regress y x, noconst command performs the same task as regress but considers the data with a 0 intercept?

        Many thanks,

        Comment


        • #5
          There is no option in lfitci to suppress the intercept. I think you'd need to calculate your own confidence intervals using post-estimation commands.

          It's documented in help regress that noconstant suppresses the intercept term.

          Comment

          Working...
          X