-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompileData_PUBLIC.m
More file actions
335 lines (274 loc) · 12.1 KB
/
compileData_PUBLIC.m
File metadata and controls
335 lines (274 loc) · 12.1 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
%% Rens Meerhoff
% 28-03-2019
% Script to generate mockdata for a paper that is in preparation with the
% title: "Exploring a Link Between Commitment to English Language Teaching
% and Student Learning Outcomes" by Moodie and Meerhoff.
%
% NB: Script works as a standalone, but then the teacher data is also
% simulated. For the paper, we used actual teacher data.
clear all
close all
%%
% Create a mock data set that represents the student pre and post test
% scores.
%% User Parameters
% Random numbers are generated along a normal distribution.
% The possibility exists to only accept generated numbers between a pre-defined minimum and/or maximum value.
% To make sure this is feasible, the standard deveiation must be roughly 1/8 of the range between the min and max parameters (assuming the average is in the middle).
%
% The parameters to determine the number of students per teacher.
% Note that the std should be roughly 1/8 of the range between the
% max and min parameters.
minimumNumberOfStudents = 4; % The script will re-generate the random numbers if one teacher has less students than this.
% NB: for student numbers there is no strict upper limit
nAverage = 30;
nStd = 10;
% The parameters to determine the pretest scores.
% Note that the std should be roughly 1/8 of the range between the
% max and min parameters.
pretestParameters.min = 5;
pretestParameters.max = 27-2; % taking max improvement into account
pretestParameters.avg = 15;
pretestParameters.std = 4;
% The parameters to determine the defaultImprovement.
% Note that the std should be roughly 1/8 of the range between the
% max and min parameters.
defaultImprovementParameters.min = -1.5;
defaultImprovementParameters.max = 4;
defaultImprovementParameters.avg = 1.25;
defaultImprovementParameters.std = 0.25;
% Bias in absolute points, where A_top gets on average a bias improvement,
% A_mid gets no improvement/decrement and A_bot gets on average a bias
% decrement.
% NB: Bias MUST BE smaller than or equal to 1
bias = [0.1 0.5 1.0];
%% / User Parameters
%% Input Data
% For the paper, we simulated the students' data, but we used real data
% from the teachers. In this public version of the script, we omitted the
% real teacher data and replaced it with made up data.
nTeachers = 70;
% Teacher IDs as found in "Full lists of pre-post tests non-anonymous.xlsx"
tID = 1 : nTeachers;
% Teacher scores
% 1 = Affective Field
% 2 = Continuance Field
% 3 = Normative Field
% 4 = Affective Work
% 5 = Continuance Work
% 6 = Normative Work
% 7 = Affective (summed)
% 8 = Continuance (summed)
% 9 = Normative (summed)
tScores = createRandomTeacherScores(nTeachers);
%% / Input Data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Generate a string to save the data as
fileString = ['RandomGen_' datestr(now, 'HH-MM-dd-mmm-yyyy')];
%% Student results - create mock data
% Generate the number of students per teacher
% nStudents = generateStudentNumbers(minimumNumberOfStudents, nAverage, nStd, tID);
nStudents = round(genSemiRandom(minimumNumberOfStudents, nAverage, nStd, length(tID)));
% Allocate the teachers to a rank based on total A score
groupsA = getGroupScores(7, tScores);
groupsC = getGroupScores(8, tScores);
groupsN = getGroupScores(9, tScores);
% Plot the student numbers
studentNumberBoxplots(nStudents, fileString, groupsA)
for i = 1:length(bias)
% % The old method
% generateMockData(bias(i), tID, nStudents, A_top, A_mid, A_bot, tScores);
% The new method: normally distributed randomization
generateMockData_normallyDistributed(bias(i), tID, nStudents, groupsA, groupsC, groupsN, tScores, fileString, pretestParameters, defaultImprovementParameters);
end
function generateMockData_normallyDistributed(bias, tID, nStudents, groupsA, groupsC, groupsN, tScores, fileString, pretestParameters, defaultImprovementParameters)
if bias > 1
error('WARNING: Code not adapted to deal with biases larger than 1.')
end
out = [];
minPreTest = pretestParameters.min;
maxPreTest = pretestParameters.max;
avgPreTest = pretestParameters.avg;
stdPreTest = pretestParameters.std;
min_defaultImprovement = defaultImprovementParameters.min;
max_defaultImprovement = defaultImprovementParameters.max;
avg_defaultImprovement = defaultImprovementParameters.avg;
std_defaultImprovement = defaultImprovementParameters.std;
stored_defaultImprovement = [];
stored_correction = [];
stored_actualImprovement = [];
stored_groupsA = [];
stored_groupsC = [];
stored_groupsN = [];
for i = 1:length(tID)
pre = genSemiRandom(minPreTest, avgPreTest, stdPreTest, nStudents(i), maxPreTest);
defaultImprovement = genSemiRandom(min_defaultImprovement, avg_defaultImprovement, std_defaultImprovement, nStudents(i), max_defaultImprovement);
if groupsA(i) == 1
% A_top
% addition between 0 and 2 for bias == 1, improvement of 1 on average
% addition between -0.5 and 1.5 for bias == 0.5, improvement of 0.5 on average
% addition between -0.9 and 1.1 for bias == 0.1, improvement of 0.1 on average
minCorrection = bias - 1;
maxCorrection = bias + 1;
elseif groupsA(i) == 2
% A_mid
% addition between -1 and 1 for all biases, an (additional) improvement of 0 on average
minCorrection = -1;
maxCorrection = 1;
elseif groupsA(i) == 3
% A_bot
% addition between -2 and 0 for bias == 1, decrease of 1 on average
% addition between -1.5 and 0.5 for bias == 0.5, decreaseof 0.5 on average
% addition between -1.1 and 0.9 for bias == 0.1, decrease of 0.1 on average
minCorrection = -1 * (bias + 1);
maxCorrection = -1 * (bias - 1);
else
error('Something went wrong in allocating groups')
end
avgCorrection = (minCorrection + maxCorrection) / 2;
% A quarter of the range
stdCorrection = 0.25 * (maxCorrection - minCorrection) / 2;
correction = genSemiRandom(minCorrection, avgCorrection, stdCorrection, nStudents(i), maxCorrection);
post = pre + defaultImprovement + correction;
for j = 1:nStudents(i)
tmp2(j,:) = tScores(i,:);
tmp3(j,:) = tID(i);
end
percImpr = (post - pre) ./ pre .* 100;
out = [out; post' pre' tmp3 tmp2 percImpr'];
stored_defaultImprovement(end+1: end+length(defaultImprovement)) = defaultImprovement;
stored_correction(end+1: end+length(defaultImprovement)) = correction;
stored_actualImprovement(end+1: end+length(defaultImprovement)) = post - pre;
stored_groupsA(end+1: end+length(defaultImprovement)) = groupsA(i);
stored_groupsC(end+1: end+length(defaultImprovement)) = groupsC(i);
stored_groupsN(end+1: end+length(defaultImprovement)) = groupsN(i);
clear tmp tmp2 tmp3 post pre correction1
end
% Create BoxPlots of stored values
fileString_tmp = [fileString '_boxplot_defaultImprovement_bias(' num2str(bias) ')'];
ystring = 'Default Improvement (absolute points)';
storedVals_Boxplots(stored_defaultImprovement, fileString_tmp, stored_groupsA, ystring)
fileString_tmp = [fileString '_boxplot_improvementCorrection_bias(' num2str(bias) ')'];
ystring = 'Improvement Correction (absolute points)';
storedVals_Boxplots(stored_correction, fileString_tmp, stored_groupsA, ystring)
fileString_tmp = [fileString '_boxplot_simulatedImprovement_bias(' num2str(bias) ')'];
ystring = 'Simulated Improvement (absolute points)';
storedVals_Boxplots(stored_actualImprovement, fileString_tmp, stored_groupsA, ystring)
% Also store the improvement for the other groupings.
storedVals_Boxplots_CN(stored_actualImprovement, fileString_tmp, stored_groupsC, ystring, 'C')
storedVals_Boxplots_CN(stored_actualImprovement, fileString_tmp, stored_groupsN, ystring, 'N')
% NB: Could add a pre-post test plot, but as there is no effect of pre test
% score, this is not (yet) necessary.
output.data = out;
output.dataLabel = {'Post','Pre','tID','A1','C1','N1','A2','C2','N2','A','C','N', 'percImpr'}; % Where A = affective, C = continuance, N = normative
disp(output.dataLabel)
csvwrite([fileString '_mockData_normallyDistributed_' num2str(bias) '.csv'],out,1,0)
end
function number = genSemiRandom(minimumNumber, avg, std, n, maximumNumber)
whilLim = 0;
number = minimumNumber - 1;
secondStatement = 1;
while any(number < minimumNumber) || secondStatement
number = normrnd(avg,std,[1 n]);
whilLim = whilLim + 1;
if whilLim > 10000
error(['WARNING: With the current minimumNumber (' num2str(minimumNumber) ') (and possibly maximumNumber), even after 1000 iterations, no random set was found. Change the <minimumNumber>, or <avg>, or <std>...'])
end
if nargin == 5
secondStatement = any(number > maximumNumber);
else
secondStatement = 0;
end
end
end
function studentNumberBoxplots(nStudents, fileString, groups)
%% OVERALL
h = figure();
boxplot(nStudents)
ylabel('Number of Students per Teacher')
xticks('')
axis([0.75 1.25 0 ceil(max(nStudents)/10)*10])
h.PaperUnits = 'inches';
h.PaperPosition = [0 0 2.5 4];
print( h, '-r300' ,'-dpng' ,['randomGenInfo\' fileString '_boxplot_nStudents.png']) % here you can specify filename extensions
close(h)
%% PER TEACHER RANK
h = figure();
boxplot(nStudents, groups)
ylabel('Number of Students per Teacher')
set(gca,'XTick',[1 2 3],'XTickLabels',{'A_top','A_mid','A_bot'})
axis([0.5 3.5 0 ceil(max(nStudents)/10)*10])
h.PaperUnits = 'inches';
h.PaperPosition = [0 0 4.25 4];
print( h, '-r300' ,'-dpng' ,['randomGenInfo\' fileString '_boxplot_nStudents_per_A_rank.png']) % here you can specify filename extensions
close(h)
end
function storedVals_Boxplots(stored_vals, fileString, stored_groups, ystring)
roundYTicksTo = 3;
ytickmin = floor(min(stored_vals)/roundYTicksTo)*roundYTicksTo;
ytickmax = ceil(max(stored_vals)/roundYTicksTo)*roundYTicksTo;
%% OVERALL
h = figure();
boxplot(stored_vals)
ylabel(ystring)
xticks('')
axis([0.75 1.25 ytickmin ytickmax])
h.PaperUnits = 'inches';
h.PaperPosition = [0 0 2.5 4];
print( h, '-r300' ,'-dpng' ,['randomGenInfo\' fileString '.png']) % here you can specify filename extensions
close(h)
%% PER TEACHER RANK
h = figure();
boxplot(stored_vals, stored_groups)
ylabel(ystring)
set(gca,'XTick',[1 2 3],'XTickLabels',{'A_top','A_mid','A_bot'})
axis([0.5 3.5 ytickmin ytickmax])
h.PaperUnits = 'inches';
h.PaperPosition = [0 0 4.25 4];
print( h, '-r300' ,'-dpng' ,['randomGenInfo\' fileString '_per_A_rank.png']) % here you can specify filename extensions
close(h)
end
function storedVals_Boxplots_CN(stored_vals, fileString, stored_groups, ystring,ord)
roundYTicksTo = 3;
ytickmin = floor(min(stored_vals)/roundYTicksTo)*roundYTicksTo;
ytickmax = ceil(max(stored_vals)/roundYTicksTo)*roundYTicksTo;
% %% OVERALL
% h = figure();
% boxplot(stored_vals)
% ylabel(ystring)
% xticks('')
% axis([0.75 1.25 ytickmin ytickmax])
% h.PaperUnits = 'inches';
% h.PaperPosition = [0 0 2.5 4];
% print( h, '-r300' ,'-dpng' ,['randomGenInfo\' fileString '.png']) % here you can specify filename extensions
% close(h)
%% PER TEACHER RANK
h = figure();
boxplot(stored_vals, stored_groups)
ylabel(ystring)
set(gca,'XTick',[1 2 3],'XTickLabels',{[ord '_top'],[ord '_mid'],[ord '_bot']})
axis([0.5 3.5 ytickmin ytickmax])
h.PaperUnits = 'inches';
h.PaperPosition = [0 0 4.25 4];
print( h, '-r300' ,'-dpng' ,['randomGenInfo\' fileString '_per_' ord '_rank.png']) % here you can specify filename extensions
close(h)
end
function groups = getGroupScores(col, tScores)
[~,tmp] = sort(tScores(:,col));
steps = floor(length(tScores)/3);
groups = tmp;
groups(tmp(1:steps)) = 3; % bottom
groups(tmp(steps +1:steps *2)) = 2; % middle
groups(tmp(steps*2 +1:end)) = 1; % top
end
function tScores = createRandomTeacherScores(nTeachers)
tScores = NaN(nTeachers, 9);
for i = 1:6
tScores(:,i) = randi(35, nTeachers, 1);
end
for i = 1:3
tScores(:,i + 6) = sum(tScores(:,[i i+3]),2);
end
end