Statistic analysis on cell arrays

4 views (last 30 days)
Sebastian
Sebastian on 10 Feb 2011
Hi,
I need to do check if the influence of two parameters on my data is significant. The data is organized in a cell array. Here is some code to generate test data:
MATLAB code
% Example data: random with offsets
%(Number of datapoints are different)
a1b1 = rand(42,1) + 0.5;
a2b1 = rand(25,1) + 1.0;
a3b1 = rand(32,1) + 1.2;
a1b2 = rand(37,1) + 0.8;
a2b2 = rand(23,1) + 1.2;
a3b2 = rand(29,1) + 1.3;
% Data is organized in a cell array
testData = {a1b1,a1b2;a2b1,a2b2;a3b1,a3b2};
testDataMean = cellfun(@mean,testData);
testDataStd = cellfun(@std,testData);
% Plot bar graph
hbar = bar(testDataMean);
Now, my question: How can I test if the influence of parameters A and B is significant?
I guess that the anovan function could possibly do what I need, but I can't get it to work on my cell array.
Can anyone help me with suggestions?

Answers (1)

Matt Tearle
Matt Tearle on 10 Feb 2011
I think this is what you're looking for:
A = nominal([ones(42,1);2*ones(25,1);3*ones(32,1);...
ones(37,1);2*ones(23,1);3*ones(29,1)]);
B = nominal([ones(42+25+32,1);2*ones(37+23+29,1)]);
data = [a1b1;a2b1;a3b1;a1b2;a2b2;a3b2];
anovan(data,{A,B})
The idea is to stack everything into one long vector and create accompanying grouping variables (A & B). You don't need to make them nominal, but it's cool if you do :) I used values (A = 1,2,3, B = 1,2) just because that's how you labeled them, but you could use other labels instead. The repmat function is handy, in that case -- eg:
B = nominal([repmat('X',42+25+32,1);repmat('Y',37+23+29,1)]);

Community Treasure Hunt

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

Start Hunting!