function p=myAnova(data,label,n)
% function£ºa one-way ANOVA for comparing the means of two groups of data
% Input£ºdata¡ª¡ªtwo groups ofdata£º1*n or n*1 vector
% label¡ª¡ªlabel must be a categorical variable,numeric vector, logical vector, string array,
% or cell array of strings with one group name for each element of data.
% n¡ª¡ªthe number of the first label
% data values corresponding to the same value of label are placed in the same group
% Output£ºp¡ª¡ªthe p-value
%
if nargin<3 | isempty(n)==1
n=1/2*length(data);
end
[m1,n1]=size(data);
if m1<n1
data=data';
end
[m2,n2]=size(label);
if m2<n2
label=label';
end
[h1,p1] = lillietest (data(1:n));
[h2,p2] = lillietest (data(n+1:end));
if h1==0 & h2==0
if p1>0.05 & p2>0.05
p3 = vartestn(data,label,'off');
if p3>0.05
p = anova1(data,label);
end
else
p = kruskalwallis(data,label);
end
else
p = kruskalwallis(data,label);
end
评论1