Skip to content

Commit afcf79a

Browse files
author
Bill Majoros
committedSep 3, 2019
update
1 parent 7664479 commit afcf79a

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
 

‎DataFrame.py

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# elem=df[i][j]
2929
# df.toInt()
3030
# df.toFloat()
31+
# df.colToFloat(colIndex)
3132
# header=df.getHeader()
3233
# df.hashRowNames()
3334
# df.hashColNames()
@@ -162,6 +163,9 @@ def __getitem__(self,i):
162163
def toInt(self):
163164
for row in self.matrix: row.toInt()
164165

166+
def colToFloat(self,colIndex):
167+
for row in self.matrix: row[colIndex]=float(row[colIndex])
168+
165169
def toFloat(self):
166170
for row in self.matrix: row.toFloat()
167171

‎SummaryStats.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def median(self,array):
3131
for x in array: a.append(x)
3232
a.sort()
3333
n=len(a)
34+
if(n<1): raise Exception("median is undefined for 0 elements")
3435
halfN=int(n/2)
3536
if(n%2==1): return a[halfN]
3637
return (a[halfN-1]+a[halfN])/2

‎parse-stan.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
#=========================================================================
3+
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
4+
# License (GPL) version 3, as described at www.opensource.org.
5+
# Author: William H. Majoros (bmajoros@alumni.duke.edu)
6+
#=========================================================================
7+
from __future__ import (absolute_import, division, print_function,
8+
unicode_literals, generators, nested_scopes, with_statement)
9+
from builtins import (bytes, dict, int, list, object, range, str, ascii,
10+
chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
11+
# The above imports should allow this program to run in both Python 2 and
12+
# Python 3. You might need to update your version of module "future".
13+
import sys
14+
import ProgramName
15+
from StanParser import StanParser
16+
17+
#=========================================================================
18+
# main()
19+
#=========================================================================
20+
if(len(sys.argv)<3):
21+
exit(ProgramName.get()+" <infile.txt> <var1> <var2> ...\n")
22+
infile=sys.argv[1]
23+
variables=sys.argv[2:]
24+
25+
parser=StanParser(infile)
26+
#(median,mean,SD,min,max)=parser.getSummary(variable)
27+
#print("# posterior median=",median,sep="")
28+
samplesByVar=[]
29+
n=0
30+
for var in variables:
31+
samples=parser.getVariable(var)
32+
samplesByVar.append(samples)
33+
n=len(samples)
34+
for i in range(n):
35+
line=[]
36+
for sample in samplesByVar: line.append(str(sample[i]))
37+
print("\t".join(line))
38+
39+
40+

‎summarize-stan.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
#=========================================================================
3+
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
4+
# License (GPL) version 3, as described at www.opensource.org.
5+
# Author: William H. Majoros (bmajoros@alumni.duke.edu)
6+
#=========================================================================
7+
from __future__ import (absolute_import, division, print_function,
8+
unicode_literals, generators, nested_scopes, with_statement)
9+
from builtins import (bytes, dict, int, list, object, range, str, ascii,
10+
chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
11+
# The above imports should allow this program to run in both Python 2 and
12+
# Python 3. You might need to update your version of module "future".
13+
import sys
14+
import ProgramName
15+
from StanParser import StanParser
16+
17+
#=========================================================================
18+
# main()
19+
#=========================================================================
20+
if(len(sys.argv)<3):
21+
exit(ProgramName.get()+" <infile.txt> <var1> <var2> ...\n")
22+
infile=sys.argv[1]
23+
variables=sys.argv[2:]
24+
25+
parser=StanParser(infile)
26+
print("variable\tmedian\tSD")
27+
for var in variables:
28+
(median,mean,SD,min,max)=parser.getSummary(var)
29+
print(var,round(median,4),round(SD,5),sep="\t")
30+
31+

0 commit comments

Comments
 (0)