Removing NaN in Linear Regression Problem. Error in line 66.
이전 댓글 표시
Hello guys,
I am trying to conduct a multivariable linear regression problem. The predictors (X) form a table sized 52824x9.
When trying to remove all the NaN values using this piece of code, included in the regress function:
% Remove missing values, if any
wasnan = (isnan(y) | any(isnan(X),2)); %line 66
havenans = any(wasnan);
if havenans
y(wasnan) = []; %line 69
X(wasnan,:) = [];
n = length(y);
end
At first, I got an error stating:
Undefined function 'isnan' for input arguments of type 'table'.
Error in regress (line 66)
wasnan = (isnan(y) | any(isnan(X),2));
I searched for solutions, and I was able to find one saying that isnan function is not able to access data from tables, and the provided solution was to include the following:
wasnan = (isnan(y{:,:}) | any(isnan(X{:,:}),2));
Now I get an error in line 69 saying the following:
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not
supported. Use a row subscript and a variable subscript.
If anyone knew how to solve the problem or to provide another solution for accessing data with the isnan function, it would be very much appreciated. I have been trying to solve this problem for some days now.
Many thanks,
Natalia
채택된 답변
추가 답변 (1개)
Cris LaPierre
2020년 3월 18일
0 개 추천
댓글 수: 5
dpb
2020년 3월 18일
But the problem OP has is has passed a table to regress instead of the variables from the table...not that it would hurt to do the cleanup externally first, but will still run into a problem elsewhere later on when trying to access x,y...
Cris LaPierre
2020년 3월 18일
I'm addressing the code the OP shared - removing NaNs from a table.
dpb
2020년 3월 18일
Hmmm....that would work outside regress and if the OP did extract that code from the regress function and is trying it elsewhere. Looked to me like was trying to patch regress instead.
But even if so, unless changes the form in which calls regress it'll result in a table and will fail again trying to get around the input check inside regress.
Cris LaPierre
2020년 3월 18일
Ah, I didn't realize that code snippet was from the regress function. Yes, don't go changing code inside the function. Use this to clean up your table before passing it to regress.
And yes, regress does not support tables as inputs. Use the dot notation to pass in variables.
NATALIA ARREGUI GONZALEZ
2020년 3월 19일
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!