-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsalstat.py
executable file
·2621 lines (2433 loc) · 91.3 KB
/
salstat.py
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
#!/usr/local/bin/python
"""SalStat Statistics Package. Copyright 2002 Alan James Salmoni. Licensed
under the GNU General Public License (GPL). See the file COPYING for full
details of this license. """
# import wx stuff
from __future__ import unicode_literals
import codecs
import numpy, math
import numpy.ma as ma
import wx
from wx.stc import *
import wx.grid as gridlib
import gridbase
import wx.html as htmllib
import wx.html2 as html2lib
import bs4 as BS
#import xlrd, xlwt # import xls format
import string, os, os.path, pickle, csv, sys
import urllib, requests #, urlparse,
import urllib.parse as urlparse
# import SalStat specific modules
import salstat_stats, images, tabler, ChartWindow
import DescriptivesFrame, PrefsFrame
import MetaGrid, AllRoutines, ImportCSV, ImportSS, ImportHTML, Inferentials
import sas7bdat as sas
import TestThreeConditions, TestTwoConditions, TestCorrelations, TestOneCondition
import exportSQLite
from xml.dom import minidom
#---------------------------------------------------------------------------
# set up id's for menu events - all on menu, some also available elsewhere
ID_FILE_NEW = wx.NewId()
ID_FILE_NEWOUTPUT = wx.NewId()
ID_FILE_OPEN = wx.NewId()
ID_FILE_URL = wx.NewId()
ID_FILE_DB = wx.NewId()
ID_FILE_APPEND = wx.NewId()
ID_FILE_SAVE = wx.NewId()
ID_FILE_SAVEAS = wx.NewId()
ID_FILE_EXPORT = wx.NewId()
ID_FILE_PRINT = wx.NewId()
ID_FILE_EXIT = wx.NewId()
ID_EDIT_UNDO = wx.NewId()
ID_EDIT_REDO = wx.NewId()
ID_EDIT_CUT = wx.NewId()
ID_EDIT_COPY = wx.NewId()
ID_EDIT_PASTE = wx.NewId()
ID_EDIT_SELECTALL = wx.NewId()
ID_EDIT_FIND = wx.NewId()
ID_EDIT_DELETECOL = wx.NewId()
ID_EDIT_DELETEROW = wx.NewId()
ID_EDIT_INSERTCOL = wx.NewId()
ID_EDIT_INSERTROW = wx.NewId()
ID_CLEAR_CELLS = wx.NewId()
ID_PREF_DATA = wx.NewId()
ID_PREF_VARIABLES = wx.NewId()
ID_PREF_GRID = wx.NewId()
ID_PREF_CELLS = wx.NewId()
ID_PREF_FONTS = wx.NewId()
ID_PREF_GEN = wx.NewId()
ID_PREPARATION_DESCRIPTIVES = wx.NewId()
ID_PREPARATION_TRANSFORM = wx.NewId()
ID_PREPARATION_OUTLIERS = wx.NewId()
ID_PREPARATION_NORMALITY = wx.NewId()
ID_TRANSFORM_SQUAREROOT = wx.NewId()
ID_TRANSFORM_SQUARE = wx.NewId()
ID_TRANSFORM_INVERSE = wx.NewId()
ID_TRANSFORM_OTHER = wx.NewId()
ID_ANALYSE_1COND = wx.NewId()
ID_ANALYSE_2COND = wx.NewId()
ID_ANALYSE_3COND = wx.NewId()
ID_ANALYSE_CORRELATION = wx.NewId()
ID_ANALYSE_2FACT = wx.NewId()
ID_ANALYSE_SCRIPT = wx.NewId()
ID_ANALYSE2_1COND = wx.NewId()
ID_ANALYSE2_2COND = wx.NewId()
ID_ANALYSE2_3COND = wx.NewId()
ID_ANALYSE2_1_TTEST = wx.NewId()
ID_ANALYSE2_1_SIGN = wx.NewId()
ID_CHART = wx.NewId()
ID_CHART_DRAW = wx.NewId()
ID_BARCHART_DRAW = wx.NewId()
ID_HELP_WIZARD = wx.NewId()
ID_HELP_TOPICS = wx.NewId()
ID_HELP_SCRIPTING = wx.NewId()
ID_HELP_LICENCE = wx.NewId()
ID_HELP_ABOUT = wx.NewId()
ID_OFILE_NEW = wx.NewId()
ID_OFILE_OPEN = wx.NewId()
ID_OFILE_SAVE = wx.NewId()
ID_OFILE_SAVEAS = wx.NewId()
ID_OFILE_PRINT = wx.NewId()
ID_OFILE_QUIT = wx.NewId()
ID_OEDIT_UNDO = wx.NewId()
ID_OEDIT_REDO = wx.NewId()
ID_OEDIT_CUT = wx.NewId()
ID_OEDIT_COPY = wx.NewId()
ID_OEDIT_PASTE = wx.NewId()
ID_OEDIT_SELECTALL = wx.NewId()
ID_OEDIT_FIND = wx.NewId()
ID_OPREF_FONT = wx.NewId()
ID_FILE_GSAVEAS = wx.NewId()
ID_FILE_GPRINTSETUP = wx.NewId()
ID_FILE_GPRINTPREVIEW = wx.NewId()
ID_FILE_GPRINT = wx.NewId()
ID_FILE_GCLOSE = wx.NewId()
ID_TITLE_GYAXIS = wx.NewId()
ID_TITLE_GXAXIS = wx.NewId()
ID_TITLE_GTITLE = wx.NewId()
ID_TITLE_LEGEND = wx.NewId()
ID_TITLE_GRID = wx.NewId()
ID_FIND_STRING = wx.NewId()
DescList=['N','Sum','Mean','Variance','Standard Deviation','Standard Error',\
'Sum of Squares','Sum of Squared Devs', \
'Coefficient of Variation','Minimum', \
'Maximum','Range','Number Missing', \
'Geometric Mean','Harmonic Mean', \
'Skewness','Kurtosis', 'Median', \
'Median Absolute Deviation','Mode', \
'Interquartile Range', \
'Number of Unique Levels']
HypList = ['One tailed','Two tailed']
inits={} # dictionary to hold the config values
ColsUsed = []
RowsUsed = []
missingvalue = -99.999
global filename # ugh
filename = 'UNTITLED'
global BWidth, BHeight # ugh again!
BWidth = 80
BHeight = 25
HOME = os.getcwd()+'/'
base_file_name = os.path.abspath(__file__)
basedir, script_name = os.path.split(base_file_name)
if wx.Platform == '__WXMSW__':
face1 = 'Courier New'
face2 = 'Times New Roman'
face3 = 'Courier New'
fontsizes = [7,8,10,12,16,22,30]
pb = 12
wind = 50
DOCDIR = 'c:\My Documents'
INITDIR = os.getcwd()
CONFIGFILE = "salstatrc"
# I got the following lines from the wxPython group but it's a red herring
# it was to ensure Javascript files would load properly.
# The solution was to use WebView.LoadURL not WebView.SetPage :-)
import _winreg as wreg
current_file = __file__
key = wreg.CreateKey(wreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION")
wreg.SetValueEx(key, current_file, 0, wreg.REG_DWORD, 10001)
elif wx.Platform == '__WXMAC__':
face1 = 'Helvetica'
face2 = 'Times'
face3 = 'Courier'
fontsizes = [10,12,14,16,19,24,32]
pb = 12
wind = 50
DOCDIR = os.path.expanduser('~') + '/Library/Application Support/Salstat/'
CONFIGFILE = "salstatrc"
INITDIR = DOCDIR
else:
face1 = 'Helvetica'
face2 = 'Times'
face3 = 'Courier'
fontsizes = [10,12,14,16,19,24,32]
pb = 12
wind = 50
DOCDIR = os.environ['HOME']
CONFIGFILE = ".salstatrc"
INITDIR = DOCDIR
def FileToURL(path):
return urlparse.urljoin('file:', urllib.request.pathname2url(path))
class History:
def __init__(self):
self.history = '' # change this for the proper DTD please!
def AppendEvent(self, xmltags):
self.history = self.history + xmltags
def ClearHistory(self):
self.history = ''
class SaveDialog(wx.Dialog):
def __init__(self, parent, id):
wx.Dialog.__init__(self, parent, id, "Save Data?", \
size=(404+wind,100+wind))#, style = wx.DIALOG_MODAL)
icon = images.getIconBitmap()
#icon = wx.Icon("icons/PurpleIcon05_32.png",wx.BITMAP_TYPE_PNG)
iconPNG = wx.Image("icons/PurpleIcon05_64.png",wx.BITMAP_TYPE_PNG).ConvertToBitmap()
iconBMP = wx.StaticBitmap(self, -1, iconPNG, pos=(20,16))
l1 = wx.StaticText(self, -1, 'Do you want to save the changes you made to', pos=(105,16))
l2 = wx.StaticText(self, -1, 'this document?', pos=(105, 36))
discardButton = wx.Button(self, 332, "Don't save", size=(90, 21),pos=(105,80))
saveButton = wx.Button(self, 331, "Save...", size=(69, 21),pos=(274,80))
CancelButton = wx.Button(self, 333, "Cancel", size=(69, 21),pos=(355,80))
self.SetIcon(ico)
saveButton.SetDefault()
self.Layout()
self.Bind(wx.EVT_BUTTON, self.SaveData, id=331)
self.Bind(wx.EVT_BUTTON, self.DiscardData, id=332)
self.Bind(wx.EVT_BUTTON, self.CancelDialog, id=333)
def SaveData(self, event):
self.EndModal(2)
self.ExitVal = 2
def DiscardData(self, event):
self.EndModal(3)
self.ExitVal = 3
def CancelDialog(self, event):
self.EndModal(4)
self.ExitVal = 4
def GetVals(self):
return self.ExitVal
################################################
# wx.FileDialog to retrieve file name. Needed before we can do anything
class GetFilename(object):
def __init__(self, parent, startDir):
dlg = wx.FileDialog(parent, message="Open a CSV file", defaultDir=startDir, \
wildcard="CSV text (*.csv)|*.csv|Plain text (*.txt)|*.txt|\
Data file (*.dat)|*.dat|Any file (*.*)|*.*")
ico = wx.Icon('icons/PurpleIcon05_32.png',wx.BITMAP_TYPE_PNG)
dlg.SetIcon(ico)
if dlg.ShowModal() == wx.ID_OK:
self.fileName = dlg.GetPath()
if os.path.exists(self.fileName):
self.fileName
else:
self.fileName = None
else:
self.fileName = None
#---------------------------------------------------------------------------
# creates an init file in the home directory of the user
class GetInits:
"""This class deals with a users init file. The coords and sizes of the
various widgets are kept here, and are stored throughout the program
as a dictionary for easy access. When the program starts, the home
directory is checked for the init files existence. If absent, it is
created with a series of default values. If it is present, the values are
read into the dictionary in a slightly roundabout way! I am sure that
there is a more "Python" way of doing this, but this way works for now"""
def __init__(self):
self.initfile = os.path.join(INITDIR, CONFIGFILE)
if os.path.isfile(self.initfile):
self.ReadInitFile(self.initfile)
else:
self.CreateInitFile(self.initfile)
def ReadInitFile(self, initfilename):
inits.clear()
try:
fin = open(initfilename, 'r')
for i in range(28):
a = fin.readline()
a = a.strip('\n').split(' ')
tmpdict = {a[0]:a[1]}
inits.update(tmpdict)
fin.close()
except IndexError:
self.CreateInitFile(self.initfile)
def CreateInitFile(self, initfilename):
inits = {
'gridsizex': '600',
'gridsizey': '420',
'gridposx': '50',
'gridposy': '20',
'gridcellsx': '20',
'gridcellsy': '80',
'outputsizex': '500',
'outputsizey': '400',
'outputposx': '20',
'outputposy': '50',
'scriptsizex': '600',
'scriptsizey': '400',
'scriptposx': '35',
'scriptposy': '35',
'chartsizex': '600',
'chartsizey': '400',
'chartposx': '50',
'chartposy': '50',
'helpsizex': '600',
'helpsizey': '400',
'helpposx': '40',
'helpposy': '40',
'lastfile1': "...",
'lastfile2': "...",
'lastfile3': "...",
'lastfile4': "...",
'opendir': DOCDIR,
'savedir': DOCDIR
}
initskeys = list(inits.keys())
initsvalues = list(inits.values())
fout = open(initfilename,'w')
for i in range(len(initskeys)):
fout.write(str(initskeys[i])+' '+str(initsvalues[i])+'\n')
fout.close()
self.ReadInitFile(initfilename) # damn hack!
#---------------------------------------------------------------------------
# method to calculate the descriptives with multiple grouping variables
def GetGroups(groupingvars):
groups = []
k = len(groupingvars)
N = len(groupingvars[0])
for idx in range(N):
row = [var[idx] for var in groupingvars]
if row not in groups:
groups.append(row)
groups.sort()
return groups
def ExtractGroupsData(group, groupingvars, variable):
N = len(variable)
if isinstance(variable, list):
data = []
for idx in range(N):
row = [element[idx] for element in groupingvars]
if group == row:
data.append(variable[idx])
return data
else:
indices = []
for idx in range(N):
row = [element[idx] for element in groupingvars]
if group == row:
indices.append(True)
else:
indices.append(False)
indices = ma.array(indices)
return variable[indices]
def ConvertToNumbers(dataIn, missingvalues=[]):
maxIdx = len(dataIn)
data = ma.zeros(maxIdx,dtype='float')
for row in range(maxIdx):
val = dataIn[row]
if (val in missingvalues):
data[row] = ma.masked
else:
try:
data[row] = float(val)
if math.isnan(data[row]):
data[row] = ma.masked
except ValueError:
data[row] = ma.masked
return data
def GroupedDescriptives(groups, groupingvars, variables, stats, groupnames, varnames,alpha):
notests = ['Frequencies','Proportions','Percentages', 'Relative frequency of the mode', \
'Trimmed mean', 'Bi-trimmed mean', 'Mode', 'Moment']
table = '<h3>Descriptive statistics</h3>\n<table class="table table-striped">\n'
table += '\t<tr><th>Variable</th>'
for groupname in groupnames:
table += '<th>%s</th>'%(groupname)
for stat in stats:
if stat not in notests:
table += '<th>%s</th>'%(stat)
if stat == "Count":
table += '<th>%s</th>'%("Missing")
table += '</tr>\n'
k = len(groups)
for idx, var in enumerate(variables):
table += '\t<tr>'
#for varname in scorenames:
table += '<td rowspan="%d">%s</td>'%(k, varnames[idx])
for group in groups:
for element in group:
table += '<td>%s</td>'%element
data = ExtractGroupsData(group, groupingvars, var)
data = ConvertToNumbers(data)
if "Count" in stats:
val = AllRoutines.Count(data)
table += '<td>%s</td>'%str(val)
if "Count" in stats:
val = AllRoutines.NumberMissing(data)
table += '<td>%s</td>'%str(val)
if "Sum" in stats:
val = AllRoutines.Sum(data)
table += '<td>%s</td>'%str(val)
if "Minimum" in stats:
val = AllRoutines.Minimum(data)
table += '<td>%s</td>'%str(val)
if "Maximum" in stats:
val = AllRoutines.Maximum(data)
table += '<td>%s</td>'%str(val)
if "Range" in stats:
val = AllRoutines.Range(data)
table += '<td>%s</td>'%str(val)
if "Cumulative sum" in stats:
val = AllRoutines.CumSum(data)
table += '<td>%s</td>'%str(val)
if "Cumulative product" in stats:
val = AllRoutines.CumProd(data)
table += '<td>%s</td>'%str(val)
if "Cumulative percent" in stats:
val = AllRoutines.CumPercent(data)
table += '<td>%s</td>'%str(val)
if "Mean" in stats:
val = AllRoutines.Mean(data)
table += '<td>%s</td>'%str(val)
if "Median" in stats:
val = AllRoutines.Median(data)
table += '<td>%s</td>'%str(val)
if "Quartiles" in stats:
val = AllRoutines.Quartiles(data)
table += '<td>%s, %s</td>'%(str(val[0]), str(val[1]))
if "Tukey's hinges" in stats:
val = AllRoutines.TukeyQuartiles(data)
table += '<td>%s, %s</td>'%(str(val[0]), str(val[1]))
if "Moore & McCabe's hinges" in stats:
val = AllRoutines.MooreQuartiles(data)
table += '<td>%s, %s</td>'%(str(val[0]),str(val[1]))
if "S-Plus quantiles" in stats:
val = AllRoutines.SPQuantile(data,alpha)
table += '<td>%s</td>'%str(val)
if "SPSS quantiles" in stats:
val = AllRoutines.TradQuantile(data,alpha)
table += '<td>%s</td>'%str(val)
if "Mid-step quantiles" in stats:
val = AllRoutines.MidstepQuantile(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 1 (Hyndman & Fan)" in stats:
val = AllRoutines.Q1(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 2 (Hyndman & Fan)" in stats:
val = AllRoutines.Q2(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 3 (Hyndman & Fan)" in stats:
val = AllRoutines.Q3(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 4 (Hyndman & Fan)" in stats:
val = AllRoutines.Q4(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 5 (Hyndman & Fan)" in stats:
val = AllRoutines.Q5(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 6 (Hyndman & Fan)" in stats:
val = AllRoutines.Q6(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 7 (Hyndman & Fan)" in stats:
val = AllRoutines.Q7(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 8 (Hyndman & Fan)" in stats:
val = AllRoutines.Q8(data,alpha)
table += '<td>%s</td>'%str(val)
if "Quantile 9 (Hyndman & Fan)" in stats:
val = AllRoutines.Q9(data,alpha)
table += '<td>%s</td>'%str(val)
if "Interquartile range" in stats:
val = AllRoutines.InterquartileRange(data)
table += '<td>%s</td>'%str(val)
if "Sum of squares" in stats:
val = AllRoutines.SS(data)
table += '<td>%s</td>'%str(val)
if "Sum of squared deviations" in stats:
val = AllRoutines.SSDevs(data)
table += '<td>%s</td>'%str(val)
if "Variance (sample)" in stats:
val = AllRoutines.SampVar(data)
table += '<td>%s</td>'%str(val)
if "Variance (population)" in stats:
val = AllRoutines.PopVar(data)
table += '<td>%s</td>'%str(val)
if "Standard deviation (sample)" in stats:
val = AllRoutines.SampStdDev(data)
table += '<td>%s</td>'%str(val)
if "Standard deviation (population)" in stats:
val = AllRoutines.PopStdDev(data)
table += '<td>%s</td>'%str(val)
if "Standard error" in stats:
val = AllRoutines.StdErr(data)
table += '<td>%s</td>'%str(val)
if "Coefficient of variation" in stats:
val = AllRoutines.CoeffVar(data)
table += '<td>%s</td>'%str(val)
if "Median absolute deviation" in stats:
val = AllRoutines.MAD(data)
table += '<td>%s</td>'%str(val)
if "Geometric mean" in stats:
val = AllRoutines.GeometricMean(data)
table += '<td>%s</td>'%str(val)
if "Harmonic mean" in stats:
val = AllRoutines.HarmonicMean(data)
table += '<td>%s</td>'%str(val)
if "Mean of successive squared differences" in stats:
val = AllRoutines.MSSD(data)
table += '<td>%s</td>'%str(val)
if "Skewness" in stats:
val = AllRoutines.Skewness(data)
table += '<td>%s</td>'%str(val)
if "Kurtosis" in stats:
val = AllRoutines.Kurtosis(data)
table += '<td>%s</td>'%str(val)
"""
if "Trimmed mean" in stats:
val = AllRoutines.TrimmedMean(data,alpha)
table += '<td>%s</td>'%str(val)
"""
table += '</tr>\n'
table += '</tr>\n'
table += '</table>\n<p /><br />\n'
output.Addhtml(table)
#---------------------------------------------------------------------------
# class to output the results of several "descriptives" in one table
class ManyDescriptives:
def __init__(self, stats, variables, variablesr, names, alpha):
#__x__ = len(ds)
str2 = '<h3>Descriptive statistics</h3>\n<table class="table table-striped">'
outlist = ['Statistic']
for name in names:
outlist.append(name)
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Count" in stats:
outlist = ['N']
for var in variables:
#outlist.append(i.N)
outlist.append(AllRoutines.Count(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
outlist = ["Missing"]
for var in variables:
outlist.append(AllRoutines.NumberMissing(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Sum" in stats:
outlist = ['Sum']
for var in variables:
outlist.append(AllRoutines.Sum(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Minimum" in stats:
outlist = ['Minimum']
for var in variables:
outlist.append(AllRoutines.Minimum(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Maximum" in stats:
outlist = ['Maximum']
for var in variables:
outlist.append(AllRoutines.Maximum(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Range" in stats:
outlist = ['Range']
for var in variables:
outlist.append(AllRoutines.Range(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Midrange" in stats:
outlist = ['Midrange']
for var in variables:
outlist.append(AllRoutines.Midrange(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Relative frequency of the mode" in stats:
outlist = ['RelFreqMode']
for var in variables:
outlist.append(AllRoutines.RelFreqMode(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Cumulative sum" in stats:
outlist = ['CumSum']
for var in variables:
outlist.append(AllRoutines.CumSum(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Cumulative product" in stats:
outlist = ['CumProduct']
for var in variables:
outlist.append(AllRoutines.CumProduct(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Cumulative percent" in stats:
outlist = ['CumPercent']
for var in variables:
outlist.append(AllRoutines.CumPercent(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Mean" in stats:
outlist = ['Mean']
for var in variables:
outlist.append(AllRoutines.Mean(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Median" in stats:
outlist = ['Median']
for var in variables:
outlist.append(AllRoutines.Median(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Tukey's hinges" in stats:
outlist = ["Tukey's hinges"]
for var in variables:
outlist.append(AllRoutines.TukeyQuartiles(var))
ln = tabler.tableHinges(outlist)
str2 = str2 + ln
if "Moore & McCabe's hinges" in stats:
outlist = ["Moore & McCabe's hinges"]
for var in variables:
outlist.append(AllRoutines.MooreQuartiles(var))
ln = tabler.tableHinges(outlist)
str2 = str2 + ln
if "Interquartile range" in stats:
outlist = ["Interquartile range"]
for var in variables:
outlist.append(AllRoutines.InterquartileRange(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Sum of squares" in stats:
outlist = ["Sum of squares"]
for var in variables:
outlist.append(AllRoutines.SS(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Sum of squared deviations" in stats:
outlist = ["Sum of squared deviations"]
for var in variables:
outlist.append(AllRoutines.SSDevs(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Variance (sample)" in stats:
outlist = ['Variance (sample)']
for var in variables:
outlist.append(AllRoutines.SampVar(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Variance (population)" in stats:
outlist = ['Variance (population)']
for var in variables:
outlist.append(AllRoutines.PopVar(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Standard deviation (sample)" in stats:
outlist = ['Standard Deviation (sample)']
for var in variables:
outlist.append(AllRoutines.SampStdDev(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Standard deviation (population)" in stats:
outlist = ['Standard deviation (population)']
for var in variables:
outlist.append(AllRoutines.PopStdDev(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Standard error" in stats:
outlist = ['Standard error']
for var in variables:
outlist.append(AllRoutines.StdErr(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quartiles" in stats:
outlist = ['Quartiles']
for var in variables:
val = AllRoutines.Quartiles(var)
outlist.append((val[0], val[2]))
ln = tabler.tableHinges(outlist)
str2 = str2 + ln
if "Coefficient of variation" in stats:
outlist = ['Coefficient of variation']
for var in variables:
outlist.append(AllRoutines.CoeffVar(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Median absolute deviation" in stats:
outlist = ['Median absolute deviation']
for var in variables:
outlist.append(AllRoutines.MAD(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Trimmed mean" in stats:
outlist = ['Trimmed mean']
for var in variables:
outlist.append(AllRoutines.TrimmedMean(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Geometric mean" in stats:
outlist = ['Geometric mean']
for var in variables:
outlist.append(AllRoutines.GeometricMean(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Harmonic mean" in stats:
outlist = ['Harmonic mean']
for var in variables:
outlist.append(AllRoutines.HarmonicMean(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Mean of subsequent squared differences" in stats:
outlist = ['Mean of subsequent squared differences']
for var in variables:
outlist.append(AllRoutines.MSSD(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Skewness" in stats:
outlist = ['Skewness']
for var in variables:
outlist.append(AllRoutines.Skewness(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Kurtosis" in stats:
outlist = ['Kurtosis']
for var in variables:
outlist.append(AllRoutines.Kurtosis(var))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "S-Plus quantiles" in stats:
outlist = ['S-Plus quantiles']
for var in variables:
outlist.append(AllRoutines.SPQuantile(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "SPSS quantiles" in stats:
outlist = ['SPSS quantiles']
for var in variables:
outlist.append(AllRoutines.TradQuantile(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Mid-step quantiles" in stats:
outlist = ['Mid-step quantiles']
for var in variables:
outlist.append(AllRoutines.MidstepQuantiles(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 1 (Hyndman & Fan)" in stats:
outlist = ['Quantile 1 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q1(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 2 (Hyndman & Fan)" in stats:
outlist = ['Quantile 2 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q2(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 3 (Hyndman & Fan)" in stats:
outlist = ['Quantile 3 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q3(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 4 (Hyndman & Fan)" in stats:
outlist = ['Quantile 4 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q4(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 5 (Hyndman & Fan)" in stats:
outlist = ['Quantile 5 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q5(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 6 (Hyndman & Fan)" in stats:
outlist = ['Quantile 6 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q6(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 7 (Hyndman & Fan)" in stats:
outlist = ['Quantile 7 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q7(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 8 (Hyndman & Fan)" in stats:
outlist = ['Quantile 8 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q8(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
if "Quantile 9 (Hyndman & Fan)" in stats:
outlist = ['Quantile 9 (Hyndman & Fan)']
for var in variables:
outlist.append(AllRoutines.Q9(var,alpha))
ln = tabler.vtable(outlist)
str2 = str2 + ln
"""
if "Trimmed mean" in stats:
val = AllRoutines.TrimmedMean(data,alpha)
table += '<td>%s</td>'%str(val)
"""
str2 += '</table>\n'
if ("Frequencies" in stats) \
or ("Proportions" in stats) \
or ("Percentages" in stats):
for idx, var in enumerate(variablesr):
vals = {}
if "Frequencies" in stats:
values, freqs = AllRoutines.Frequencies(var)
ln = tabler.vtable(['Number of items',len(values)])
str2 += ln
vals['values'] = values
vals['freqs'] = freqs
else:
vals['freqs'] = None
if "Proportions" in stats:
values, props = AllRoutines.Proportions(var)
vals['props'] = props
else:
vals['props'] = None
if "Percentages" in stats:
values, percs = AllRoutines.Percentages(var)
vals['percs'] = percs
else:
vals['percs'] = None
ln = tabler.tableMultiples(vals, names[idx])
str2 += ln
if "Mode" in stats:
outlist = []
for var in variables:
outlist.append(AllRoutines.Mode(var))
ln = tabler.tableMode(outlist)
str2 = str2 + ln
str2 += '<p /><br />\n'
output.Addhtml(str2)
#---------------------------------------------------------------------------
# DescChoice-wx.CheckListBox with list of descriptive stats in it
class DescChoiceBox(wx.CheckListBox):
def __init__(self, parent, id):
self.test_list = AllRoutines.GetMostUsedTests()
wx.CheckListBox.__init__(self, parent, -1, pos=(250,30), \
size=(240,310), choices=self.test_list)
self.SetCheckedItems([0,1,2,5,6,7])
def SelectAllDescriptives(self, event):
for i in range(len(self.test_list)):
self.Check(i, True)
def SelectNoDescriptives(self, event):
for i in range(len(self.test_list)):
self.Check(i, False)
#---------------------------------------------------------------------------
# base class for getting number of columns/rows to add
class EditGridFrame(wx.Dialog):
def __init__(self, parent, id):
wx.Dialog.__init__(self, parent, id, "Change Grid Size", \
size=(205, 100+wind))
self.SetIcon(ico)
l1 = wx.StaticText(self, -1, 'Add Columns',pos=(10,15))
l2 = wx.StaticText(self, -1, 'Add Rows',pos=(10,55))
self.numnewcols = wx.SpinCtrl(self, -1, "", wx.Point(110,10), wx.Size(80,25))
self.numnewcols.SetRange(0, 100)
self.numnewcols.SetValue(0)
self.numnewRows = wx.SpinCtrl(self, -1, "", wx.Point(110, 50), wx.Size(80,25))
self.numnewRows.SetRange(0, 100)
self.numnewRows.SetValue(0)
okaybutton = wx.Button(self, 421, "Okay", wx.Point(10, 90),\
wx.Size(BWidth, BHeight))
cancelbutton = wx.Button(self, 422, "Cancel", wx.Point(110,90), \
wx.Size(BWidth, BHeight))
self.Bind(wx.EVT_BUTTON, self.OkayButtonPressed, id=421)
self.Bind(wx.EVT_BUTTON, self.CancelButtonPressed, id=422)
def OkayButtonPressed(self, event):
colswanted = self.numnewcols.GetValue()
rowswanted = self.numnewRows.GetValue()
frame.grid.AddNCells(colswanted, rowswanted)
self.Close(True)
def CancelButtonPressed(self, event):
self.Close(True)
#---------------------------------------------------------------------------
# shows the scripting window for entering Python syntax commands
class ScriptFrame(wx.Frame):
def __init__(self, parent, id):
dimx = int(inits.get('scriptsizex'))
dimy = int(inits.get('scriptsizey'))
posx = int(inits.get('scriptposx'))
posy = int(inits.get('scriptposy'))
wx.Frame.__init__(self, parent, id, "Scripting Window", \
size=(dimx, dimy), pos=(posx,posy))
#set icon for frame (needs x-platform separator!
self.SetIcon(ico)
#self.scripted = wx.Editor(self,-1)
GoIcon = images.getApplyBitmap()
OpenIcon = images.getOpenBitmap()
SaveIcon = images.getSaveBitmap()
SaveAsIcon = images.getSaveAsBitmap()
PrintIcon = images.getPrintBitmap()
CutIcon = images.getCutBitmap()
CopyIcon = images.getCopyBitmap()
PasteIcon = images.getPasteBitmap()
HelpIcon = images.getHelpBitmap()
toolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER| \
wx.TB_3DBUTTONS|wx.TB_TEXT)
toolBar.AddLabelTool(710, "Run script", wx.Bitmap("icons/IconNew.png"), shortHelp="Run this script now")
toolBar.AddLabelTool(711, "Open", wx.Bitmap("icons/IconOpen.png"), shortHelp="Open a script from a file")
toolBar.AddLabelTool(712, "Save", wx.Bitmap("icons/IconSave.png"), shortHelp="Save this script to file")
toolBar.AddLabelTool(713, "Save As", wx.Bitmap("icons/IconSaveAs.png"), shortHelp="Save this script to a file")
toolBar.AddLabelTool(714, "Print", wx.Bitmap("icons/IconPrint.png"), shortHelp="Print out this script")
toolBar.AddLabelTool(715, "Cut", wx.Bitmap("icons/IconCut.png"), shortHelp="Cut selection to clipboard")
toolBar.AddLabelTool(716, "Copy", wx.Bitmap("icons/IconCopy.png"), shortHelp="Copy selection to clipboard")
toolBar.AddLabelTool(717, "Paste", wx.Bitmap("icons/IconPaste.png"), shortHelp="Paste selection from clipboard")
toolBar.AddLabelTool(718, "Help", wx.Bitmap("icons/IconHelp.png"), shortHelp="See the help documents")
"""
toolBar.AddLabelTool(710, "Run Script",GoIcon,"Run the Script")
toolBar.AddLabelTool(711, OpenIcon,"Open","Open Script from a File")
toolBar.AddLabelTool(712, SaveIcon,"Save","Save Script to a file")
toolBar.AddLabelTool(713, SaveAsIcon,"Save As","Save Script under \
a new filename")
toolBar.AddLabelTool(714, PrintIcon,"Print","Print Out Script")
toolBar.AddLabelTool(715, CutIcon, "Cut", "Cut selection to \
clipboard")
toolBar.AddLabelTool(716, CopyIcon, "Copy", "Copy selection to \
clipboard")
toolBar.AddLabelTool(717, PasteIcon, "Paste", "Paste selection \
from clipboard")
toolBar.AddLabelTool(718, HelpIcon, "Help", "Get some help!")
"""
toolBar.SetToolBitmapSize((24,24))
toolBar.Realize()
self.Bind(wx.EVT_TOOL, self.ExecuteScript, id=710)
self.Bind(wx.EVT_TOOL, self.OpenScript, id=711)
self.Bind(wx.EVT_TOOL, self.SaveScriptAs, id=713)
self.Bind(wx.EVT_TOOL, self.CutSelection, id=715)
self.Bind(wx.EVT_TOOL, self.CopySelection, id=716)
self.Bind(wx.EVT_TOOL, self.PasteSelection, id=717)
self.Bind(wx.EVT_TOOL, self.ShowHelp, id=718)
def ExecuteScript(self, event):
mainscript = self.scripted.GetText()
execscript = string.join(mainscript, '\n')
exec(execscript)
def CutSelection(self, event):
self.scripted.OnCutSelection(event)
def CopySelection(self, event):
self.scripted.OnCopySelection(event)
def PasteSelection(self, event):
self.scripted.OnPaste(event)
def ShowHelp(self, event):
win = AboutFrame(frame, -1, 2)
win.Show(True)