-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPRM064.bas
1753 lines (1646 loc) · 49 KB
/
PRM064.bas
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
! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
! //
! // SCHRAUSSER-MAT:
! // Permutation methods calculator
! //
! // P R M
! //
! // by
! // Dietmar Gerald Schrausser
! // © 2023
! //
_name$="PRM"
_ver$="v1.2"
! /////////////////////////////////////////////////////////
INCLUDE strg.inc
INCLUDE data1.prm
INCLUDE data2.prm
INCLUDE data3.prm
! // INI file
FILE.EXISTS f_ini, "prm.ini"
IF f_ini
TEXT.OPEN r, ini, "prm.ini"
TEXT.READLN ini, ini$:inf=VAL(ini$)
TEXT.READLN ini, ini$:pth$=ini$
TEXT.READLN ini, ini$:p_b=VAL(ini$)
TEXT.READLN ini, ini$:rp=VAL(ini$)
TEXT.READLN ini, ini$:psg=VAL(ini$)
TEXT.READLN ini, ini$:rnsw=VAL(ini$)
TEXT.READLN ini, ini$:sig=VAL(ini$)
TEXT.READLN ini, ini$:seed=VAL(ini$)
TEXT.READLN ini, ini$:meth=VAL(ini$)
TEXT.READLN ini, ini$:met$=ini$
TEXT.READLN ini, ini$:m0=VAL(ini$)
TEXT.READLN ini, ini$:fi$=ini$
TEXT.READLN ini, ini$:mode=VAL(ini$)
TEXT.READLN ini, ini$:thta$=ini$
TEXT.READLN ini, ini$:thmode=VAL(ini$)
TEXT.READLN ini, ini$:rnsw$=ini$
TEXT.READLN ini, ini$:fiout$=ini$
TEXT.READLN ini, ini$:fidt$=ini$
TEXT.READLN ini, ini$:fids$=ini$
TEXT.READLN ini, ini$:grsw=VAL(ini$)
TEXT.READLN ini, ini$:pvsw=VAL(ini$)
TEXT.READLN ini, ini$:msw=VAL(ini$)
TEXT.READLN ini, ini$:mvd=VAL(ini$)
TEXT.READLN ini, ini$:inpt=VAL(ini$)
TEXT.READLN ini, ini$:swout=VAL(ini$)
TEXT.READLN ini, ini$:swdal=VAL(ini$)
TEXT.READLN ini, ini$:swvec=VAL(ini$)
TEXT.READLN ini, ini$:m1=VAL(ini$)
TEXT.READLN ini, ini$:fo1$=ini$
TEXT.READLN ini, ini$:fo2$=ini$
TEXT.READLN ini, ini$:fo3$=ini$
TEXT.READLN ini, ini$:win1$=ini$
TEXT.READLN ini, ini$:win2$=ini$
TEXT.READLN ini, ini$:win3$=ini$
TEXT.READLN ini, ini$:scm$=ini$
TEXT.READLN ini, ini$:scm=VAL(ini$)
TEXT.READLN ini, ini$:outsw1=VAL(ini$)
TEXT.READLN ini, ini$:outsw2=VAL(ini$)
TEXT.READLN ini, ini$:outsw3=VAL(ini$)
TEXT.READLN ini, ini$:outsw4=VAL(ini$)
TEXT.CLOSE ini
ELSE
! // Default //
inf=1 % // startinfo sw //
pth$="../../PRM/" % // input-output path //
p_b=0.5 % // Binomialdesign p //
rp=0.5 % // mid p //
psg=0.05 % // crit niv //
rnsw=1 % // rnd -1=sys 1=sigma //
sig=1 % // tailed //
seed=0 % // seed, 0= systime //
meth=1 % // method switch P //
met$="P" % // method switch label //
m0=10000 % // initial random cycles //
fi$="" % // default input file //
mode=1 % // default input mode //
thta$="AM Difference [dAM]" % // default Theta label //
thmode=1 % // default Theta //
rnsw$="Sigma" % // rnd label //
fiout$="prm_out.txt" % // default log file //
fidt$="prm_outdat.txt" % // default datlog file //
fids$="prm_pvt.txt" % // default distr file //
grsw=1 % // dynamic graph sw //
pvsw=1 % // dyn p value sw //
msw=1 % // dyn m counter sw //
mvd=10000 % // dist vect max //
inpt=2 % // input mode //
swout=1 % // output log on sw //
swdal=1 % // output dat on sw //
swvec=1 % // output vec on sw //
m1=10000 % // default random cycles //
fo1$=" [Out] " % // output log label //
fo2$=" [Dat] " % // output dat label //
fo3$=" [Dist] " % // output dist label //
win1$=" Dist~ " % // window graph label //
win2$=" p~ " % // window p val label //
win3$=" m~ " % // window m label //
scm$=" Default" % // scheme label //
scm=1 % // scheme sw //
outsw1=1 % // outpt option sw1 //
outsw2=1 % // outpt option sw2 //
outsw3=1 % // outpt option sw3 //
outsw4=1 % // outpt option sw4 //
ENDIF
m=m0 % // default m reset //
IF seed=0
GOSUB dlgseed:ENDIF % // seed value
!seed1=seed
__sd_=seed
sgm=34/45 % // sigma //
scsw=1 % // scheme sw ini //
dlsw=1 % // dlgmain sw ini //
swtl=1 % // taild switch //
smq$=CHR$(9654) % // menue symbol > //
IF sig=2: swtl=-1: ENDIF
st0: % // start0 //
IF scm=1:GR.OPEN 255,150,150,150,0,1:ENDIF % // Default //
IF scm=2:GR.OPEN 255,80,30,30,0,1:ENDIF % // Red //
IF scm=3:GR.OPEN 255,30,80,30,0,1:ENDIF % // Green //
IF scm=4:GR.OPEN 255,30,30,30,0,1:ENDIF % // Inverted //
IF scm=5:GR.OPEN 255,255,255,255,0,1:ENDIF % // RGB1 //
IF scm=6:GR.OPEN 255,200,200,200,0,1:ENDIF % // RGB2 //
GR.SCREEN sx,sy
IF inf=1 %Startinfo
!DIALOG.MESSAGE ,_name$+ "Permutation methods calculator "+_ver$+" Copyright © 2023 by Dietmar G. SCHRAUSSER + Veritas in materia principii +",msg
ENDIF
st: % // start //
IF mode=2 % // initial file input //
GOSUB filinp: ENDIF
s1m=0 % // Simulation sums ini //
s2m=0 %
pe=0 % // p values ini //
pg=0 % //
ps=0 % //
seedsw=0 % // rnd reset //
IF rnsw=-1
rdz=RANDOMIZE(seed) % // system rnd seed //
ENDIF
IF dlsw=1 THEN GOSUB dlgmain % // main menue //
IF scsw=0
scsw=1:dlsw=0:GR.CLOSE:GOTO st0 % // scheme sw //
ENDIF
dlsw=1 % // dlgmain sw reset //
IF meth=3 | meth =4 % // mP, mPr //
DIM mP_12[n1+n2,2]
FOR i=1 TO n1+n2
mP_12[i,1]=n0_12[i,1]
mP_12[i,2]=n0_12[i,2]
NEXT
ENDIF
GOSUB tval % // q0, t value //
IF thmode=1 % // dAM //
GOSUB tp % // t probability //
ENDIF
GOSUB binom % // Binomial probability //
IF meth <3 % // exact % wP/Matrices //
GOSUB perm
m=perm
GOSUB exact % // start position st //
READ.FROM st+1
ENDIF
IF m<=mvd % // max mv for distr vector d //
mv=m: ELSE: mv=mvd
ENDIF
DIM pvt[mv] % // Distribution vector d //
! /////////////////////////////////////////////////////////
! // Simulations over cycles M
IF meth>2:m_=m-1:ELSE:m_=m:ENDIF
FOR j=1 TO m_ % // over m //
DIM q11[n1]
DIM q12[n2]
! //
IF meth >= 5 % // Bt, Btr / ///Bootstrap/// /
FOR i=1 TO n1
IF rnsw=1
GOSUB rand % // Randomization function sigma //
r=INT((n1+n2)* n__ )+1 % // Bt x1 //
ELSE
r=INT((n1+n2)* RND() )+1 % // Bt x1 //
ENDIF
s1m=s1m+ n0_12[r,1] % // sum1 //
q11[i]= n0_12[r,1] % // vector q11 //
NEXT
FOR i=1 TO n2
IF rnsw=1
GOSUB rand % // Randomization function sigma //
r=INT((n1+n2)* n__ )+1 % // Bt x2 //
ELSE
r=INT((n1+n2)* RND() )+1 % // Bt x2 //
ENDIF
s2m=s2m+ n0_12[r,1] % // sum2 //
q12[i]= n0_12[r,1] % // vector q12 //
NEXT
ENDIF
! //
IF meth=3 | meth=4 % // mP, mPr / ///randomized/P/// /
DIM perm [n1+n2]
n2_sw=1
DO % // n2_sw loop //
FOR i=1 TO n1+n2
DO % // n_sw loop //
n_sw=0
IF rnsw=-1 % // Randomization function system //
r=ROUND((RND()*((n1+n2)-1))+1) % // random index i[1,n1+n2] //
ELSE % // Randomization function sigma //
GOSUB rand
r=ROUND((n__*((n1+n2)-1))+1) % // random index i[1,n1+n2] //
ENDIF
IF i>1
FOR k=1 TO i-1
IF perm[k]=r:n_sw=1:ENDIF % // permutation switch n_sw://
NEXT % // no multiple elements //
ENDIF
UNTIL n_sw=0 % // n_sw
perm[i]=r
NEXT
FOR i=1 TO n1 % // class permutation n2_sw //
IF perm[i]>n1:n2_sw=0 % // no intraclass permutation //
ENDIF
NEXT
UNTIL n2_sw=0 % // n2_sw //
FOR i=1 TO n1
s1m=s1m+ mP_12[perm[i],1] % // sum1 m //
q11[i]= mP_12[perm[i],1] % // vector q11 //
NEXT
FOR i=1 TO n2
s2m=s2m+ mP_12[perm[i+n1],1] % // sum2 m //
q12[i]= mP_12[perm[i+n1],1] % // vector q12 //
NEXT
ARRAY.DELETE perm[] % // delete tmp vector //
ENDIF
! //
IF meth=1 | meth=2 % // P, Pr / ///Exact/p/// /
FOR i=1 TO n1
READ.NEXT rnp % P
s1m=s1m+ n0_12[rnp,1] % // sum1 //
q11[i]= n0_12[rnp,1] % // vector q11 //
NEXT
FOR i=1 TO n2
READ.NEXT rnp % P
s2m=s2m+ n0_12[rnp,1] % // sum2 //
q12[i]= n0_12[rnp,1] % // vector q12 //
NEXT
ENDIF
! ////////////////////////////////////////////////////////
! // Theta, q1
IF thmode=1 % //dAM //
q1=s1m/n1-s2m/n2 % // one-tailed //
IF sig=2
q0=ABS(q0) % // two-tailed //
q1=ABS(q1)
ENDIF
ENDIF
IF thmode=2 % //dSD //
s211=0:s221=0
FOR i=1 TO n1
s211=s211+(q11[i]-s1m/n1)^2
NEXT
s211=SQR(s211/n1)
FOR i=1 TO n2
s221=s221+(q12[i]-s2m/n2)^2
NEXT
s221=SQR(s221/n2)
q1=s211-s221 % // one-tailed //
IF sig=2
q0=ABS(q0) % // two-tailed //
q1=ABS(q1)
ENDIF
ENDIF
ARRAY.DELETE q11[]
ARRAY.DELETE q12[]
! ////////////////////////////////////////////////////////
! // sum, p/btr probability
IF j=1 & meth>2:pe=1:ENDIF
IF q0=q1 THEN pe=pe+1
IF q0>q1 THEN pg=pg+1
IF q0<q1 THEN ps=ps+1
IF j=m_ &(meth=1 | meth=3 | meth=5) % // p=->p //
IF pg<=ps:pg=pg+pe: ELSE: ps=ps+pe
ENDIF
ENDIF
! //
IF j=m_ &(meth = 2 | meth=4 | meth=6) % // randomized p //
IF pg<=ps
pg=pg+ pe * rp
ps=ps+ pe * (1-rp)
ELSE
pg=pg+ pe * (1-rp)
ps=ps+ pe * rp
ENDIF
ENDIF
! //
sgpg$="":sgps$="" % // sig marks //
IF pg/j<=0.1 THEN sgpg$="+"
IF pg/j<=0.05 THEN sgpg$="*"
IF pg/j<=0.01 THEN sgpg$="**"
IF pg/j<=0.001 THEN sgpg$="***"
IF ps/j<=0.1 THEN sgps$="+"
IF ps/j<=0.05 THEN sgps$="*"
IF ps/j<=0.01 THEN sgps$="**"
IF ps/j<=0.001 THEN sgps$="***"
s1m=0: s2m=0 % // sum scores //
! ////////////////////////////////////////////////////////
! // Screen graph output
xx=(sx-sx/20)-sx/20 % // window width
yy=(sy/2+sy/20)-(sy-sy/20) % // window hight
pvt[j]=q1 % // Simulation distribution vector //
GR.CLS
IF grsw=1 | (grsw=-1 &j>m_-2) % // graph out sw //
DIM pvt1[j] % // tmp vector for graphics
DIM pvt2[j] % // tmp vector for vector
FOR i=1 TO j
pvt1[i] =pvt[i]
pvt2[i]=pvt[i]
NEXT
ARRAY.SORT pvt1[] % // sort tmp graphics vector
IF j=m_
DIM pval2[m_] % // pvalue vector //
FOR k=1 TO m_:pval2[k]=k/m_:NEXT
ARRAY.SORT pvt2[] % // sort tmp vector vector
ENDIF
ARRAY.MIN minp, pvt1[] % // min value
IF sig=1 % // 1-tailed negativ corr
FOR i=1 TO j
pvt1[i]=pvt1[i]+ABS(minp)
NEXT
ENDIF
dmin=pvt1[1] % // min value
dmax=pvt1[j] % // max value
IF dmax=0 THEN dmax=1 % // division by 0
! ////////////////////////////////////////////////////////
! // permutation, btr distribution graph
FOR i=1 TO j % //
pvt_=pvt1[i]
yy1=yy-(yy*((pvt_/dmax))*0.9) % // actual val/max val
xx0=xx*((i-1)/j) % percentage width st
xx1=xx*((j-i)/j ) % percentage width end
! ///////////////////////////////////////////////////////
! // bar colors and style
SW.BEGIN scm
SW.CASE 1 % // default //
cr01s= 20:cg01s= 20:cb01s= 20
cr01g=120:cg01g=120:cb01g=120
cr01e= 20:cg01e= 20:cb01e= 20
cr0s= 20:cg0s= 20:cb0s= 20
cr0g= 120:cg0g= 120:cb0g= 120
cr0e= 20:cg0e= 20:cb0e= 20
sc1=0
SW.BREAK
SW.CASE 2 % // red //
cr01s=255:cg01s= 30:cb01s= 30
cr01g=185:cg01g= 30:cb01g= 30
cr01e=255:cg01e= 30:cb01e= 30
cr0s= 255:cg0s= 30:cb0s= 30
cr0g= 185:cg0g= 30:cb0g= 30
cr0e= 255:cg0e= 30:cb0e= 30
sc1=1
SW.BREAK
SW.BREAK
SW.CASE 3 % // green //
cg01s=255:cr01s= 30:cb01s= 30
cg01g=185:cr01g= 30:cb01g= 30
cg01e=255:cr01e= 30:cb01e= 30
cg0s= 255:cr0s= 30:cb0s= 30
cg0g= 185:cr0g= 30:cb0g= 30
cg0e= 255:cr0e= 30:cb0e= 30
sc1=1
SW.BREAK
SW.CASE 4 % // inverted //
cr01s=150:cg01s=150:cb01s=150
cr01g= 90:cg01g= 90:cb01g= 90
cr01e=150:cg01e=150:cb01e=150
cr0s= 150:cg0s= 150:cb0s= 150
cr0g= 90:cg0g= 90:cb0g= 90
cr0e= 150:cg0e= 150:cb0e= 150
sc1=0
SW.BREAK
SW.CASE 5 % // RGB1 //
cr01s=100:cg01s=220:cb01s=100
cr01g=150:cg01g=150:cb01g=150
cr01e=100:cg01e=220:cb01e=100
cr0s= 100:cg0s= 220:cb0s= 100
cr0g= 150:cg0g= 150:cb0g= 150
cr0e= 100:cg0e= 220:cb0e= 100
sc1=0
SW.BREAK
SW.CASE 6 % // RGB2 //
cr01s=255:cg01s= 0:cb01s= 0
cr01g=100:cg01g=100:cb01g=100
cr01e=255:cg01e= 0:cb01e= 0
cr0s= 255:cg0s= 0:cb0s= 0
cr0g= 100:cg0g= 100:cb0g= 100
cr0e= 255:cg0e= 0:cb0e= 0
sc1=0
SW.BREAK
SW.END
IF sig=1
q01=q0+ABS(minp)
IF pvt_ =q01 THEN GR.COLOR 255,cr01e,cg01e,cb01e,1 % // q1=q0
IF ps/j>0.5&pg/j<0.5
IF pvt_ <q01 THEN GR.COLOR 255,cr01s,cg01s,cb01s,sc1 % // q1<q0
IF pvt_ >q01 THEN GR.COLOR 255,cr01g,cg01g,cb01g,0 % // q1>q0
ELSE
IF pvt_ <q01 THEN GR.COLOR 255,cr01g,cg01g,cb01g,0 % // q1<q0
IF pvt_ >q01 THEN GR.COLOR 255,cr01s,cg01s,cb01s,sc1 % // q1>q0
ENDIF
ENDIF
IF sig=2
IF pvt_ =q0 THEN GR.COLOR 255,cr0e,cg0e,cb0e,1 % // q1=q0
IF ps/j>0.5&pg/j<0.5
IF pvt_ <q0 THEN GR.COLOR 255,cr0s,cg0s,cb0s,sc1 % // q1<q0
IF pvt_ >q0 THEN GR.COLOR 255,cr0g,cg0g,cb0g,0 % // q1>q0
ELSE
IF pvt_ <q0 THEN GR.COLOR 255,cr0g,cg0g,cb0g,0 % // q1<q0
IF pvt_ >q0 THEN GR.COLOR 255,cr0s,cg0s,cb0s,sc1 % // q1>q0
ENDIF
ENDIF
! ///////distribution/graph/rendering/////////////////////////////////
GR.RECT rec,(sx/20) +xx0, (sy-sy/20), (sx-sx/20)-xx1, (sy/2+sy/20)-yy1
NEXT
! ///////// distribution vector /////////////////////////////////////
GR.TEXT.SIZE sx/35
GR.TEXT.ALIGN 1
SW.BEGIN scm
SW.CASE 1:vcrs= 120:vcgs= 120:vcbs= 120:SW.BREAK
SW.CASE 2:vcrs= 255:vcgs= 30:vcbs= 30:SW.BREAK
SW.CASE 3:vcrs= 30:vcgs= 255:vcbs= 30:SW.BREAK
SW.CASE 4:vcrs= 80:vcgs= 80:vcbs= 80:SW.BREAK
SW.CASE 5:vcrs= 160:vcgs= 160:vcbs= 160:SW.BREAK
SW.CASE 6:vcrs= 130:vcgs= 130:vcbs= 130:SW.BREAK
SW.END
GR.COLOR 255,vcrs,vcgs,vcbs,1
stv=sy/23
IF j<16
FOR v=1 TO j
GR.TEXT.ALIGN 1
sgv_$=""
IF pvt2[v]=q0 THEN sgv_$=" >"
GR.TEXT.DRAW vec,sx/2+sx/5+sx/100,sy/2-sy/2.7+stv, STR$(ROUND(pvt2[v],2))+sgv_$
IF j=m_
GR.TEXT.ALIGN 3
GR.TEXT.DRAW vec,sx-sx/15,sy/2-sy/2.7+stv, FORMAT$("%.###",pval2[v])
ENDIF
stv=stv+sy/77
NEXT
ELSE
IF j<m_
FOR v=1 TO 16
GR.TEXT.DRAW vec,sx/2+sx/5+sx/100,sy/2-sy/2.7+stv, STR$(ROUND(pvt2[j-v+1],2))
stv=stv+sy/77
NEXT
ELSE % // last vector M //
swpvv=1
FOR k=1 TO m_ % // q0 position //
IF swpvv=1&pvt2[k]>=q0:swpvv=0:pvv=k:ENDIF
NEXT
pvv1=8 % // q0 in mid position of output //
IF pvv <=8 THEN pvv1=7-(8-pvv) % // k<8 //
pvv=pvv-pvv1
pmk=pvv+15
IF m_-pvv <15 THEN pmk=pvv+(m_-pvv) % // k+8>M //
FOR v=pvv TO pmk
GR.TEXT.ALIGN 1
IF v=pvv+pvv1 THEN sgv_$=" >" % // q0 mark //
GR.TEXT.DRAW vec,sx/2+sx/5+sx/100,sy/2-sy/2.7+stv, STR$(ROUND(pvt2[v],2))+sgv_$
sgv_$=""
GR.TEXT.ALIGN 3
GR.TEXT.DRAW vec,sx-sx/15,sy/2-sy/2.7+stv, FORMAT$("%.###",pval2[v])
stv=stv+sy/77
NEXT
ENDIF
ENDIF
ARRAY.DELETE pvt1[] % // delete tmp vector //
!ARRAY.DELETE pvt2[] % // delete tmp vector //
ENDIF % // graph out sw //
! //
! //////////// windows /////////////////////////////////////////////
! // head //
IF scm=1:GR.COLOR 255,130,130,130,1:ENDIF % // default //
IF scm=2:GR.COLOR 255, 80, 30, 30,1:ENDIF % // red //
IF scm=3:GR.COLOR 255, 30, 80, 30,1:ENDIF % // green //
IF scm=4:GR.COLOR 255,100,100,100,1:ENDIF % // inverted//
IF scm=5:GR.COLOR 255,120,150,255,1:ENDIF % // RGB1 //
IF scm=6:GR.COLOR 255, 50, 50,255,1:ENDIF % // RGB2 //
GR.RECT rec, sx/20,sy/2+sy/12,sx-sx/20,sy/2+sy/20 %
GR.RECT rec, sx/2+sx/5, sy/2-sy/2.95, sx-sx/20, sy/2-sy/2.7
IF scm=1:GR.COLOR 255,180,180,180,1:ENDIF % // default //
IF scm=2:GR.COLOR 255,255, 30, 30,1:ENDIF % // red //
IF scm=3:GR.COLOR 255, 30,255, 30,1:ENDIF % // green //
IF scm=4:GR.COLOR 255, 30, 30, 30,1:ENDIF % // inverted//
IF scm=5:GR.COLOR 255,255,255,255,1:ENDIF % // RGB1 //
IF scm=6:GR.COLOR 255,255,255,255,1:ENDIF % // RGB2 //
GR.TEXT.ALIGN 1
GR.TEXT.SIZE sx/30
GR.TEXT.DRAW tx,sx/20+sx/100,sy/2+sy/14, met$+" - Distribution"
GR.TEXT.DRAW tx,sx/2+sx/5+sx/100,sy/2-sy/2.86, met$+" - Vector"
IF mode=2
GR.TEXT.ALIGN 3
GR.TEXT.DRAW tx,sx-sx/20-sx/100,sy/2+sy/14, fi$
ENDIF
! // window frame //
IF scm=1:GR.COLOR 255,165,165,165, 0:ENDIF % // default //
IF scm=2:GR.COLOR 255,255, 30, 30, 0:ENDIF % // red //
IF scm=3:GR.COLOR 255, 30,255, 30, 0:ENDIF % // green //
IF scm=4:GR.COLOR 255, 80, 80, 80, 0:ENDIF % // inverted //
IF scm=5:GR.COLOR 255, 100, 100, 100, 0:ENDIF % // RGB1 //
IF scm=6:GR.COLOR 80, 230, 230, 230, 1:ENDIF % // RGB2 //
GR.LINE ln, sx/20,sy-sy/20+yy/2+sy/45,sx-(sx/20),sy-sy/20+yy/2+sy/45 % // hor
GR.LINE ln, sx/20+xx/2,sy-sy/20,sx/20+xx/2,sy/2+sy/12 % // vert
IF scm=1:GR.COLOR 255,200,200,200,0:ENDIF % // default //
GR.LINE ln, sx/20,sy/2+sy/12,sx-(sx/20),sy/2+sy/12 %
GR.RECT ln, sx/2+sx/5, sy/2-sy/2.95, sx-sx/20, sy/2-sy/2.95
GR.RECT rec, sx/20,sy-sy/20,sx-sx/20,sy/2+sy/20 %// bottom
GR.RECT rec, sx/2+sx/5,sy/2-sy/8,sx-sx/20,sy/2-sy/2.7 %// top
! ////////////////////////////////////////////////////////
! // Text rendering
IF (pvsw=1|msw=1)|((pvsw=-1&pvsw=-1)&(j=1|j>m_-1))
!!
IF scm=1:GR.COLOR 255,200,200,200,1:ENDIF % // default //
!!
GR.TEXT.BOLD 0
GR.TEXT.ALIGN 3
GR.TEXT.SIZE sx/20
! // meth, p<>, M //
IF scm=1:GR.COLOR 255,220,220,220,1:ENDIF % // default //
IF scm=2:GR.COLOR 255,255, 30, 30,1:ENDIF % // red //
IF scm=3:GR.COLOR 255, 30,255, 30,1:ENDIF % // green //
IF scm=4:GR.COLOR 255,100,100,100,1:ENDIF % // inverted //
IF scm=5:GR.COLOR 255,100,220,100,1:ENDIF % // RGB1 //
IF scm=6:GR.COLOR 255,10,10,10,1:ENDIF % // RGB2 //
IF (pvsw=-1) % // window sw //
IF j=1
GR.TEXT.DRAW tx,sx-sx/13,sy/30, "~m "+INT$(m)
ENDIF
IF j>m_-1
GR.TEXT.DRAW tx,sx-sx/13,sy/30, "M="+INT$(m)
ENDIF
ENDIF
IF (pvsw=1|msw=1)
IF j < m_
GR.TEXT.DRAW tx,sx-sx/13,sy/30, "m="+INT$(m-j)
ELSE
GR.TEXT.DRAW tx,sx-sx/13,sy/30, "M="+INT$(m)
ENDIF
ENDIF
GR.TEXT.ALIGN 1
IF (pvsw=1|msw=1) |(pvsw=-1 & j>m_-1) % // window sw //
IF ps>0
GR.TEXT.DRAW tx, sx/11.7,1.8*(sy/25), " p>:"+FORMAT$("%.#####", ROUND(ps/j,5))+sgps$
ENDIF
IF pg>0
GR.TEXT.DRAW tx,sx/11.7,3.2*(sy/25), " p<:"+FORMAT$("%.#####",round (pg/j,5))+sgpg$
ENDIF
ENDIF
GR.TEXT.SIZE sx/12
GR.TEXT.DRAW tx,-sx/108,sy/25, met$
! // main text, p= //
IF scm=1:GR.COLOR 255,200,200,200,1:ENDIF % // default //
IF scm=2:GR.COLOR 255,255, 30, 30,1:ENDIF % // red //
IF scm=3:GR.COLOR 255, 30,255, 30,1:ENDIF % // green //
IF scm=4:GR.COLOR 255, 80, 80, 80,1:ENDIF % // inverted//
IF scm=5:GR.COLOR 255,90,90,90,1:ENDIF % // RGB1 //
IF scm=6:GR.COLOR 255,120,120,120,1:ENDIF % // RGB2 //
GR.TEXT.SIZE sx/20
IF (pvsw=1|msw=1) |(pvsw=-1 & j>m_-1) % // window sw //
IF pe>0
IF meth = 2 | meth=4 | meth=6
GR.TEXT.DRAW tx,sx/11.7,2.5*(sy/25), " p=:"+FORMAT$("%.#####", ROUND(pe/j,5))+FORMAT$(" [%.#",rp)+"]"
ELSE
GR.TEXT.DRAW tx,sx/11.7,2.5*(sy/25), " p=:"+FORMAT$("%.#####", ROUND(pe/j,5))
ENDIF
ENDIF
ELSE
GR.TEXT.DRAW tx,sx/11.7,2.5*(sy/25), " p: Iterate over m ..."
ENDIF
IF 1/m >0.00001 % // pmin! //
GR.TEXT.DRAW tx,sx/6.5,sy/25, FORMAT$("[ %.#####",1/m)+" ]"
ENDIF
GR.TEXT.ALIGN 3
IF thmode=1
GR.TEXT.DRAW tx,sx-sx/13,2.8*(sy/40), "dAM[0]: "+STR$(round (ABS(q0),2))
ENDIF
IF thmode=2
GR.TEXT.DRAW tx,sx-sx/13,2.8*(sy/40), "dSD[0]: "+STR$(round (ABS(q0),2))
ENDIF
GR.TEXT.DRAW tx,sx-sx/13,4*(sy/40), INT$(sig) +"-tailed"
GR.TEXT.SIZE sx/15
GR.TEXT.ALIGN 1
GR.TEXT.DRAW tx,5,sy-sy/100, _name$+": "+des$
GR.TEXT.ALIGN 2
GR.TEXT.SIZE sx/5
GR.TEXT.DRAW tx,sx/2-sx/6.5-sx/7,sy/2-sy/6.5, "A"
IF (pvsw=1|msw=1) |(pvsw=-1 & j>m_-2) % // window sw //
IF (pg/j<=0.05 | ps/j<=0.05)
IF sig=1
IF ((am1>am2)&thmode=1)|((SQR(s21)>SQR(s22))&thmode=2)
GR.TEXT.DRAW tx,sx/2-sx/7,sy/2-sy/6.5, ">"
ELSE
GR.TEXT.DRAW tx,sx/2-sx/7,sy/2-sy/6.5, "<"
ENDIF
ELSE
GR.TEXT.DRAW tx,sx/2-sx/7,sy/2-sy/6.5, CHR$(8800)
ENDIF
ENDIF
ENDIF
GR.TEXT.DRAW tx,sx/2+sx/6.5-sx/7,sy/2-sy/6.5, "B"
GR.TEXT.ALIGN 2
GR.TEXT.SIZE sx/8
GR.TEXT.DRAW tx,sx/2-sx/6.5-sx/7,sy/2-sy/14.5, INT$(n1)
GR.TEXT.DRAW tx,sx/2+sx/6.5-sx/7,sy/2-sy/14.5, INT$(n2)
GR.TEXT.SIZE sx/20
GR.TEXT.ALIGN 2
GR.TEXT.SIZE sx/12
IF thmode=1
GR.TEXT.DRAW tx,sx/2-sx/6.5-sx/7,sy/2, STR$(ROUND(am1,2))
GR.TEXT.DRAW tx,sx/2+sx/6.5-sx/7,sy/2, STR$(ROUND(am2,2))
ENDIF
IF thmode=2
GR.TEXT.DRAW tx,sx/2-sx/6.5-sx/7,sy/2, STR$(ROUND(SQR(s21),2))
GR.TEXT.DRAW tx,sx/2+sx/6.5-sx/7,sy/2, STR$(ROUND(SQR(s22),2))
ENDIF
GR.TEXT.SIZE sx/20
GR.TEXT.ALIGN 3
GR.TEXT.DRAW tx,sx-sx/13,sy/2-sy/14.5, FORMAT$("p: %.###",bnp)
IF thmode=1
GR.TEXT.DRAW tx,sx-sx/13,sy/2, FORMAT$("t: %.###",twer)
ENDIF
GR.TEXT.ALIGN 1
! // pt //
IF scm=1:GR.COLOR 255,220,220,220,1:ENDIF % // default //
IF scm=2:GR.COLOR 255,255, 30, 30,1:ENDIF % // red //
IF scm=3:GR.COLOR 255, 30,255, 30,1:ENDIF % // green //
IF scm=4:GR.COLOR 255,100,100,100,1:ENDIF % // inverted//
IF scm=5:GR.COLOR 255,100,220,100,1:ENDIF % // RGB1 //
IF scm=6:GR.COLOR 255,10,10,10,1:ENDIF % // RGB2 //
IF thmode=1
GR.TEXT.DRAW tx,sx/2+sx/4.5,sy/2+sy/40, FORMAT$("p: %.###",pval)+sgpv$
ENDIF
! // date //
IF scm=1:GR.COLOR 255,200,200,200,1:ENDIF % // default //
IF scm=2:GR.COLOR 255,255, 30, 30,1:ENDIF % // red //
IF scm=3:GR.COLOR 255, 30,255, 30,1:ENDIF % // green //
IF scm=4:GR.COLOR 255, 80, 80, 80,1:ENDIF % // inverted//
IF scm=5:GR.COLOR 255,120,120,120,1:ENDIF % // RGB1 //
IF scm=6:GR.COLOR 255,120,120,120,1:ENDIF % // RGB2 //
GR.TEXT.SIZE sx/25
GR.TEXT.ALIGN 3
GOSUB systime
GR.TEXT.DRAW tx,sx-sx/150,sy-sy/100, Y$+"."+M$+"."+D$+"/"+h$+":"+min$+":"+sec$
! //
GR.RENDER
ENDIF
! //
GR.TOUCH tc,tx,ty
IF tc: GOTO en: ENDIF
NEXT j % // over cycles M //
! //
IF swvec=1
GOSUB distout % // distribution out stream //
ENDIF
IF swout=1
GOSUB dwass % // dwass efficiency //
GOSUB logout % // log results out stream //
ENDIF
IF swdal
GOSUB datout % // raw data out stream //
ENDIF
en: % // wait... //
FOR i=1 TO 1000000
NEXT
! //
DO % // wait //
GR.TOUCH tc1,tx,ty
IF tc1
ARRAY.DELETE mP_12[]
ARRAY.DELETE pvt[]
ARRAY.DELETE m0_12[]
GOTO st
ENDIF
UNTIL 0
!!
ONERROR: GOSUB fin: END
!!
ONMENUKEY:GOSUB dialog
MENUKEY.RESUME
ONBACKKEY:GOSUB fin
END
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
! // Subroutines
rand:
INCLUDE sigma.inc
!!
rn=seed1^sgm
nx=1000*(rn-FLOOR(rn))-FLOOR(1000*(rn-FLOOR(rn)))
seed1=nx
!!
RETURN
! /////////////////////////////////////////////////////////
! // q0, t-value
tval:
am1=s1/n1 % // arithmetic mean x1 //
am2=s2/n2 % // arithmetic mean x2 //
s21=0
FOR i=1 TO n1
s21=s21+(n0_1[i]-am1)^2
NEXT
s21=s21/n1 % // sample variance s21 //
s22=0
FOR i=1 TO n2
s22=s22+(n0_2[i]-am2)^2
NEXT
s22=s22/n2 % //sample variance s22 //
SW.BEGIN thmode
SW.CASE 1
q0=am1-am2 % // AM diff 0 //
SW.BREAK
SW.CASE 2
q0=SQR(s21)-SQR(s22) % // SD diff 0 //
SW.BREAK
SW.END
twer=am1-am2
twer=twer/(SQR((s21*n1+s22*n2)/(n1+n2-2))*SQR(1/n1+1/n2))
q11=0
RETURN
! /////////////////////////////////////////////////////////
! // t probability p(t,n)
tp:
n=n1+n2
nn2=1
IF n/2 <> FLOOR(n/2)
n=n+1
ENDIF
n1_ = n
n = 1
w4 = twer
twer =POW(twer,2)
w1 = n1_/(n1_+1*twer)
w2 = SQR(1-w1)
nn1 =2*FLOOR(n1_/2)-n1_+2
pval = 1-w2
w3 = w1*w2/2
FOR i = nn1 TO n1_ STEP 2
ij = i
IF n1_ <= i | ABS(2/i*w3)<0.00001*pval
GOTO e
ENDIF
pval = pval-2/i*w3
w3 = w3*w1*(nn2/i+1)
NEXT
e:
pval = pval/2
n = n1_
tx = w4
IF twer < 0
pval = 1-pval
ENDIF
xx_t = pval
yy = -5
IF xx_t = 0 THEN GOTO g
fx = (ABS(xx_t))
fx = LOG10(fx)
yy = fx + yy
IF fx >= 0
fx = FLOOR(fx)
ELSE
fx = -1*(FLOOR(ABS(fx)))
ENDIF
zz = fx
fx = yy
IF fx >= 0
fx = FLOOR(fx)
ELSE
fx = -1*(FLOOR(ABS(fx)))
ENDIF
yy = zz-fx-1
IF yy >= 19 THEN GOTO g
IF yy < 0
xx_t = 0
GOTO g
ENDIF
IF zz >= 90
xx_t = 10^-20
fx = zz
zz = zz-20
ENDIF
ww = ABS(xx_t*POW(10,-zz ))
ww = FLOOR(ww*POW(10,yy)+0.5)
ww = ww*(POW(10,zz))*(POW(10,-yy))
IF fx >= 90
ww = 10^20
ENDIF
IF xx_t >= 0
xx_t = ww
ELSE
xx_t = ww * -1
ENDIF
g:
pval = xx_t
pval =ABS(pval)*sig % // tail //
sgpv$=""
IF pval<=0.1 THEN sgpv$="+"
IF pval<=0.05 THEN sgpv$="*"
IF pval<=0.01 THEN sgpv$="**"
twer=ABS(w4)
RETURN
! /////////////////////////////////////////////////////////
! // Binomial probabilities
binom:
q_b=1-p_b:bnp0=0
fa_n=1
FOR i=1 TO n1+n2:fa_n=fa_n*i:NEXT
FOR i=0 TO n1+n2
fa_i=1
FOR j=1 TO i:fa_i=fa_i*j:NEXT
fa_ni=1
FOR j=1 TO n1+n2-i:fa_ni=fa_ni*j:NEXT
bpP0=(fa_n/(fa_i*fa_ni))*p_b^i*q_b^(n1+n2-i)
bnp0=bnp0+bpP0
IF i=n1
bnp=bnp0 % // binomial probability //
bpP=bpP0 % // binomial Point probability //
ENDIF
NEXT
bp1=bnp % // 1-tailed binomial p //
IF bp1>0.5:bp1=1-bp1
ENDIF
bp2=2*bp1 % // 2-tailed binomial p //
RETURN
! /////////////////////////////////////////////////////////
! // Dwass efficiency
dwass:
pdw=pg/m
IF pdw>ps/m THEN pdw=ps/m
IF pdw>0 & psg>0
edp= 1-SQR((1-pdw)/pdw)*(1/SQR(m*2*PI()))
edsg= 1-SQR((1-psg)/psg)*(1/SQR(m*2*PI()))
ENDIF
RETURN
! /////////////////////////////////////////////////////////
!// n of permutations wP
perm:
p_n=1: p_n1=1: p_n2=1
FOR i=1 TO n1+n2:p_n=p_n*i:NEXT
FOR i=1 TO n1:p_n1=p_n1*i:NEXT
FOR i=1 TO n2:p_n2=p_n2*i:NEXT
perm=p_n/(p_n1*p_n2)
RETURN
! /////////////////////////////////////////////////////////
!// P vectors start position
exact:
IF n1=1 & n2=2 THEN st=0
IF n1=1 & n2=3 THEN st=9
IF n1=2 & n2=2 THEN st=25
IF n1=1 & n2=4 THEN st=49
IF n1=2 & n2=3 THEN st=74
IF n1=1 & n2=5 THEN st=124
IF n1=2 & n2=4 THEN st=160
IF n1=3 & n2=3 THEN st=250
IF n1=1 & n2=6 THEN st=370
IF n1=2 & n2=5 THEN st=419
IF n1=3 & n2=4 THEN st=566
IF n1=1 & n2=7 THEN st=811
IF n1=2 & n2=6 THEN st=875
IF n1=3 & n2=5 THEN st=1099
IF n1=4 & n2=4 THEN st=1547
IF n1=1 & n2=8 THEN st=2107
IF n1=2 & n2=7 THEN st=2188
IF n1=3 & n2=6 THEN st=2512
IF n1=4 & n2=5 THEN st=3268
IF n1=1 & n2=9 THEN st=4402
IF n1=2 & n2=8 THEN st=4502
IF n1=3 & n2=7 THEN st=4952
IF n1=4 & n2=6 THEN st=6152
IF n1=5 & n2=5 THEN st=8252
IF n1=1 & n2=10 THEN st=10772
IF n1=2 & n2=9 THEN st=10893
IF n1=3 & n2=8 THEN st=11498
IF n1=4 & n2=7 THEN st=13313
IF n1=5 & n2=6 THEN st=16943
IF n1=1 & n2=11 THEN st=22025
IF n1=2 & n2=10 THEN st=22169
IF n1=3 & n2=9 THEN st=22961
!!
IF n1=4 & n2=8 THEN st=25601
IF n1=5 & n2=7 THEN st=31541
IF n1=6 & n2=6 THEN st=41045
IF n1=1 & n2=12 THEN st=52133
IF n1=2 & n2=11 THEN st=52302
IF n1=3 & n2=10 THEN st=53316
IF n1=4 & n2=9 THEN st=57034
IF n1=5 & n2=8 THEN st=66329
!!
RETURN
! /////////////////////////////////////////////////////////
! // Dialogs
! ////////////////////////////////////////////////////////
! // main menue
dlgmain:
smb$=CHR$(9989)
GOSUB menu
std:
ARRAY.LOAD main$[], o01$,o02$,o03$,o04$,o05$,o06$,o07$,"OK",o09$
DIALOG.SELECT main,main$[], _name$+" Permutation Methods Calculator "+_ver$
SW.BEGIN main
SW.CASE 1:GOSUB dlgmode:SW.BREAK
SW.CASE 2:GOSUB dlgtheta:SW.BREAK
SW.CASE 3
swtl=swtl*-1
IF swtl=1:sig=1:ENDIF
IF swtl=-1:sig=2:ENDIF
SW.BREAK
SW.CASE 4:GOSUB dlgmethod:SW.BREAK
SW.CASE 5:GOSUB dlgm:SW.BREAK
SW.CASE 6
IF meth>2
INPUT "Seed (0 = timevalue)",seed,0
IF seed=0:GOSUB dlgseed:ENDIF
!seed1=seed
__sd_=seed
ENDIF:SW.BREAK
SW.CASE 7:GOSUB dlgopt:SW.BREAK
SW.CASE 8:IF n1&n2>0:RETURN
ELSE:GOSUB dlgmode:ENDIF:SW.BREAK
SW.CASE 9:GOSUB exit:IF exb=1:GOSUB fin:END:ENDIF:SW.BREAK
SW.END
GOSUB menu
GOTO std
RETURN
menu:
IF inpt=2:IF fi$<>"":o01$=smq$+" Input: "+fi$:ELSE