Problem with LinearModel varNames

조회 수: 3 (최근 30일)
Hal
Hal 2014년 6월 9일
댓글: the cyclist 2014년 6월 10일
I've tried using both stepwise and stepwiselm in their (X,y) input mode, with X being 45x20 and y 45x1, but whenever I try to run it I get the error "VARNAMES must be a cell array with names for all predictors and for the response." Looking into the debugger, it seems to set varNames to a 1x46 cell and nvars to 21 (which are the variables it checks to see if they're equal before giving the error) so I thought it might be a transposition issue but that doesn't work either (then it gives me varNames 1x21 and nvars 46).
I've searched online but no one seems to be encountering this, what am I doing wrong?
  댓글 수: 2
the cyclist
the cyclist 2014년 6월 9일
Would it be possible for you to create the smallest possible self-contained example that we could run ourselves, that exhibits the error?
the cyclist
the cyclist 2014년 6월 10일
Does this code give you that error?
rng(1)
X = rand(45,20);
y = rand(45,1);
mdl=stepwiselm(X,y)
(If you have an old version of MATLAB, comment out the first line where I set the RNG seed.)

댓글을 달려면 로그인하십시오.

답변 (2개)

Roger Wohlwend
Roger Wohlwend 2014년 6월 10일
The error message tells me that you have defined the names of the variables incorrectly. I assume that your code looks something like this:
mdl = stepwiselm(X,y,'VarNames',Names);
The argument Names must be a cellarray with 21 elements (20 names for the x-variables and one name for the y-variable). See the Matlab documentation for further information.
If this does not help you you have to show us your code.

Hal
Hal 2014년 6월 10일
I'm using the mdl=stepwiselm(X,y) syntax so it's auto-assigning the variable names by default. And that's all of my code. X is a matrix I create from my data that's 45x20, y is a matrix that's 45x1. There is nothing else in my code.
  댓글 수: 1
Roger Wohlwend
Roger Wohlwend 2014년 6월 10일
편집: Roger Wohlwend 2014년 6월 10일
That makes it difficult. Could you please save the variables in a mat-file and post them so we could try to reproduce the error.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Model Building and Assessment에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by