stepwise regression: Undefined function ' stepwiselm' for input arguments of type 'cell'.

I have one .txt file and converted to first a table Ta(Ta=readtable('xxx.txt')) then an array Aa(Aa=table2array(Ta)), the .txt file contains 220 rows and 12 cols, but the table and the array only have 219 rows and 1 col. Where did I do wrong?
Then when I tried to do stepwise regression I got error message: Undefined function ' stepwiselm' for input arguments of type 'cell'.
My coad was: mdl=stepwiselm(Aa)
In the .txt file, the first raw are texts e.g. elevation, hight, yields etc. I though I could use these names to define Predictor variables and Response variable. But since these names are lost in Aa, how should I write code for stepwise regression?

댓글 수: 2

Please attach the file to your question.
exercise_data333.txt(220*10) contains data for sample points. I converted it to a table and then an array A. Then use A in the code for calculation to get a new .txt called A-100spreg2-raa12.
I then converted the new .txt to a matrix M M = dlmread('A-100spreg2-raa12.txt')
Then I want to apply stepwise regression on M.
In exercise_data333.txt, the first row are texts, but in M there are no text. Then how can I write e.g. use 'yield' as dependent variable i.e. response variable and 'DEM, grad, HI' as independent variables i.e.predictor variables?
  • 'yield' is the 10th colmun, so stepwise(M,M(:,10)) works fine, but what if I want to keep names for all variables.

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

답변 (1개)

I recommend using a dataset for your problem.
A = dataset('File','excercise-data333.txt');
A dataset is a kind of table. The headers do not get lost and you can easily address a column (for expample: b = A.yield or c = A.x). The function stepwiselm accepts datasets as first argument.

댓글 수: 3

Instead of exercise-data333, I used another .txt file called Araa06.txt, which contains the same variable names as exercise-data333(first row) but new values (after ran the code). Then I ran A = dataset('File','Araa06.txt')
Two errors returned:
Misuse dataset/readFile (line 207) Variable lengths must all be the same.
Error dataset (line 351) a = readFile(a,fileArg,otherArgs) What do they mean?
Hard to tell. The function can handle missing values, so that cannot be the problem. I have no idea.
For some reason it works now! (I simply copied the first row(names of variables) form the original file exercise-data333.txt to Araa06.txt, then created dataset A, then ran stepwise regression.)
Thank you so much!

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

카테고리

질문:

2014년 9월 17일

댓글:

2014년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by