Quantcast
Viewing all articles
Browse latest Browse all 1015

Linear regression with random error giving EXACT predefined parameter estimates

By anspiess

When simulating linear models based on some defined slope/intercept and added gaussian noise, the parameter estimates vary after least-squares fitting. Here is some code I developed that does a double transform of these models as to obtain a fitted model with EXACT defined parameter estimates a (intercept) and b (slope).

It does so by:
1) Fitting a linear model #1 to the x,y data.
2) Correcting y by Image may be NSFW.
Clik here to view.
beta_1
: Image may be NSFW.
Clik here to view.
Y_i = Y_i cdot (mathrm{b}/beta_1)
.
3) Refitting linear model #2: Image may be NSFW.
Clik here to view.
Y_i = beta_0 + beta_1X_i + varepsilon_i
.
4) Correcting y by Image may be NSFW.
Clik here to view.
beta_0
: Image may be NSFW.
Clik here to view.
Y_i = Y_i + (mathrm{a} - beta_0)
.
5) Refitting linear model #3: Image may be NSFW.
Clik here to view.
Y_i = beta_0 + beta_1X_i + varepsilon_i
, which is the final model with parameter estimates a and b.

Below is the code:

exactLM x = 1:100, ## predictor values
b = 0.01, ## slope
a = 3, ## intercept
error = NULL, ## homoscedastic error
n = 1, ## number of replicates
weights = NULL, ## possible weights, i.e. when heteroscedastic
plot = TRUE, ## plot data and regression
... ## other parameters to 'lm'
)
{
if (is.null(error)) stop("Please ...read more

Source:: r-bloggers.com


Viewing all articles
Browse latest Browse all 1015

Trending Articles