-
Notifications
You must be signed in to change notification settings - Fork 1
/
OPMA functions - r.vb
1553 lines (1445 loc) · 56.3 KB
/
OPMA functions - r.vb
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' Open Psychometric Meta-Analyis (Excel)
' Created by Brenton M. Wiernik
' version 1.0.1
' Open Psychometric Meta-Analysis (Excel) -- VBA scripts for conducting psychometric
' meta-analysis using Microsoft Excel.
' Copyright (C) 2017 Brenton M. Wiernik.
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' Variable list:
' k = number of effect sizes
' nRyy = number of reliability (ryy) values
' R = matrix of effect sizes and sample sizes
' RY = matrix of ryy values and frequencies
' Ntotal = total sample size (N)
' sumR = weighted sumR of uncorrected d values
' meanR = weighted average uncorrected d value
' SampErrVar = Expected sampling error
' ObsSSQ = Observed Sums of Squares
' ObsVar = Observed variance of effect sizes
' SDobs = Observed SD of effect sizes
' PercentVarSamp = Percent of observed effect size variance due to sampling error
' SumRyy = Sum of y measure reliabilities
' SumRyyFreq = Sum of reliability frequencies
' SumRyySq = Sum of squared y measure reliabilities
' MeanRyy = Mean y measure reliability
' SDRyy = SD of y measure reliabilities
' SumQualy = Sum of y measure qualities (sqrt of reliability)
' MeanQualy = Mean y measure quality (sqrt of reliability)
' SDQualy = SD of y measure qualities (sqrt of reliabilities)
' Rho = estimated mean true d effect size
' Ratten = Attenuated d value for a particular ryy value
' RattenWeighted = Weighted attenuated d value for a particular ryy value
' SumRatten = Sum of attenuated d values
' SumRattenSq = Sum of squared attenuated d values
' ArtVar = Expected variance due to artifacts
' ResVar = Residual Variance of effect sizes
' SDres = Residual SD of effect sizes
' SDpred = Predicted SD of effect sizes
' PerVarAcc = Percent of variance in effect sizes accounted for
' SDrho = True effect standard deviation
' SEmeanR = Standard error of mean d
' df = Degrees of freedom for confidence interval when k < 30
' Crit = Critical value for confidence interval when k < 30
' UpCIdelta = Upper value of 80% confidence interval for delta
' LoCIdelta = Lower value of 80% confidence interval for delta
' UpCImeanR = Upper value of 80% confidence interval for mean d
' LoCImeanD = Lower value of 80% confidence interval for mean d
' UpCVdelta = Upper value of 80% credibility interval for delta
' LoCVdelta = Lower value of 80% credibility interval for delta
' UpCVmeanD = Upper value of 80% credibility interval for mean d
' LoCVmeanD = Lower value of 80% credibility interval for mean d
Function IsMac() As Boolean
#If Mac Then
IsMac = True
#End If
End Function
Function Is64BitOffice() As Boolean
#If Win64 Then
Is64BitOffice = True
#End If
End Function
Function Excelversion() As Double
'Win Excel versions are always a whole number (15)
'Mac Excel versions show also the number of the update (15.29)
Excelversion = Val(Application.Version)
End Function
Function NeedCompatMode() As Boolean
#If IsMac Then
#If Excelversion < 15 Then
NeedCompatMode = True
#Else
NeedCompatMode = False
#End If
#Else
#If Excelversion < 14 Then
NeedCompatMode = True
#Else
NeedCompatMode = False
#End If
#End If
End Function
Function TruncNorm(Min As Double, Max As Double, Mean As Variant, SD As Variant)
Randomize ' Initialize the random number generator
CompatMode = NeedCompatMode
If CompatMode Then
MinD = WorksheetFunction.NormDist(Min, Mean, SD, True)
MaxD = Rnd() * (WorksheetFunction.NormDist(Max, Mean, SD, True) - WorksheetFunction.NormDist(Min, Mean, SD, True))
RangeD = MinD + MaxD
TruncNorm = WorksheetFunction.NormInv(RangeD, Mean, SD)
Else
MinD = WorksheetFunction.Norm_Dist(Min, Mean, SD, True)
MaxD = Rnd() * (WorksheetFunction.Norm_Dist(Max, Mean, SD, True) - WorksheetFunction.Norm_Dist(Min, Mean, SD, True))
RangeD = MinD + MaxD
TruncNorm = WorksheetFunction.Norm_Inv(RangeD, Mean, SD)
End If
End Function
Sub MetaAnalysisR()
' Turn off screen updating for efficiency
Application.ScreenUpdating = False
' Set up control parameters based on OS version and options set via worksheet controls
CompatMode = NeedCompatMode
Dim alert As Integer
' Set alert flag counter to zero and reset all flags
flags = 0
FlagRxxOver = vbNullString
FlagQualxUnder = vbNullString
FlagNoSDQualx = vbNullString
FlagQualyUnder = vbNullString
FlagNoSDQualy = vbNullString
' ==================================
' === Choose meta-analytic model ===
' ==================================
' TODO: Add alternative weighting methods
' === Weighting method options =====
' If Worksheets("Correlations").Shapes("WtTotal").ControlFormat.Value = 1 Then
' Weights = "Total"
' ElseIf Worksheets("Correlations").Shapes("WtUnit").ControlFormat.Value = 1 Then
' Weights = "Unit"
' ElseIf Worksheets("Correlations").Shapes("WtInvSamp").ControlFormat.Value = 1 Then
' Weights = "InvSamp"
' Else
' alert = MsgBox ("Error: Please select a weighting method", vbCritical, "Choose an option")
' Exit Sub
' End If
' === Artifact correction options ===
' ===== Reliability in X (Rxx) ======
If Worksheets("rxx").Shapes("NoDistx").ControlFormat.Value = 1 Then
CorrectRxx = False
ElseIf Worksheets("rxx").Shapes("NewDistx").ControlFormat.Value = 1 Then
CorrectRxx = True
SpecDistx = False
ElseIf Worksheets("rxx").Shapes("SpecDistx").ControlFormat.Value = 1 Then
CorrectRxx = True
SpecDistx = True
Else
alert = MsgBox("Error: Please an option for correcting for unreliability in X", vbCritical, "Choose an option")
Exit Sub
End If
If Worksheets("rxx").Shapes("RelUnrestx").ControlFormat.Value = 1 Then
RelUnrestx = True
ElseIf Worksheets("rxx").Shapes("RelRestx").ControlFormat.Value = 1 Then
RelUnrestx = False
ElseIf CorrectRxx Then
alert = MsgBox("Error: Please indicate whether reliability values for X are from the restricted (incumbent) or unrestricted (applicant) group", vbCritical, "Choose an option")
Exit Sub
End If
' ===== Reliability in Y (Ryy) ======
' TODO: Allow specification of whether reliabilities for Y are from restricted or unrestricted population
If Worksheets("ryy").Shapes("NoDisty").ControlFormat.Value = 1 Then
CorrectRyy = False
ElseIf Worksheets("ryy").Shapes("NewDisty").ControlFormat.Value = 1 Then
CorrectRyy = True
SpecDisty = False
ElseIf Worksheets("ryy").Shapes("SpecDisty").ControlFormat.Value = 1 Then
CorrectRyy = True
SpecDisty = True
Else
alert = MsgBox("Error: Please an option for correcting for unreliability in Y", vbCritical, "Choose an option")
Exit Sub
End If
' ======== Range restriction ========
If Worksheets("RR").Shapes("NoDistu").ControlFormat.Value = 1 Then
CorrectRR = False
ElseIf Worksheets("RR").Shapes("NewDistu").ControlFormat.Value = 1 Then
CorrectRR = True
SpecDistu = False
ElseIf Worksheets("RR").Shapes("SpecDistu").ControlFormat.Value = 1 Then
CorrectRR = True
SpecDistu = True
Else
alert = MsgBox("Error: Please an option for correcting for range restriction", vbCritical, "Choose an option")
Exit Sub
End If
If Worksheets("RR").Shapes("RRdirect").ControlFormat.Value = 1 Then
rrDirect = True
rrIndirect = False
ElseIf Worksheets("RR").Shapes("RRindirect").ControlFormat.Value = 1 Then
rrDirect = False
rrIndirect = True
ElseIf CorrectRR Then
alert = MsgBox("Error: Please choose either direct or indirect range restriction", vbCritical, "Choose an option")
Exit Sub
End If
If Worksheets("RR").Shapes("ux").ControlFormat.Value = 1 Then
Observedu = True
ElseIf Worksheets("RR").Shapes("uT").ControlFormat.Value = 1 Then
Observedu = False
ElseIf CorrectRR And Not SpecDistu Then
alert = MsgBox("Error: Please choose whether the u values in Column A are for observed scores (ux) or true scores (uT)", vbCritical, "Choose an option")
Exit Sub
End If
' =====================================
' ===== Get data to meta-analyze ======
' =====================================
' === Correlations and sample sizes ===
k = Application.Count(Worksheets("Correlations").Range("A:A"))
kN = Application.Count(Worksheets("Correlations").Range("B:B"))
ReDim R(k, 2)
For i = 1 To k
R(i, 1) = Worksheets("Correlations").Cells(i + 1, 1).Value
R(i, 2) = Worksheets("Correlations").Cells(i + 1, 2).Value
Next i
' Error messages for faulty data
If k = 0 Then
alert = MsgBox("Error: No correlations entered in Column A of Correlations page", vbCritical, "Missing information")
Exit Sub
ElseIf k < kN Then
alert = MsgBox("Error: One or more correlations missing. Please check data entered in Column A of Correlations page.", vbCritical, "Missing information")
Exit Sub
ElseIf k > kN Then
alert = MsgBox("Error: One or more sample sizes missing. Please check data entered in Column B of Correlations page.", vbCritical, "Missing information")
Exit Sub
ElseIf Application.Sum(Worksheets("Correlations").Range("A:A")) > Application.Sum(Worksheets("Correlations").Range("B:B")) Then
alert = MsgBox("Error: It appears that you have entered correlations and sample sizes in the wrong columns. Please check data entered on the Correlations page.", vbCritical, "Check data")
Exit Sub
End If
' ========= Reliability of X ==========
' New rxx distribution
If CorrectRxx And Not SpecDistx Then
' Get rxx data
nRxx = Application.Count(Worksheets("rxx").Range("A:A"))
ReDim RX(nRxx, 2)
For i = 1 To nRxx
RX(i, 1) = Worksheets("rxx").Cells(i + 1, 1).Value
RX(i, 2) = Worksheets("rxx").Cells(i + 1, 2).Value
Next i
' Compute rxx distribution
SumRxx = 0
SumRxxFreq = 0
SumRxxSq = 0
SumQualx = 0
For i = 1 To nRxx
SumRxx = SumRxx + RX(i, 1) * RX(i, 2)
SumRxxSq = SumRxxSq + (RX(i, 1) ^ 2) * RX(1, 2)
SumQualx = SumQualx + Sqr(RX(i, 1)) * RX(i, 2)
SumRxxFreq = SumRxxFreq + RX(i, 2)
Next i
MeanRxx = SumRxx / SumRxxFreq
SDRxx = Sqr(WorksheetFunction.Max(0, (SumRxxSq / SumRxxFreq) - (SumRxx / SumRxxFreq) ^ 2))
MeanQualx = SumQualx / SumRxxFreq
SDQualx = Sqr(WorksheetFunction.Max(0, (SumRxx / SumRxxFreq) - (SumQualx / SumRxxFreq) ^ 2))
' Prespecified rxx distribution
ElseIf CorrectRxx And SpecDistx Then
If IsEmpty(Worksheets("rxx").Cells(8, 5)) Then
noMeanRxx = True
Else
noMeanRxx = False
End If
If IsEmpty(Worksheets("rxx").Cells(9, 5)) Then
noSDRxx = True
Else
noSDRxx = False
End If
If IsEmpty(Worksheets("rxx").Cells(11, 5)) Then
noMeanQualx = True
Else
noMeanQualx = False
End If
If IsEmpty(Worksheets("rxx").Cells(12, 5)) Then
noSDQualx = True
Else
noSDQualx = False
End If
If noMeanRxx And noSDRxx And noMeanQualx And noSDQualx Then
alert = MsgBox("Error: Please enter prespecified artifact distribution values for reliability in X", vbCritical, "Missing information")
Exit Sub
End If
' Mean Rxx
If noMeanRxx Then
If noMeanQualx Then
alert = MsgBox("Error: Please enter mean artifact distribution values for reliability in X", vbCritical, "Missing information")
Exit Sub
ElseIf noSDQualx Then
MeanQualx = Worksheets("rxx").Cells(11, 5).Value
MeanRxx = MeanQualx * MeanQualx
FlagRxxOver = "* Mean rxx estimated as mean(" & ChrW(8730) & "rxx) squared because no SD given for " & ChrW(8730) & "rxx. Range restriction estimates are slightly inaccurate."
flags = flags + 1
Else
MeanQualx = Worksheets("rxx").Cells(11, 5).Value
SDQualx = Worksheets("rxx").Cells(12, 5).Value
ReDim RqX(1000, 1)
For i = 1 To 1000
RqX(i, 1) = TruncNorm(0, 1.1, MeanQualx, SDQualx)
Next i
SumRxx = 0
For i = 1 To 1000
SumRxx = SumRxx + RqX(i, 1) * RqX(i, 1)
Next i
MeanRxx = SumRxx / 1000
End If
Else
MeanRxx = Worksheets("rxx").Cells(8, 5).Value
End If
' SD Rxx
SDRxx = Worksheets("rxx").Cells(9, 5).Value ' SDRxx is not used in any meta-analysis equation, so it does not need to be estimated if missing.
' Mean and SD Qualx
If noMeanQualx Or noSDQualx Then
If noSDRxx Then
If noMeanQualx Then
MeanQualx = Sqr(MeanRxx)
FlagQualxUnder = "* Mean " & ChrW(8730) & "rxx estimated as " & ChrW(8730) & "mean(rxx) because no SD given for rxx. Estimated " & ChrW(961) & " is a slight underestimate."
flags = flags + 1
Else
MeanQualx = Worksheets("rxx").Cells(11, 5).Value
End If
If noSDQualx Then
SDQualx = 0
FlagNoSDQualx = "* No SD given for reliability of X (rxx) or square root of reliability of X. Values of zero assumed. SD" & ChrW(961) & " is an overestimate."
flags = flags + 1
Else
SDQualx = Worksheets("rxx").Cells(12, 5).Value
End If
Else
ReDim RX(1000, 1)
For i = 1 To 1000
RX(i, 1) = TruncNorm(0, 1.1, MeanRxx, SDRxx)
Next i
SumQualx = 0
SumRxx = 0
For i = 1 To 1000
SumQualx = SumQualx + Sqr(RX(i, 1))
SumRxx = SumRxx + RX(i, 1)
Next i
If noMeanQualx Then
MeanQualx = SumQualx / 1000
Else
MeanQualx = Worksheets("rxx").Cells(11, 5).Value
End If
If noSDQualx Then
SDQualx = Sqr((SumRxx / 1000) - (SumQualx / 1000) ^ 2)
Else
SDQualx = Worksheets("rxx").Cells(12, 5).Value
End If
End If
Else
MeanQualx = Worksheets("rxx").Cells(11, 5).Value
SDQualx = Worksheets("rxx").Cells(12, 5).Value
End If
ElseIf Not CorrectRxx Then
nRxx = 1
MeanRxx = 1
MeanQualx = 1
MeanQualxa = 1
MeanQualxi = 1
MeanRxxa = 1
MeanRxxi = 1
SDRxx = 0
SDQualx = 0
SDRxxa = 0
SDRxxi = 0
SDQualxa = 0
SDQualxi = 0
ReDim RX(1, 2)
RX(1, 1) = 1
RX(1, 2) = 1
End If
' ========= Reliability of Y ==========
' New ryy distribution
If CorrectRyy And Not SpecDisty Then
' Get ryy data
nRyy = Application.Count(Worksheets("ryy").Range("A:A"))
ReDim RY(nRyy, 2)
For i = 1 To nRyy
RY(i, 1) = Worksheets("ryy").Cells(i + 1, 1).Value
RY(i, 2) = Worksheets("ryy").Cells(i + 1, 2).Value
Next i
' Compute ryy distribution
SumRyy = 0
SumRyyFreq = 0
SumRyySq = 0
SumQualy = 0
For i = 1 To nRyy
SumRyy = SumRyy + RY(i, 1) * RY(i, 2)
SumRyySq = SumRyySq + (RY(i, 1) ^ 2) * RY(1, 2)
SumQualy = SumQualy + Sqr(RY(i, 1)) * RY(i, 2)
SumRyyFreq = SumRyyFreq + RY(i, 2)
Next i
MeanRyy = SumRyy / SumRyyFreq
SDRyy = Sqr(WorksheetFunction.Max(0, (SumRyySq / SumRyyFreq) - (SumRyy / SumRyyFreq) ^ 2))
MeanQualy = SumQualy / SumRyyFreq
SDQualy = Sqr(WorksheetFunction.Max(0, (SumRyy / SumRyyFreq) - (SumQualy / SumRyyFreq) ^ 2))
' Prespecified ryy distribution
ElseIf CorrectRyy And SpecDisty Then
If IsEmpty(Worksheets("ryy").Cells(8, 5)) Then
noMeanRyy = True
Else
noMeanRyy = False
End If
If IsEmpty(Worksheets("ryy").Cells(9, 5)) Then
noSDRyy = True
Else
noSDRyy = False
End If
If IsEmpty(Worksheets("ryy").Cells(11, 5)) Then
noMeanQualy = True
Else
noMeanQualy = False
End If
If IsEmpty(Worksheets("ryy").Cells(12, 5)) Then
noSDQualy = True
Else
noSDQualy = False
End If
If noMeanRyy And noSDRyy And noMeanQualy And noSDQualy Then
alert = MsgBox("Error: Please enter prespecified artifact distribution values for reliability in Y", vbCritical, "Missing information")
Exit Sub
End If
' Mean ryy
MeanRyy = Worksheets("ryy").Cells(8, 5).Value ' Mean Ryy is not used in any meta-analysis equation, so it does not need to be estimated if missing.
' SD Ryy
SDRyy = Worksheets("ryy").Cells(9, 5).Value ' SDRyy is not used in any meta-analysis equation, so it does not need to be estimated if missing.
' Mean and SD Qualy
If noMeanQualy Or noSDQualy Then
If noSDRyy Then
If noMeanQualy Then
MeanQualy = Sqr(MeanRyy)
FlagQualyUnder = "* Mean " & ChrW(8730) & "ryy estimated as " & ChrW(8730) & "mean(ryy) because no SD given for ryy. Estimated " & ChrW(961) & " is a slight underestimate."
flags = flags + 1
Else
MeanQualy = Worksheets("ryy").Cells(11, 5).Value
End If
If noSDQualy Then
SDQualy = 0
FlagNoSDQualy = "* No SD given for reliability of Y (ryy) or square root of reliability of Y. Values of zero assumed. SD" & ChrW(961) & " is an overestimate."
flags = flags + 1
Else
SDQualy = Worksheets("ryy").Cells(12, 5).Value
End If
Else
ReDim RY(1000, 1)
For i = 1 To 1000
RY(i, 1) = TruncNorm(0, 1.1, MeanRyy, SDRyy)
Next i
SumQualy = 0
SumRyy = 0
For i = 1 To 1000
SumQualy = SumQualy + Sqr(RY(i, 1))
SumRyy = SumRyy + RY(i, 1)
Next i
If noMeanQualy Then
MeanQualy = SumQualy / 1000
Else
MeanQualy = Worksheets("ryy").Cells(11, 5).Value
End If
If noSDQualy Then
SDQualy = Sqr((SumRyy / 1000) - (SumQualy / 1000) ^ 2)
Else
SDQualy = Worksheets("ryy").Cells(12, 5).Value
End If
End If
Else
MeanQualy = Worksheets("ryy").Cells(11, 5).Value
SDQualy = Worksheets("ryy").Cells(12, 5).Value
End If
ElseIf Not CorrectRyy Then
nRyy = 1
MeanRyy = 1
MeanQualy = 1
SDRyy = 0
SDQualy = 0
ReDim RY(1, 2)
RY(1, 1) = 1
RY(1, 2) = 1
End If
' ========= Range restriction ==========
' New u distribution
If CorrectRR And Not SpecDistu Then
' Get u data
nU = Application.Count(Worksheets("RR").Range("A:A"))
ReDim U(nU, 2)
For i = 1 To nU
U(i, 1) = Worksheets("RR").Cells(i + 1, 1).Value
U(i, 2) = Worksheets("RR").Cells(i + 1, 2).Value
Next i
' Compute u distribution
SumU = 0
SumUFreq = 0
SumUSq = 0
For i = 1 To nU
SumU = SumU + U(i, 1) * U(i, 2)
SumUSq = SumUSq + (U(i, 1) ^ 2) * U(1, 2)
SumUFreq = SumUFreq + U(i, 2)
Next i
MeanU = SumU / SumUFreq
SDu = Sqr(WorksheetFunction.Max(0, (SumUSq / SumUFreq) - (SumU / SumUFreq) ^ 2))
MeanBigU = 1 / MeanU
' Prespecified u distribution
ElseIf CorrectRR And SpecDistu Then
If IsEmpty(Worksheets("RR").Cells(13, 5)) Then
noMeanux = True
Else
noMeanux = False
End If
If IsEmpty(Worksheets("RR").Cells(14, 5)) Then
noSDux = True
Else
noSDux = False
End If
If IsEmpty(Worksheets("RR").Cells(16, 5)) Then
noMeanuT = True
Else
noMeanuT = False
End If
If IsEmpty(Worksheets("RR").Cells(17, 5)) Then
noSDuT = True
Else
noSDuT = False
End If
If noMeanux And noSDux And noMeanuT And noSDQualuT Then
alert = MsgBox("Error: Please enter prespecified artifact distribution values for range restriction", vbCritical, "Missing information")
Exit Sub
End If
Meanux = Worksheets("RR").Cells(13, 5)
SDux = Worksheets("RR").Cells(14, 5)
MeanuT = Worksheets("RR").Cells(16, 5)
SDuT = Worksheets("RR").Cells(17, 5)
If Not noMeanux Then MeanBigUx = 1 / Meanux
If Not noMeanuT Then MeanBigUT = 1 / MeanuT
ElseIf Not CorrectRR Then
nU = 1
MeanU = 1
MeanBigU = 1
SDu = 0
ReDim U(1, 2)
U(1, 1) = 1
U(1, 2) = 1
End If
' =====================================================
' ===== Transform artifacts for range restriction =====
' =====================================================
' This section of the program computes values for the distributions of rxx_i, rxx_a, ux, and uT if they are not already present
If CorrectRR Then ' Skip this if not correcting for range restriction
If CorrectRxx Then ' If not correcting for measurement error, then ux and uT are the same
' ===== Reliability in X =====
If Not RelUnrestx Then
MeanRxxi = MeanRxx
SDRxxi = SDRxx
MeanQualxi = MeanQualx
SDQualxi = SDQualx
If SpecDistx Then
If SpecDistu Then
If noMeanux Then
Meanux = Sqr((MeanuT ^ 2) / (MeanuT ^ 2 + MeanRxxi * (1 - MeanuT ^ 2)))
MeanBigUx = 1 / Meanux
End If
MeanRxxa = 1 - (Meanux ^ 2 * (1 - MeanRxxi))
If Not IsEmpty(SDRxxi) Then SDRxxa = Sqr(WorksheetFunction.Max(0, 1 + (Meanux ^ 2 * (Meanux ^ 2 - 2)) + (2 * Meanux ^ 2 * MeanRxxi * (1 - Meanux ^ 2)) + (Meanux ^ 4 * (SDRxxi ^ 2 + MeanRxxi ^ 2)) - MeanRxxa ^ 2))
MeanQualxa = 1 - (Meanux ^ 2 * (1 - MeanQualxi))
SDQualxa = Sqr(WorksheetFunction.Max(0, MeanRxxa - MeanQualxa ^ 2))
ElseIf Not SpecDistu Then
If Observedu Then
MeanRxxa = 1 - (MeanU ^ 2 * (1 - MeanRxxi))
If Not IsEmpty(SDRxxi) Then SDRxxa = Sqr(WorksheetFunction.Max(0, 1 + (MeanU ^ 2 * (MeanU ^ 2 - 2)) + (2 * MeanU ^ 2 * MeanRxxi * (1 - MeanU ^ 2)) + (MeanU ^ 4 * (SDRxxi ^ 2 + MeanRxxi ^ 2)) - MeanRxxa ^ 2))
MeanQualxa = 1 - (MeanU ^ 2 * (1 - MeanQualxi))
SDQualxa = Sqr(WorksheetFunction.Max(0, MeanRxxa - MeanQualxa ^ 2))
ElseIf Not Observedu Then
Meanux = Sqr((MeanU ^ 2) / (MeanU ^ 2 + MeanRxxi * (1 - MeanU ^ 2)))
MeanRxxa = 1 - (Meanux ^ 2 * (1 - MeanRxxi))
If Not IsEmpty(SDRxxi) Then SDRxxa = Sqr(WorksheetFunction.Max(0, 1 + (Meanux ^ 2 * (Meanux ^ 2 - 2)) + (2 * Meanux ^ 2 * MeanRxxi * (1 - Meanux ^ 2)) + (Meanux ^ 4 * (SDRxxi ^ 2 + MeanRxxi ^ 2)) - MeanRxxa ^ 2))
MeanQualxa = 1 - (Meanux ^ 2 * (1 - MeanQualxi))
SDQualxa = Sqr(WorksheetFunction.Max(0, MeanRxxa - MeanQualxa ^ 2))
End If
End If
ElseIf Not SpecDistx Then
ReDim RXi(nRxx, 2)
RXi = RX
ReDim RXa(nRxx, 2)
If SpecDistu Then
If Not noMeanux Then
For i = 1 To nRxx
RXa(i, 1) = 1 - (Meanux ^ 2 * (1 - RXi(i, 1)))
RXa(i, 2) = RXi(i, 2)
Next i
ElseIf noMeanux Then
Meanux = Sqr((MeanuT ^ 2) / (MeanuT ^ 2 + MeanRxxi * (1 - MeanuT ^ 2)))
For i = 1 To nRxx
RXa(i, 1) = 1 - (Meanux ^ 2 * (1 - RXi(i, 1)))
RXa(i, 2) = RXi(i, 2)
Next i
End If
ElseIf Not SpecDistu Then
If Observedu Then
For i = 1 To nRxx
RXa(i, 1) = 1 - (MeanU ^ 2 * (1 - RXi(i, 1)))
RXa(i, 2) = RXi(i, 2)
Next i
ElseIf Not Observedu Then
Meanux = Sqr((MeanU ^ 2) / (MeanU ^ 2 + MeanRxxi * (1 - MeanU ^ 2)))
For i = 1 To nRxx
RXa(i, 1) = 1 - (Meanux ^ 2 * (1 - RXi(i, 1)))
RXa(i, 2) = RXi(i, 2)
Next i
End If
End If
' Compute new rxx_a distribution values
SumRxx = 0
SumRxxSq = 0
SumQualx = 0
For i = 1 To nRxx
SumRxx = SumRxx + RXa(i, 1) * RXa(i, 2)
SumRxxSq = SumRxxSq + (RXa(i, 1) ^ 2) * RXa(1, 2)
SumQualx = SumQualx + Sqr(RXa(i, 1)) * RXa(i, 2)
Next i
MeanRxxa = SumRxx / SumRxxFreq
SDRxxa = Sqr(WorksheetFunction.Max(0, (SumRxxSq / SumRxxFreq) - (SumRxx / SumRxxFreq) ^ 2))
MeanQualxa = SumQualx / SumRxxFreq
SDQualxa = Sqr(WorksheetFunction.Max(0, (SumRxx / SumRxxFreq) - (SumQualx / SumRxxFreq) ^ 2))
End If
ElseIf RelUnrestx Then
MeanRxxa = MeanRxx
SDRxxa = SDRxx
MeanQualxa = MeanQualx
SDQualxa = SDQualx
If SpecDistx Then
If SpecDistu Then
If noMeanux Then
Meanux = Sqr((MeanRxxa * MeanuT ^ 2) - MeanRxxa + 1)
MeanBigUx = 1 / Meanux
End If
MeanRxxi = 1 - (MeanBigUx ^ 2 * (1 - MeanRxxa)) ' TODO: Handle the problem with very low ux and rxxa
If Not IsEmpty(SDRxxa) Then SDRxxi = Sqr(WorksheetFunction.Max(0, 1 + (MeanBigUx ^ 2 * (MeanBigUx ^ 2 - 2)) + (2 * MeanBigUx ^ 2 * MeanRxxa * (1 - MeanBigUx ^ 2)) + (MeanBigUx ^ 4 * (SDRxxa ^ 2 + MeanRxxa ^ 2)) - MeanRxxi ^ 2)) ' TODO: Handle the problem with very low ux and rxxa
MeanQualxi = 1 - (MeanBigUx ^ 2 * (1 - MeanQualxa)) ' TODO: Handle the problem with very low ux and rxxa
SDQualxi = Sqr(WorksheetFunction.Max(0, MeanRxxi - MeanQualxi ^ 2))
ElseIf Not SpecDistu Then
If Observedu Then
MeanRxxi = 1 - (MeanBigU ^ 2 * (1 - MeanRxxa)) ' TODO: Handle the problem with very low ux and rxxa
If Not IsEmpty(SDRxxa) Then SDRxxi = Sqr(1 + (MeanBigU ^ 2 * (MeanBigU ^ 2 - 2)) + (2 * MeanBigU ^ 2 * MeanRxxa * (1 - MeanBigU ^ 2)) + (MeanBigU ^ 4 * (SDRxxa ^ 2 + MeanRxxa ^ 2)) - MeanRxxi ^ 2) ' TODO: Handle the problem with very low ux and rxxa, Protect against floating point errors
MeanQualxi = 1 - (MeanBigU ^ 2 * (1 - MeanQualxa)) ' TODO: Handle the problem with very low ux and rxxa
SDQualxi = Sqr(WorksheetFunction.Max(0, MeanRxxi - MeanQualxi ^ 2))
ElseIf Not Observedu Then
Meanux = Sqr((MeanRxxa * MeanuT ^ 2) - MeanRxxa + 1)
MeanBigUx = 1 / Meanux
MeanRxxi = 1 - (MeanBigUx ^ 2 * (1 - MeanRxxa)) ' TODO: Handle the problem with very low ux and rxxa
If Not IsEmpty(SDRxxa) Then SDRxxi = Sqr(WorksheetFunction.Max(0, 1 + (MeanBigUx ^ 2 * (MeanBigUx ^ 2 - 2)) + (2 * MeanBigUx ^ 2 * MeanRxxa * (1 - MeanBigUx ^ 2)) + (MeanBigUx ^ 4 * (SDRxxa ^ 2 + MeanRxxa ^ 2)) - MeanRxxi ^ 2)) ' Handle the problem with very low ux and rxxa
MeanQualxi = 1 - (MeanBigUx ^ 2 * (1 - MeanQualxa)) ' TODO: Handle the problem with very low ux and rxxa
SDQualxi = Sqr(WorksheetFunction.Max(0, MeanRxxi - MeanQualxi ^ 2))
End If
End If
ElseIf Not SpecDistx Then
ReDim RXa(nRxx, 2)
RXa = RX
ReDim RXi(nRxx, 2)
If SpecDistu Then
If Not noMeanux Then
For i = 1 To nRxx
RXi(i, 1) = 1 - (MeanBigUx ^ 2 * (1 - RXa(i, 1))) ' TODO: Handle the problem with very low ux and rxxa
RXi(i, 2) = RXa(i, 2)
Next i
ElseIf noMeanux Then
Meanux = Sqr((MeanRxxa * MeanuT ^ 2) - MeanRxxa + 1)
MeanBigUx = 1 / Meanux
For i = 1 To nRxx
RXi(i, 1) = 1 - (MeanBigUx ^ 2 * (1 - RXa(i, 1))) ' TODO: Handle the problem with very low ux and rxxa
RXi(i, 2) = RXa(i, 2)
Next i
End If
ElseIf Not SpecDistu Then
If Observedu Then
For i = 1 To nRxx
RXi(i, 1) = 1 - (MeanBigU ^ 2 * (1 - RXa(i, 1))) ' TODO: Handle the problem with very low ux and rxxa
RXi(i, 2) = RXa(i, 2)
Next i
ElseIf Not Observedu Then
Meanux = Sqr((MeanRxxa * MeanuT ^ 2) - MeanRxxa + 1)
MeanBigUx = 1 / Meanux
For i = 1 To nRxx
RXi(i, 1) = 1 - (MeanBigUx ^ 2 * (1 - RXa(i, 1))) ' TODO: Handle the problem with very low ux and rxxa
RXi(i, 2) = RXa(i, 2)
Next i
End If
End If
' Compute new rxx_i distribution values
SumRxx = 0
SumRxxSq = 0
SumQualx = 0
For i = 1 To nRxx
SumRxx = SumRxx + RXi(i, 1) * RXi(i, 2)
SumRxxSq = SumRxxSq + (RXi(i, 1) ^ 2) * RXi(1, 2)
SumQualx = SumQualx + Sqr(RXi(i, 1)) * RXi(i, 2)
Next i
MeanRxxi = SumRxx / SumRxxFreq
SDRxxi = Sqr(WorksheetFunction.Max(0, (SumRxxSq / SumRxxFreq) - (SumRxx / SumRxxFreq) ^ 2))
MeanQualxi = SumQualx / SumRxxFreq
SDQualxi = Sqr(WorksheetFunction.Max(0, (SumRxx / SumRxxFreq) - (SumQualx / SumRxxFreq) ^ 2))
End If
End If
' ==== Range restriction values ====
If SpecDistu Then
If noMeanux Then Meanux = Sqr((MeanuT ^ 2) / (MeanuT ^ 2 + MeanRxxi * (1 - MeanuT ^ 2)))
If noSDux Then SDux = Sqr(SDuT ^ 2 * MeanRxxa)
If noMeanuT Then MeanuT = Sqr(((Meanux ^ 2) - (1 - MeanRxxa)) / MeanRxxa) ' TODO: Handle the problem with very low ux and rxxa
If noSDuT Then SDuT = Sqr(SDux ^ 2 / MeanRxxa)
MeanBigUx = 1 / Meanux
MeanBigUT = 1 / MeanuT
ElseIf Not SpecDistu Then
If Observedu Then
Meanux = MeanU
SDux = SDu
MeanBigUx = MeanBigU
ReDim Ux(nU, 2)
Ux = U
ReDim UT(nU, 2)
For i = 1 To nU
UT(i, 1) = Sqr(((Ux(i, 1) ^ 2) - (1 - MeanRxxa)) / MeanRxxa) ' TODO: Handle the problem with very low ux and rxxa
UT(i, 2) = Ux(i, 2)
Next i
' Compute new ux distribution values
SumU = 0
SumUSq = 0
For i = 1 To nU
SumU = SumU + UT(i, 1) * UT(i, 2)
SumUSq = SumUSq + (UT(i, 1) ^ 2) * UT(1, 2)
Next i
MeanuT = SumU / SumUFreq
SDuT = Sqr(WorksheetFunction.Max(0, (SumUSq / SumUFreq) - (SumU / SumUFreq) ^ 2))
MeanBigUT = 1 / MeanuT
ElseIf Not Observedu Then
MeanuT = MeanU
SDuT = SDu
MeanBigUT = MeanBigU
ReDim UT(nU, 2)
UT = U
ReDim Ux(nU, 2)
For i = 1 To nU
Ux(i, 1) = Sqr((UT(i, 1) ^ 2) / (UT(i, 1) ^ 2 + MeanRxxi * (1 - UT(i, 1) ^ 2)))
Ux(i, 2) = UT(i, 2)
Next i
' Compute new ux distribution values
SumU = 0
SumUSq = 0
For i = 1 To nU
SumU = SumU + Ux(i, 1) * Ux(i, 2)
SumUSq = SumUSq + (Ux(i, 1) ^ 2) * Ux(1, 2)
Next i
Meanux = SumU / SumUFreq
SDux = Sqr(WorksheetFunction.Max(0, (SumUSq / SumUFreq) - (SumU / SumUFreq) ^ 2))
MeanBigUx = 1 / Meanux
End If
End If
Else
' If there is no measurement error in X, then distributions of ux and uT are the same
If SpecDistu Then
If noMeanux Then
Meanux = MeanuT
MeanBigUx = 1 / Meanux
End If
If noSDux Then SDux = SDuT
If noMeanuT Then
MeanuT = Meanux
MeanBigUT = 1 / MeanuT
End If
If noSDuT Then SDuT = SDux
Else
Meanux = MeanU
SDux = SDu
MeanBigUx = MeanBigU
MeanuT = MeanU
SDuT = SDu
MeanBigUT = MeanBigU
ReDim Ux(nU, 2)
ReDim UT(nU, 2)
Ux = U
UT = U
End If
End If
End If
' =====================================
' ===== Bare bones meta-analysis ======
' =====================================
' Compute mean uncorrected r
Ntotal = 0
sumR = 0
For i = 1 To k
sumR = sumR + R(i, 2) * R(i, 1)
Ntotal = Ntotal + R(i, 2)
Next i
meanR = sumR / Ntotal
meanN = Ntotal / k
' Correct r values for small sample size bias
aR = 1 - (1 - meanR ^ 2) / ((2 * meanN) - 2)
meanR = meanR / aR
' Compute expected sampling error variance of observed r's
unexpVar = 1 - (meanR ^ 2)
SampErrVar = (unexpVar ^ 2) / (meanN - 1)
' Compute observed variance of observed r's
ObsSSQ = 0
For i = 1 To k
ObsSSQ = ObsSSQ + R(i, 2) * (R(i, 1) - meanR) ^ 2
Next i
ObsVar = ObsSSQ / Ntotal
SDobs = Sqr(ObsVar)
' Compute percent of variance due to sampling error
If ObsVar < 1E-16 Then
PerVarSamp = "No Obs. Var."
Else
PerVarSamp = (SampErrVar / ObsVar)
End If
' =====================================
' ===== Apply artifact corrections ====
' =====================================
' TODO: Implement Le et al. (2013) range restriction correction (p. 193 H&S 3ed)
' TODO: Implement Alexander et al. (1987) double range restriction correction (p. 193 H&S 3ed)
' TODO: Consider Raju, Burke, Normand (1991) methods for accounting for sampling error in artifacts
' === Compute true score mean r (rho) ===
If Not CorrectRR Then ' No range restriction
Rho = meanR / (MeanQualy * MeanQualx)
RhoValidity = meanR / MeanQualy
ElseIf rrDirect Then ' Direct range restriction
RhoValidityRestricted = meanR / MeanQualy
RhoValidity = RhoValidityRestricted * MeanBigUx / Sqr(((MeanBigUx ^ 2) - 1) * (RhoValidityRestricted ^ 2) + 1)
Rho = RhoValidity / MeanQualxa
ElseIf rrIndirect Then ' Indirect range restriction
RhoRestricted = meanR / (MeanQualy * MeanQualxi)
Rho = RhoRestricted * MeanBigUT / Sqr(((MeanBigUT ^ 2) - 1) * (RhoRestricted ^ 2) + 1)
RhoValidity = Rho * MeanQualxa
End If
' === Compute variance due to artifact differences ===
If Not CorrectRR Then ' No range restriction
If (Not CorrectRxx Or Not SpecDistx) And (Not CorrectRyy Or Not SpecDisty) Then
' If all distributions are new, then use interactive method to estimate variance
Taylor = False
SumRatten = 0
SumRSQatten = 0
SumArtFreq = 0
For IXX = 1 To nRxx
Qualx = Sqr(RX(IXX, 1))
For ICC = 1 To nRyy
Qualy = Sqr(RY(ICC, 1))
Ratten = Qualx * Qualy * Rho
ArtFreq = RX(IXX, 2) * RY(ICC, 2)
SumRatten = SumRatten + ArtFreq * Ratten
SumRSQatten = SumRSQatten + ArtFreq * Ratten * Ratten
SumArtFreq = SumArtFreq + ArtFreq
Next ICC
Next IXX
SumRatten = SumRatten / SumArtFreq
ArtVar = SumRSQatten / SumArtFreq - SumRatten * SumRatten
Else
' If some of the distributions are pre-specified, then use Raju and Burke's (1983) Taylor Series 2 model to estimate variance
' Note that R&B1983 had errors in their formulas and multipled F, G by .5
Taylor = True
E = meanR / Rho
F = (meanR / MeanQualx)
G = (meanR / MeanQualy)
VarRho = (ObsVar - SampErrVar - (F ^ 2) * (SDQualx ^ 2) - (G ^ 2) * (SDQualy ^ 2)) / (E ^ 2) / (aR ^ 2) ' aR is correcting for the disattenuation of the slight bias in the sample correlation coefficient
SDrho = Sqr(WorksheetFunction.Max(0, VarRho))
SDrhoValidity = SDrho * MeanQualx
ResVar = VarRho * ((MeanQualx * MeanQualy) ^ 2)
SDres = SDrho * (MeanQualx * MeanQualy)
PredVar = ObsVar - ResVar
SDpred = Sqr(PredVar)
' Alternative method:
' Multiplicative (noninteractive) model for estimating true variance
' Results are virtually identical to the Raju and Burke method for these artifacts
' Taylor = False
' A = MeanQualx * MeanQualy
' V = (SDQualx/MeanQualx)^2 + (SDQualy/MeanQualy)^2
' ArtVar = Rho^2 * A^2 * V
' Then use nonlinear function below to estimate VarRho (or just divide by product of MeanRxx and MeanRyy)
End If
ElseIf rrDirect Then ' Direct range restriction
If (Not CorrectRxx Or Not SpecDistx) And (Not CorrectRyy Or Not SpecDisty) And Not SpecDistu Then
' If all distributions are new, then use interactive method to estimate variance
Taylor = False
SumRatten = 0
SumRSQatten = 0
SumArtFreq = 0
For IXX = 1 To nRxx
Qualx = Sqr(RXa(IXX, 1))
For ICC = 1 To nRyy
Qualy = Sqr(RY(ICC, 1))
For IU = 1 To nU
uval = Ux(IU, 1)
Ratten = Qualx * Rho
RRatten = ((uval ^ 2) - 1) * (Ratten ^ 2) + 1
Ratten = uval * Ratten / Sqr(RRatten)
Ratten = Ratten * Qualy
ArtFreq = RXa(IXX, 2) * RY(ICC, 2) * Ux(IU, 2)
SumRatten = SumRatten + ArtFreq * Ratten
SumRSQatten = SumRSQatten + ArtFreq * Ratten * Ratten
SumArtFreq = SumArtFreq + ArtFreq
Next IU
Next ICC
Next IXX
SumRatten = SumRatten / SumArtFreq
ArtVar = SumRSQatten / SumArtFreq - SumRatten * SumRatten
Else
' If some of the distributions are pre-specified, then use Raju and Burke's (1983) Taylor Series 2 model to estimate variance
' Note that R&B1983 had errors in their formulas and multipled F, G by .5
Taylor = True
E = (meanR / Rho) + (((meanR ^ 3) * (1 - (Meanux ^ 2))) / (Rho * (Meanux ^ 2)))
F = ((meanR / MeanQualxa) + (((meanR ^ 3) * (1 - (Meanux ^ 2))) / (MeanQualxa * (Meanux ^ 2))))
G = ((meanR / MeanQualy) + (((meanR ^ 3) * (1 - (Meanux ^ 2))) / (MeanQualy * (Meanux ^ 2))))
H = (meanR - (meanR ^ 3)) / Meanux
VarRho = (ObsVar - SampErrVar - (F ^ 2) * (SDQualxa ^ 2) - (G ^ 2) * (SDQualy ^ 2) - (H ^ 2) * (SDux ^ 2)) / (E ^ 2) / (aR ^ 2) ' aR is correcting for the disattenuation of the slight bias in the sample correlation coefficient
SDrho = Sqr(WorksheetFunction.Max(0, VarRho))
SDrhoValidity = SDrho * MeanQualxa
' Estimate residual distribution of r using reverse of of Law et al.'s (1994) non-linear procedure
FR = Array(0, 0.0004, 0.0006, 0.0008, 0.001, 0.0014, 0.0018, 0.0022, 0.0028, 0.0036, 0.0044, 0.0054, 0.0066, 0.0079, 0.0094, 0.0111, 0.013, 0.015, 0.0171, 0.0194, 0.0218, 0.0242, 0.0266, 0.029, 0.0312, 0.0333, 0.0352, 0.0368, 0.0381, 0.0391, 0.0397, 0.0399, 0.0397, 0.0391, 0.0381, 0.0368, 0.0352, 0.0333, 0.0312, 0.029, 0.0266, 0.0242, 0.0218, 0.0194, 0.0171, 0.015, 0.013, 0.0111, 0.0094, 0.0079, 0.0066, 0.0054, 0.0044, 0.0036, 0.0028, 0.0022, 0.0018, 0.0014, 0.001, 0.0008, 0.0006, 0.0004)
sumRnonlinatten = 0
SSQRnonlinatten = 0
SumDist = 0
For i = 1 To 61
rDist = Rho + (i - 31) * 0.1 * SDrho
rDist = rDist * MeanQualxa
rDist = rDist * (Meanux / Sqr(1 + ((Meanux ^ 2) - 1) * (rDist ^ 2)))
rDist = rDist * MeanQualy
sumRnonlinatten = sumRnonlinatten + FR(i) * rDist
SSQRnonlinatten = SSQRnonlinatten + FR(i) * (rDist ^ 2)
SumDist = SumDist + FR(i)
Next i
meanRnonlinatten = sumRnonlinatten / SumDist
If meanR = meanRnonlinatten Then
NonLinCheck = True
Else
NonLinCheck = False
End If
ResVar = SSQRnonlinatten / SumDist - (meanRnonlinatten ^ 2)
SDres = Sqr(WorksheetFunction.Max(0, ResVar))
PredVar = ObsVar - ResVar
SDpred = Sqr(PredVar)
' Alternative method:
' Multiplicative (noninteractive) model for estimating true variance
' Results for the Raju and Burke method are more accurate for these artifacts because they don't assume that c is independent of Qualx and Qualy
' Taylor = False
' c = Sqr( Meanux^2 + (MeanR^2) * (1 - Meanux^2) )
' SDc = Sqr( MeanR^2 - c^2 + ( (1 - MeanR^2) * (Meanux^2 + SDux^2) ) )
' A = MeanQualx * MeanQualy * c
' V = (SDQualx/MeanQualx)^2 + (SDQualy/MeanQualy)^2 + (SDc/c)^2
' ArtVar = Rho^2 * A^2 * V