Excluding data points while using least square method
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
John D'Errico
el 24 de Jul. de 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 comentarios
John D'Errico
el 24 de Jul. de 2017
Editada: John D'Errico
el 24 de Jul. de 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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!