Excluding data points while using least square method
1 view (last 30 days)
Show older comments
Hi all. How can I exclude some points from my response data ( entries of value 0 ) while estimating the coefficient for my ( multiple ) linear regression model using least squares, so that obv the corresponding points in the x,y,z matrices ( predictors ) will be excluded too ? Thank you.
0 Comments
Answers (1)
John D'Errico
on 24 Jul 2017
How can you exclude them?
You do that by excluding them. Just drop them from your dataset. Create a new copy that lacks those points, then use the modified set for the estimation. You can just use find to find the points with a zero. Or use find to find the points that are not zero.
WTP?
3 Comments
John D'Errico
on 24 Jul 2017
Edited: John D'Errico
on 24 Jul 2017
I'd suggest you need to read the getting started tutorials.
Learn to use find, although you might note that I never even needed to use find. A logical vector was sufficient, but I could have used find. Learn to use indexing.
% make up some data
xy = randn(20,2);
z = randn(20,1);
% As an example, select and use only the data with z greater than zero
ind = z > 0;
zhat = z(ind);
xyhat = xy(ind,:);
% use backslash
pred = xy\z;
Or, if you don't want to create those extra variables, don't.
ind = z > 0;
pred = xy(ind,:)\z(ind);
Or use find:
ind = find(z > 0);
pred = xy(ind,:)\z(ind);
Or never even create an index vector at all:
pred = xy(z > 0,:)\z(z > 0);
All basic MATLAB.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!