Excluding data points while using least square method
Afficher commentaires plus anciens
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.
Réponses (1)
John D'Errico
le 24 Juil 2017
0 votes
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 commentaires
Damian Wierzbicki
le 24 Juil 2017
Damian Wierzbicki
le 24 Juil 2017
John D'Errico
le 24 Juil 2017
Modifié(e) : John D'Errico
le 24 Juil 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.
Catégories
En savoir plus sur Linear Predictive Coding dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!