-
Notifications
You must be signed in to change notification settings - Fork 0
/
counterbalance.m
186 lines (148 loc) · 5.93 KB
/
counterbalance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function [c] = counterbalance(ppnr)
% Inequality UG
% Inge
% 2017-11-07
%
% Counterbalancing
%
% 3 (wealth participant) x 3 (wealth other) x 6 (offer: 0, 25, 50, 75, 100)
% within subjects design, all possible combinations are repeated six
% times.
%
% wealth participant blocked and counterbalanced between participants
try
% Set different seed for every participant
rng shuffle
%% Set parameters
wealth = [1.9,7.5,30];
offer = 0.1:0.1:0.6;
offerRep = [5,4,3,3,5,2];
wealthO = [1,2,3];
wealthPP_order = [[1,2,3];[1,3,2];[2,1,3];[2,3,1];[3,1,2];[3,2,1]];
wealthPP = wealthPP_order(mod(ppnr,6)+1,:);
%% Create all trials
offers = zeros(sum(offerRep)*length(wealthO),2);
count = 1;
for k = 1:length(wealthO)
for i = 1:length(offer)
for j = 1:offerRep(i)
offers(count,:) = [wealth(k), offer(i)];
count = count +1;
end
end
end
%% make randomisation
nbtrials = (sum(offerRep)*length(wealthPP));
trials = zeros(sum(offerRep)*length(wealthO)*length(wealthPP),10);
trials(:,1) = repmat(ppnr,1,nbtrials*length(wealthPP));
trials(:,2) = 1:size(trials,1);
trials(:,3) = repmat(1:nbtrials,1,length(wealthPP));
for k = 1:length(wealthPP)
randCheck = 1;
cycle = 1;
while randCheck
offersS = offers(shuffle(1:size(offers,1)),:);
wOS = 0;
oS = 0;
for i = 1:size(offers,1)
if i ~= size(offers,1)
%Check wealth other previous trial
if offersS(i+1,1) == offersS(i,1)
wOS = wOS +1;
else
wOS = 0;
end
%Check offer previous trial
if offersS(i+1,2) == offersS(i,2)
oS = oS +1;
else
oS = 0;
end
%If three reps of wealth other or offer, shuffle again.
if wOS > 2 || oS > 2
cycle = cycle + 1;
break
end
else
randCheck = 0;
break
end
end
end
trials((nbtrials*(k-1))+1:(nbtrials*(k-1))+nbtrials,4) = repmat(k,1,nbtrials);
trials((nbtrials*(k-1))+1:(nbtrials*(k-1))+nbtrials,5) = repmat(wealth(wealthPP(k)),1,nbtrials);
trials((nbtrials*(k-1))+1:(nbtrials*(k-1))+nbtrials,6:7) = offersS;
end
%% Fixation cross jitter
% fMRI
% jitter_1 = 2:(3/89):5;
% jitter_2 = 2:(3/89):5;
% jitter_3 = 2:(3/89):5;
% fixed randomized jitters for 2 fixation crosses
% jitter between
start = 2;
stop = 4;
trials(:,8:10) = [shuffle(start:((stop-start)/(nbtrials-1)):stop)',...
shuffle(start:((stop-start)/(nbtrials-1)):stop)',...
shuffle(start:((stop-start)/(nbtrials-1)):stop)';...
shuffle(start:((stop-start)/(nbtrials-1)):stop)',...
shuffle(start:((stop-start)/(nbtrials-1)):stop)',...
shuffle(start:((stop-start)/(nbtrials-1)):stop)';...
shuffle(start:((stop-start)/(nbtrials-1)):stop)',...
shuffle(start:((stop-start)/(nbtrials-1)):stop)',...
shuffle(start:((stop-start)/(nbtrials-1)):stop)'];
%Initials other player
trials(:,11:12) = player_numbers(size(trials,1));
%L/R Accept/Reject counterbalancing
trials(:,13) = [shuffle([zeros(1,length(wealthO)*(sum(offerRep)/2)), ones(1,length(wealthO)*(sum(offerRep)/2))]),...
shuffle([zeros(1,length(wealthO)*(sum(offerRep)/2)), ones(1,length(wealthO)*(sum(offerRep)/2))]),...
shuffle([zeros(1,length(wealthO)*(sum(offerRep)/2)), ones(1,length(wealthO)*(sum(offerRep)/2))])];
c.header = {'ppnr', 'trial', 'blocktrial','block','wealthPP','wealthO','offer','jitter1','jitter2','jitter3', 'initial1', 'initial2', 'LR'};
c.trials = trials;
% %% Load offer images
%
%
% %Stimulus direcotry
% stimdir = [cd '/Pictures_SP/'];
% %% Prepare Stimuli %%
%
% %Read all filenames
% listing = dir(stimdir);
% filenames = char(listing.name);
%
% %first two entries are non informative
% filenames(1:2,:) = [];
% %filenames(end,:) = [];
%
%
% %Save filenames
% c.filenames = filenames;
%
% % Read images and add to variable
% images = zeros(720, 960, 3, length(filenames(:,1)), 'uint8');
%
% for i = 1:(length(filenames(:,1)))
%
% [~,~,ext] = fileparts(filenames(i,:));
% if strcmp(strtrim(ext), strtrim('.jpg'))
% % Read image from stiminfo
% tmpimg = imread([stimdir, filenames(i,:)], 'jpg');
%
% % Store in new variable
% images(:,:,:,i) = tmpimg;
% else
% continue
% end
%
% end
%
% c.images = images;
catch me
fprintf('Error in counterbalancing script\n');
me.message
me.stack
me.stack.line
Screen('CloseAll');
return
end
end