Title says it all…

Here is roughly what happens in the code below:

  1. We specify the sample size of the example groups we want to create.
  2. We create normally distributed sets of samples for each group with equal standard deviation.
  3. We sort the samples’ values into vectors that can be used by the MatLab ANOVA function.
  4. We run the MatLab ANOVA function anova1.
  5. We pass the results of anova1 to the MatLab function for executing a multiple comparison.

In the end, this should take us to an interface where we can see which conditions are significantly different (p<0.05), and which aren’t.

%% Create mock data to run the ANOVA on

% Set the number of samples in each group
group_sizes = [12,9,10,8,14,10];
num_groups = numel(group_sizes);

% Randomly assign the population means of the groups
group_means = rand(1,num_groups);

% Set the level of variation
sigma = 0.3;

% Make a cell array, each cell element contains the values from one group
group_vals = cell(1,num_groups);

% Assign the sample values in the groups
for kk = 1:num_groups
    % Make values distributed normally around group mean with standard
    % deviation sigma
    group_vals{kk} = group_means(kk)+sigma.*randn(group_sizes(kk),1);

%% Prepare for and execute ANOVA

% Make the sample value and group membership vector
sample_vec = [];
membership_vec = [];

for kk = 1:num_groups
    % Iterate through all groups
    % Add this group's values to the value vector
    sample_vec = [sample_vec;group_vals{kk}];
    % Add the membership values to the membership vector
    membership_vec = [membership_vec;kk.*ones(numel(group_vals{kk}),1)];

[p_val,ANOVA_table,mult_comp_stats] = anova1(sample_vec,membership_vec);

%% Go into multiple comparison to find out where differences reside


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s