Weighted least squares in R

August 18, 2006

I’m using R to fit curves to data that has outliers backed by low observation counts. I’ve been thrashing round trying different R fitting methods, including glm.fit. But linear fits were obviously wrong. Not being a maths graduate, I was a bit stumped until I had a chat with one of our more maths and tech minded model traders. He looked at my charts and data, and suggested a weighted least squares fit.

In R we can do a least squares fit with loess() and predict(). Given sample data including weights, loess() will generate fitting parameters. The you feed data points to be charted through predict(), along with the fitting parameters, and plot the nicely smoothed result. Do example(loess) in R to get started.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s