0

I am running a simple regression in R with Price and Quantity:

  MyModel=lm(MyData$Price ~ MyData$CumQuantity)
  MyCoef=coef(MyModel)

Then the slope will be MyCoef[2], while the intercept will be MyCoef[1].

Is it possible to force it to go through a certain point (a Price and a Quantity), and then get the slope and intercept for that line instead?

Thanks in advance!

Progman
  • 16,827
  • 6
  • 33
  • 48
Avocado
  • 70
  • 8
  • Does this solve the problem? https://stackoverflow.com/questions/7333203/linear-regression-with-a-known-fixed-intercept-in-r – Harrison Jones Jun 07 '22 at 16:27

1 Answers1

1

This is a minor variation on the linked question (which specified an intercept, but not an (x,y) value)

I think this should set the (0,0) point (implicitly) to (target_CumQuantity, target_Price) and fit a model without intercept (i.e. going through (0,0)). There will be no intercept estimate, only a slope estimate. You'd have to work out the intercept estimate by hand ...

MyModel <- lm((Price - target_Price) ~ I(CumQuantity - target_CumQuantity) - 1, 
              data = MyData)
intercept <- with(myData,
    target_Price - target_CumQuantity * coef(MyModel)[1])
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453