I have a point (x,y) that I need a linear regressor to pass through given a data set (X,Y). How do I implement this in R?
If $(x_0,y_0)$ is the point through which the regression line must pass, fit the model $y−y_0=\beta (x−x_0)+\varepsilon$, i.e., a linear regression with "no intercept" on a translated data set. In $R$, this might look like
lm( I(y-y0) ~ I(x-x0) + 0). Note the
+ 0 at the end which indicates to
lm that no intercept term should be fit.
Depending on how easily you are convinced, there are multiple ways to demonstrate that this does, indeed, yield the correct answer. If you want to establish it formally, one simple method is to use Lagrange multipliers.
Whether or not it is actually a good idea to force a regression line to go through a particular point is a separate matter and is problem dependent. Generally, I would personally caution against this, unless there is a very good reason (e.g., very strong theoretical considerations). For one thing, fitting the full model can provide a means for measuring lack of fit. As a second matter, if you are mostly interested in evaluating model explanatory power for values of $x$ and $y$ "far away" from $(x_0,y_0)$, then the relevance of the fixed point becomes suspect.