-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimpleSubjectSim.m
179 lines (127 loc) · 4.64 KB
/
SimpleSubjectSim.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
%% Monte Carlo Simulation of Ambiguous Decision Making
% Produces estimate of response distribution during stochastic choices in ambiguous decision making task
% Indirect Method
% Initialize variables
tic
h = waitbar(0,'Simulating Simple Data...');
v = [5,6,7,8,10,12,14,16,19,23,27,31,37,44,52,61,73,86,101,120];
p = [.5];
a = [.7];
V = repmat(v,1,2)';
P_temp = ones(20,1)*p;
P = [P_temp(:);.5*ones(20,1)];
A_temp = ones(20,1)*a;
A = [zeros(20,1);A_temp(:)];
trialnumber = length(V);
simnumbs = 10000;
for sims = 1:simnumbs
Cresults = zeros(2,20);
while sum(sum(Cresults==1)) > 35 || sum(sum(Cresults==0)) > 35
Choices = zeros(trialnumber,1);
alpha = .1 + 1.9.*rand(1); %Gains Normal distribution of measured Risk Preferences
%alpha = .97 + .75*randn(1); %Loss
alpha(alpha<0) = 0;
beta = -1 + 2.*rand(1); %Gains Normal distribution of measured Ambiguity Preferences
%beta = -.48 + 1.01*randn(1); %Loss
noise = 0+.2*randn(1);
for i = 1:trialnumber;
if (5^alpha)*(1+noise*randn(1)) > (P(i)*(1-beta*(A(i)/2)))*(V(i)^alpha)*(1+noise*randn(1)); % Subjective Value under ambiguity model Gain
%if (-((5)^alpha))*(1+noise*randn(1)) > (P(i)*(1-beta*(A(i)/2)))*(-(V(i)^alpha))*(1+noise*randn(1)); % Subjective Value under ambiguity model Loss
Choices(i) = 0;
else
Choices(i) = 1;
end
end
%Risk = Choices(1:100);
%Ambiguity = Choices(101:160);
%Vresults = [mean(Risk(and(V(1:100)==5,P(1:100)==.13))),mean(Risk(V(1:100)==8)),mean(Risk(V(1:100)==20)),mean(Risk(V(1:100)==50)),mean(Risk(V(1:100)==125));...
%mean(Ambiguity(V(101:160)==5)),mean(Ambiguity(V(101:160)==8)),mean(Ambiguity(V(101:160)==20)),mean(Ambiguity(V(101:160)==50)),mean(Ambiguity(V(101:160)==125))];
%disp(Vresults)
Cresults = zeros(2,20);
for valindex = 1:20
for riskindex = 1
Cresults(riskindex,valindex) = mean(Choices(V==v(valindex) & P==p(riskindex) & A==0));
end
for ambindex = 2
Cresults(ambindex,valindex) = mean(Choices(and(V==v(valindex),A==a(ambindex-1))));
end
end
end
MultiSubChoices(:,:,sims) = [V,P,A,Choices];
MultiSubResults(:,:,sims) = Cresults;
MultiParams(sims,:) = [alpha,beta];
MultiNoise(sims) = noise;
MultiFOSD(sims) = sum(Cresults(:,1));
waitbar(sims/simnumbs,h)
end
Subindex = 1:simnumbs;
%close(h)
toc
%% Fit Model
tic
base = 0;
model = 'ambigNrisk'
fixed_valueP = 5;
fixed_valueN = -5;
fixed_prob = 1;
% Initialize parameters (this could be smarter)
if strcmp(model,'ambiguity')
b0 = [-1 1]';
elseif strcmp(model,'power')
b0 = [-1 0.8];
elseif strcmp(model, 'ambigNrisk')
b0 = [-1 0.5 0.5]'; %slope, beta, alpha
elseif strcmp(model, 'ambigNriskFixSlope')
b0 = [0.5 0.5]'; %beta, alpha
end
for s = 1:length(Subindex)
%ACTUAL START
%MultiSubChoices(:,:,sims) = [V,P,A,Choices];
% get rid of no choice trials
choice = MultiSubChoices(:,4,s);
vA = MultiSubChoices(:,1,s); %Gains
%vA = -1*MultiSubChoices(:,1,s); %Loss
AL = MultiSubChoices(:,3,s);
pA = MultiSubChoices(:,2,s);
% separate fit for pos
choiceP = choice(find(vA>0));
vP = vA(find(vA>0));
pP = pA(find(vA>0));
AP = AL(find(vA>0));
vFP = fixed_valueP * ones(length(choiceP),1);
pFP = fixed_prob * ones(length(choiceP),1);
[info,p] = fit_ambigNrisk_model_Constrained(choiceP,vFP,vP,pFP,pP,AP,model,b0,base);
if strcmp(model,'ambigNrisk')
slopeP = info.b(1);
aP = info.b(3);
bP = info.b(2);
elseif strcmp(model,'ambigNriskFixSlope')
slopeP = -1;
aP = info.b(2);
bP = info.b(1);
end
r2P = info.r2;
% separate fit for neg
choiceN = choice(find(vA<0));
vN = vA(find(vA<0));
pN = pA(find(vA<0));
AN = AL(find(vA<0));
vFN = fixed_valueN * ones(length(choiceN),1);
pFN = fixed_prob * ones(length(choiceN),1);
[info,p] = fit_ambigNrisk_model_Constrained(~choiceN,-vFN,-vN,pFN,pN,AN,model,b0,base);
if strcmp(model,'ambigNrisk')
slopeN = info.b(1);
aN = info.b(3);
bN = info.b(2);
elseif strcmp(model,'ambigNriskFixSlope')
slopeN = -1;
aN = info.b(2);
bN = info.b(1);
end
r2N = info.r2;
ParamsResults(s,:) = [aP,bP,slopeP,r2P];
%ParamsResults(s,:) = [aN,bN,slopeN,r2N];
waitbar(s/length(Subindex),h,'Fitting Simple Data...')
end
close(h)
toc