フィルターのクリア

Test Results in a table

6 ビュー (過去 30 日間)
Antonio Melieni
Antonio Melieni 2019 年 5 月 22 日
編集済み: Adam Danz 2019 年 5 月 23 日
Hi
I need to performe an adf test for several columns of an array and need the results for all of the columns in one table.
Is that possible?
My idea is this:
for i = size(array_x,2)
[h,pValue,stat,cValue] = adftest(array_x(:,i));
end
ADFStat = table(h,pValue,stat,cValue,'RowNames',{'EUR_USD''GBP_USD''USD_CHF''USD_JPY'});
end
any ideas?

採用された回答

Adam Danz
Adam Danz 2019 年 5 月 22 日
編集済み: Adam Danz 2019 年 5 月 22 日
This should get you started. This solution only saves the h and pValue outputs - you can add in the stat and cValue variables by following my example. They are all scalar values so it should be fairly straightforward to add those in (I intentionally left them out so you'd have some practice).
One note: you specified row names but I added them as column names (I assume that's what you meant since you only had 4 names and the adftest() requires a sample size of at least 10).
% Create fake data
array_x = rand(40,5);
h = zeros(size(array_x,2),1); %Column vector!
pValue = h;
for i = size(array_x,2)
[h(i),pValue(i)] = adftest(array_x(:,i));
end
ADFStat = table(h,pValue,'VariableNames',{'EUR_USD','GBP_USD'});
Please feel free to comment below with questions etc.
  4 件のコメント
Antonio Melieni
Antonio Melieni 2019 年 5 月 23 日
Thanks for you help Adam!
You gave me the right input to achiev what I needed :)
function [ADF_Test] = ADFTest(array_x)
%Summary of this function goes here
% Detailed explanation goes here
array_x = table2array(array_x);
array_y = zeros(size(array_x,2),4);
for i = 1: size(array_x,2)
[h,pValue,stat,cValue] = adftest(array_x(:,i));
array_y(i,:) = [h,pValue,stat,cValue];
end
ADF_Test = table(array_y(:,1),array_y(:,2),array_y(:,3),array_y(:,4),...
'VariableNames',{'Null_rejected','pValue','Test_Statistic','cValue'},...
'RowNames',{'EUR_USD','GBP_USD','USD_CHF','USD_JPY'});
end
Adam Danz
Adam Danz 2019 年 5 月 23 日
編集済み: Adam Danz 2019 年 5 月 23 日
Nice work! You could do this if you want to save a line of code
for i = 1: size(array_x,2)
array_y(i,:) = adftest(array_x(:,i));
end
And you could do this to simplify the table conversion
ADF_Test = array2table(array_y,...
'VariableNames',{'Null_rejected','pValue','Test_Statistic','cValue'},...
'RowNames',{'EUR_USD','GBP_USD','USD_CHF','USD_JPY'});
end

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by