Reputation: 307
I have a set of data that includes 821 observations, each with 20 measurements. I would like to regress this set data against a set of single dependent variables using a multiple linear regression in MATLAB. However, I would also like to weight each observation differently in the regression based on my own calculations. For example, I would like to give the first observation a weight of 1 and the second observation a weight of 1.6, which would ideally pull the regression towards the more heavily weighted second observation.
Is such a computation possible in MATLAB? If so, what function(s) would be best to carry out this type of computation?
Thanks for the help!
Upvotes: 1
Views: 3891
Reputation: 791
You do not actually need the Statistics Toolbox to do this. The built-in function lscov
will do everything you want.
[b,bse] = lscov(X,y,w)
will provide weighted OLS estimates and their standard errors. If you would like a constant in the regression then include a column of ones in X.
Upvotes: 2
Reputation: 24127
With Statistics Toolbox, you can use fitlm
to create a linear regression model, applying the Weights
option to supply your weights.
NB in older versions of MATLAB, you'll need to use LinearModel.fit
rather than fitlm
, but they do the same thing.
Upvotes: 1