Permutations function
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear community, I am writing to you because I need some help with programming in Matlab. I have to use Matlab for some statistical analysis but I haven't got much experience so far. I was wondering whether one of you could offer me some advice. I used a program to give me a matrix containing files of 30 different participants and their viewing duration of pictures for several trials (40 for each condition). Now I specified that the program should only include and average the times below 20000ms and above 10000ms. Numbers below or above should be labelled as "NaN". This is the script:
Matlab Code
% This program generates the time profile of the listening
% locked to the decision.
% Generate listening profile
Like_Decision = nan(20000,40,30);
Dislike_Decision = nan(20000,40,30);
for j=1:30
temp1 = dat(j).dat1;
temp2 = dat(j).dat2;
index1 = 0;
index2 = 0;
for i=[3:42 45:84],
overallTime = sum(temp2{i}(2:2:length(temp2{i})));
if overallTime > 300 && overallTime < 20000,
if temp1(i,4)==1
index1 = index1 + 1;
choice = temp1(i,6)-48;
Like_Decision(:,index1,j) = sequence1(temp2{i},choice);
else
index2 = index2 + 1;
choice = temp1(i,6)-48;
Dislike_Decision(:,index2,j) = sequence1(temp2{i},choice);
end
end
end
disp(['C1: ' num2str(index1) ', C2: ' num2str(index2)]);
end
end
function time = sequence1(rt,choice)
% This program will convert the rt sequence
% to a sequenece of 1s and 0s where
% 1 = choice
% 0 = non-choice
% Additionally we will also clip any rt to 20000 ms
time=[];
for i = 1:2:length(rt)-1
if rt(i) == choice
time = cat(1,time,ones(rt(i+1),1));
else
time = [time;zeros(rt(i+1),1)];
end
end
if length(time)>20000
time = time(end-20000+1:end);
else
time=cat(1,NaN(20000-length(time),1),time);
end
%time=downsample(time,5);
end
What I got to do now is to use that program in order to produce a permutation plot of these viewing times. So, the "for" loop should be repeated a 1000 times (for each condition: time1 (buy) or time2 (discard)) to get 1000 random histograms, then I was advised to use the sort(x) command to take off the extreme ends and produce a plot that shows the confidence intervals for all the simulated 1000 histograms.
Sigh, sorry it's quite an issue... Thank you very much and best wishes Chris
3 commentaires
Walter Roberson
le 1 Mar 2011
I cannot tell from your question which array you want to select random values from. The seeming most obvious would be time(), but considering the range of values you allow for it, duplicate times would seem unlikely so it then becomes unclear what you would be histograming.
Réponses (2)
Matt Tearle
le 2 Mar 2011
OK, still not sure if I quite get all the details (I think I'm getting mired in the terminology of samples vs trials vs participants etc), but I think I have enough to point you to randsample in Statistics Toolbox.
I think the simplest way of achieving what you want would be something along these lines:
y = rand(10,7);
col = size(y,2);
nboot = 500;
yboot = zeros(nboot,col);
for k=1:col
yboot(:,k) = randsample(y(:,k),nboot,true);
end
mean(y)
mean(yboot)
You could then perhaps use the distribution fitting functions to fit the data.
[mu,sigma,muci,sigmaci] = normfit(yboot)
Matt Tearle
le 2 Mar 2011
Mostly going to echo the comments made by The Usual Suspects. In particular, can you explain what you're trying to histogram, what you're randomly selecting from, and what the variables are (size, type, etc).
In the meantime, a couple of comments:
- it sounds like you're trying to do some kind of bootstrapping. Given that you're doing statistics, I assume you have Statistics Toolbox. In which case, you can look at bootstrp and bootci.
- it's hard to tell from the code (unformatted, and we don't have access to the data to try it), but it looks suspiciously like you could replace a lot of code with logical operations. In particular, the first part of sequence1 seems to do:
t = double(rt==choice);
3 commentaires
Matt Tearle
le 2 Mar 2011
A little, but I'm still not fully clear. I see two variables, (like and dislike), each being 20000-by-40-by-30. But then you want to average over the first dimension (or at least a portion of it). So then you'd have two matrices, both 40-by-30, right? Then you'd like to sample the rows with replacement to bootstrap up to 1000-by-30? Then... something. I don't quite understand, at this point. If these were two vectors of 1000 points, I'd guess that you're trying to compare the two distributions for a significant difference.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!