def main(posargs): # Check then handle the positional arguements # brough in from the command line if len(posargs) < 3: raise ValueError("At least three arguments are required.\n") name = posargs.pop() stat = posargs[0] tocompare = posargs[1:] # Create a csv file to tabulate into f = open('{0}_{1}.csv'.format(name, stat), 'w') csvw = csv.writer(f) csvw.writerow(["mean", "sd", "D", "dataset", "model", "boldmeta", "dmmeta", "cond"]) models = get_model_names(tocompare[0]) ## Assume models are identical for ## each hdf to compare for model in models: for ii, comp in enumerate(tocompare): meta = get_model_meta(comp, model) boldmeta = "_".join([str(b) for b in meta["bold"]]) dmmeta = "_".join([str(d) for d in meta["dm"]]) # Generate the data to add to the table. hist_list = create_hist_list(comp, model, stat) means = [hist.mean() for hist in hist_list] stdevs = [hist.stdev() for hist in hist_list] names = [hist.name for hist in hist_list] # Calculate effect sizes ns = [hist.n() for hist in hist_list] k = len(hist_list) + 1 ## Number of predcitors ## +1 for the dummy cohen_ds = [(2.0 * mean) / np.sqrt(n - k - 1.0) for mean, n in zip(means, ns)] ## d = 2*t / sqrt(DF) ## DF = n - k - 1 ## n = sample number ## k = predictor number # And add it. databasename = os.path.splitext(os.path.basename(comp))[0] for mean, sd, d, name in zip(means, stdevs, cohen_ds, names): row = [mean, sd, d, databasename, model, boldmeta, dmmeta, name] csvw.writerow(row) f.close()
def main(posargs): # Check then handle the positional arguements # brough in from the command line if len(posargs) != 4: raise ValueError("Four arguments are required.\n") hdf = posargs[0] stat = posargs[1] criterion = float(posargs[2]) name = posargs[3] # Create csv writer named name # And give it a header f = open("{0}_{1}{2}.csv".format(name, stat, criterion), "w") csvw = csv.writer(f) csvw.writerow(["area", "model", "boldmeta", "dmmeta", "cond"]) models = get_model_names(hdf) for model in models: hist_list = create_hist_list(hdf, model, stat) # Loop over the hist_list adding # the results from each hist.above(criterion) # to a bar plot. areas = [hist.above(criterion) for hist in hist_list] names = [hist.name for hist in hist_list] # Pretty things up then save # this barplot to the pdf # and move onto the next model meta = get_model_meta(hdf, model) boldmeta = "_".join([str(b) for b in meta["bold"]]) dmmeta = "_".join([str(d) for d in meta["dm"]]) for area, name in zip(areas, names): row = [area, model, boldmeta, dmmeta, name] csvw.writerow(row) f.close()