def ttest_table(ttest_table_name, tcrit, tables1, tables2, xcolname, ycolname):

    assert (len(tables1) == len(tables2))

    colnames = [xcolname, 'Mean', 'StdDev', 'Sig', 'tval', 'pval']
    xcoltype = tables1[0].coltypes[tables1[0].colnames.index(xcolname)]
    coltypes = [xcoltype, 'float', 'float', 'int', 'float', 'float']

    xvalues = common_functions.get_timesteps(tables1 + tables2, xcolname)

    result = datalib.Table(ttest_table_name, colnames, coltypes)

    for x in xvalues:
        data1 = [table[x][ycolname] for table in tables1]
        data2 = [table[x][ycolname] for table in tables2]

        diffMean, stdDev, tval, pval = ttest(data1, data2)

        row = result.createRow()

        row[xcolname] = x
        row["Mean"] = diffMean
        row["StdDev"] = stdDev
        if tval >= tcrit:
            row["Sig"] = 1
        else:
            row["Sig"] = 0
        row["tval"] = tval
        row["pval"] = pval

    return result
def avr_table_from_tables( avr_table_name, tables, xcolname, ycolname ):
	colnames = [xcolname, 'min', 'q1', 'median', 'q3', 'max', 'mean', 'mean_stderr', 'sampsize']
	xcoltype = tables[0].coltypes[ tables[0].colnames.index(xcolname) ]
	coltypes = [xcoltype, 'float', 'float', 'float', 'float', 'float', 'float', 'float', 'int']

	result = datalib.Table(avr_table_name, colnames, coltypes)

	xvalues = common_functions.get_timesteps( tables, xcolname )

	for x in xvalues:
		ydata = []
		for table in tables:
			ydata.append( table[x][ycolname] )
		ydata.sort()
                        
                minimum, maximum, mean, mean_stderr, q1, q3, median = avr(ydata)

		row = result.createRow()
		row.set(xcolname, x)
		row.set('min', minimum)
		row.set('max', maximum)
		row.set('mean', mean)
		row.set('mean_stderr', mean_stderr)
		row.set('median', median)
		row.set('q1', q1)
		row.set('q3', q3)
		row.set('sampsize', len(ydata))

	return result
def avr_table_from_tables(avr_table_name, tables, xcolname, ycolname):
    colnames = [
        xcolname, 'min', 'q1', 'median', 'q3', 'max', 'mean', 'mean_stderr',
        'sampsize'
    ]
    xcoltype = tables[0].coltypes[tables[0].colnames.index(xcolname)]
    coltypes = [
        xcoltype, 'float', 'float', 'float', 'float', 'float', 'float',
        'float', 'int'
    ]

    result = datalib.Table(avr_table_name, colnames, coltypes)

    xvalues = common_functions.get_timesteps(tables, xcolname)

    for x in xvalues:
        ydata = []
        for table in tables:
            ydata.append(table[x][ycolname])
        ydata.sort()

        minimum, maximum, mean, mean_stderr, q1, q3, median = avr(ydata)

        row = result.createRow()
        row.set(xcolname, x)
        row.set('min', minimum)
        row.set('max', maximum)
        row.set('mean', mean)
        row.set('mean_stderr', mean_stderr)
        row.set('median', median)
        row.set('q1', q1)
        row.set('q3', q3)
        row.set('sampsize', len(ydata))

    return result
def ttest_table( ttest_table_name,
		 tcrit,
		 tables1,
		 tables2,
		 xcolname,
		 ycolname ):

    assert( len(tables1) == len(tables2) )

    colnames = [xcolname, 'Mean', 'StdDev', 'Sig', 'tval', 'pval'] 
    xcoltype = tables1[0].coltypes[ tables1[0].colnames.index(xcolname) ]
    coltypes = [xcoltype, 'float', 'float', 'int', 'float', 'float']

    xvalues = common_functions.get_timesteps( tables1 + tables2, xcolname )

    result = datalib.Table( ttest_table_name, colnames, coltypes )

    for x in xvalues:
	    data1 = [ table[x][ycolname] for table in tables1 ]
	    data2 = [ table[x][ycolname] for table in tables2 ]

	    diffMean, stdDev, tval, pval = ttest( data1, data2 )

	    row = result.createRow()

	    row[xcolname] = x
	    row["Mean"] = diffMean
	    row["StdDev"] = stdDev
	    if tval >= tcrit:
                    row["Sig"] = 1
	    else:
                    row["Sig"] = 0
	    row["tval"] = tval
	    row["pval"] = pval

    return result