フィルターのクリア

Bug using LinearModel.fit in a loop?

1 回表示 (過去 30 日間)
Simon
Simon 2013 年 5 月 29 日
Everytime i try using my datas and LinearModel.fit it works perfectly, but when i try to use it in a loop i always end up having a matrix (of the correct size) of empty cells... Somebody who has matlab R2013a on a MAC said my said was running perfectly but it doesn't seem to run on a PC with R2012a. Thanks in advance!
V = nchoosek(6,4)
for i = 1:15
A{i}¨= V(i,:)
end
for i = 1:15
C{i} = horzcat(A{1,i}{1,1},A{1,i}{1,2},A{1,i}{1,3},A{1,i}{1,4})
end
for i = 1:15
DATA{i} = [C{1,i} Y] %Y is my independent variable
end
for i = 1:15
REG{i} = LinearModel.fit(DATA{1,i})

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 5 月 29 日
Well this part doesn't work:
V = nchoosek(6,4)
for i = 1:15
A{i}= V(i,:)
end
because V is a scalar. Start using the debugger, run the following:
dbstop if error
Then run your script. It will stop and you'll be able to inspect what's causing the error.
  1 件のコメント
Simon
Simon 2013 年 5 月 30 日
Good thinking. I made it work because i realised that LinearModel.fit is an object so i can't make many object in a matrix... but using only Varname.Rsquared.Adjusted can give me all the Rsquared im looking for in a matrix. The only problem is that it doesn't give me the var name anymore, only the answer :S. Is there a way to generate the Rsquared AND having the coefficient names for each answer at the same time? That would be great. I know the ''.Coefficients'' gives the coeff names but i don't know how to put it together WITH Rsquared :/
Thank you!

サインインしてコメントする。

その他の回答 (1 件)

Tom Lane
Tom Lane 2013 年 5 月 30 日
I don't really understand the question. But with the hint from Sean, I will show you the following code that will collect R-squared values from all of the fits into a single matrix.
V = nchoosek(1:6,4)
Y = [1.1;2.5;3.2;1.5];
for i = 1:15
REG{i} = LinearModel.fit(V(i,:)',Y)
end
rsq = zeros(15,1);
for i=1:15
rsq(i,1) = REG{i}.Rsquared.Ordinary;
end

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by