The result of anovan is "NaN".

2 views (last 30 days)
Kaminosono Shougo
Kaminosono Shougo on 17 Jan 2023
Answered: Omega on 12 Jul 2024
I have a program that reads in 4 data, calculates the slope, and then applies the slope to an analysis of variance, but the result is "NaN"." I have defined the data as continuous variables with the "continuous" option, but I wonder if there is a problem.

Answers (1)

Omega
Omega on 12 Jul 2024
Hi Kaminosono,
I understand that you are getting 'NaN' values in in your 'annovan' calculation. I ran the attached MATLAB script and found that the reason for these 'NaN' results might be due to '-Inf' values in your 'sloop' array.
You can replace the '-Inf' values with 'NaN' in your 'sloop' array by inserting the following line after your calculation of the 'sloop' array. This will handle the '-Inf' values.
sloop(isinf(sloop)) = NaN;
Here is a complete version of the code:
dataFileName1 = 'exp3_sloop_parameter';
dataFileID1 = fopen([dataFileName1,'.txt'],'r');
if (dataFileID1 == -1)
error('data file not exist');
end
formatSpec = '%f';
y = fscanf(dataFileID1,formatSpec);
fclose(dataFileID1);
outFileID3=fopen(['invidi_sloop','.txt'],'w');
if (outFileID3 == -1)
error('cannot open output file');
end
outFileID4=fopen(['invidi_para','.txt'],'w');
if (outFileID3 == -1)
error('cannot open output file');
end
indivi=12; %subject_number
y = reshape(y,[4,3,indivi]);
sloop = zeros(3);
%/ j=1:ek j=2:jp j=3:tw
% sloop =(y2-y1)/(x2-x1)
for j =1:indivi
for i =1:3
sloop(i,j) = (y(4,i,j)-y(2,i,j))/(y(3,i,j)-y(1,i,j));
end
end
sloop(isinf(sloop)) = NaN;
y = reshape(y,[4,3*indivi]);
sloop = reshape(sloop,[indivi*3,1]);
sloop;
for i = 1:indivi*3
fprintf(outFileID3,"%f\n",sloop(i,1));
fprintf(outFileID4,"%f\n%f\n%f\n%f\n%f\n\n",y(1,i),y(2,i),y(3,i),y(4,i),sloop(i,1));
end
g1 = [1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3]; %文化
g2 = [1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12]; %個人
g3 = [1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3];%刺激
p = anovan(sloop,{g1,g2,g3},'model',[0 0 1],'varnames',{'culture','individual','stimuli'},'continuous',[1 2 3]);

Community Treasure Hunt

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

Start Hunting!