Example #1
0
def main(hdf, name):
    f = open('{0}.csv'.format(name), 'w')
    csvw = csv.writer(f)
    
    # A header for the table
    head = ["tau", "p_tau",
            "r", "p_r",
            "rho", "p_rho",
            "cond",
            "boldmeta", 
            "model"]
    csvw.writerow(head)
    
    models = get_model_names(hdf)
    for model in models:
        # Get model meta data
        meta = get_model_meta(hdf, model)
        boldmeta = "_".join([str(b) for b in meta["bold"]])
            ## meta['bold'] can be a list
            ## but we need a string....
        
        # Get all the design matrices and
        # Get all the bold signals as a 1d array
        dm = np.array(read_hdf(hdf, '/' + model + '/dm'))
        bold = np.array(read_hdf(hdf, '/' + model + '/bold')).flatten()
        
        # Loop over the dm cols in the dm:
        #  axis 1 is a sim index/count, 
        #  axis 2 is the dm row
        #  axis 3 is the dm cols
        for jj in range(dm.shape[2]):
            # Get all this cols in a 1d array
            # matching what was done to
            # bold above
            x1 = dm[:, :, jj].flatten()
            x1name = meta["dm"][jj]
            
            # And calc the corr between 
            # the two 1d arrays
            tau, p_tau = kendalltau(bold, x1)
            r, p_r = pearsonr(bold, x1)
            rho, p_rho = spearmanr(bold, x1)
            
            # then write it all out.
            csvw.writerow([
                    tau, p_tau,
                    r, p_r,
                    rho, p_rho,
                    x1name,
                    boldmeta, 
                    model])
    f.close()
def main(hdf, name):
    # Create a csv file to tabulate into
    f = open('{0}.csv'.format(name), 'w')
    csvw = csv.writer(f)
    
    # Make a header for the table
    header = ["x", "count", "cond"]
    csvw.writerow(header)
    
    conds = set(["acc", "value", "rpe", "p", "rand", "box"])
    
    # Find a dmcol from models,
    # pick the first model with 
    # that dm cond. Conds across
    # models are the same.
    locations = {} 
    models = get_model_names(hdf)
    for model in models:

        # Get model meta data and compare it too conds
        meta = get_model_meta(hdf, model)
        for ii, dmname in enumerate(meta["dm"]):
            if dmname in conds:
                locations[dmname] = (model, ii)
                conds.remove(dmname)
                    ## conds loses elements!

        # If conds is empty, stop
        if not conds:
            print("All conds found. {0}".format(model))
            break
    
    # Get each dm's data and pick a col using pos;
    # pos matches cond.
    dmdata = {}
    for cond, loci in locations.items():
        print("Getting {0}".format(cond))
        
        model, pos = loci
        dm = np.array(read_hdf(hdf, '/' + model + '/dm'))
        dmdata[cond] = dm[:,:,pos].flatten()
    
    # Create a histogram then write it out.
    for cond, data in dmdata.items():
        print("Histogramming {0}".format(cond))
        
        # Instantiate a RHist instance and 
        # use it to make a histogram
        hist = RHist(name=cond, decimals=2)
        [hist.add(x) for x in data]
        
        # Tell that textfile a tale.
        [csvw.writerow([k, v, cond]) for k, v in hist.h.items()]
    
    f.close()
Example #3
0
def create_hist_list(hdf, model, stat):
    """ Create a list of Rhist (histogram) objects for <model> and 
    <stat> in the given <hdf>. 
    
    If <stat> has only one entry (as is the case for 'aic') the list will have 
    only one entry.  If however <stat> has n entries per model (like't') 
    the list will have n-1 entries. As n matches the number of columns in
    the design matrix, the rightmost will always correspond to the dummy 
    predictor and is therefore discarded. """

    hist_list = []  ## A list of RHist objects.
    meta = get_model_meta(hdf, model)  ## metadata for naming

    # A handle on the hdf data
    hdfdata = read_hdf(hdf, '/' + model + '/' + stat)

    # Loop over the nodes, adding the data
    # for each to a RHist.
    for node in hdfdata:
        # Some data will be list-like
        # so try to iterate, if that fails
        # assume the data is a single number
        try:
            for ii in range(len(node) - 1):
                # Init entries in hist_list as needed
                try:
                    hist_list[ii].add(node[ii])
                except IndexError:
                    hist_list.append(RHist(name=meta['dm'][ii], decimals=2))
                    hist_list[ii].add(node[ii])
        except TypeError:
            # Assume a number so hist_list has only one
            # entry (i.e. 0).
            #
            # Init entries in hist_list as needed
            try:
                hist_list[0].add(node)
            except IndexError:
                hist_list.append(RHist(name=stat, decimals=2))
                hist_list[0].add(node)

    return hist_list
Example #4
0
def create_hist_list(hdf, model, stat):
    """ Create a list of Rhist (histogram) objects for <model> and 
    <stat> in the given <hdf>. 
    
    If <stat> has only one entry (as is the case for 'aic') the list will have 
    only one entry.  If however <stat> has n entries per model (like't') 
    the list will have n-1 entries. As n matches the number of columns in
    the design matrix, the rightmost will always correspond to the dummy 
    predictor and is therefore discarded. """
    
    hist_list = [] ## A list of RHist objects.
    meta = get_model_meta(hdf, model) ## metadata for naming
    
    # A handle on the hdf data
    hdfdata = read_hdf(hdf, '/' + model + '/' + stat)   
    
    # Loop over the nodes, adding the data
    # for each to a RHist. 
    for node in hdfdata:
        # Some data will be list-like
        # so try to iterate, if that fails
        # assume the data is a single number
        try:
            for ii in range(len(node)-1):
                # Init entries in hist_list as needed
                try:
                    hist_list[ii].add(node[ii])
                except IndexError:
                    hist_list.append(RHist(name=meta['dm'][ii], decimals=2))
                    hist_list[ii].add(node[ii])
        except TypeError:
            # Assume a number so hist_list has only one
            # entry (i.e. 0).
            #
            # Init entries in hist_list as needed
            try:
                hist_list[0].add(node)
            except IndexError:
                hist_list.append(RHist(name=stat, decimals=2))
                hist_list[0].add(node)

    return hist_list
def main(hdf, name):
    # Create a csv file to tabulate into
    f = open('{0}.csv'.format(name), 'w')
    csvw = csv.writer(f)
    
    # A header for the table
    head = ["tau", "p_tau",
            "r", "p_r",
            "rho", "p_rho",
            "cond0",
            "cond1"] 
    
    csvw.writerow(head)
    
    conds = set(["acc", "value", "rpe", "p", "rand", "box"])
    pairs = permutations(conds, 2)
    
    # Find a dmcol from models,
    # pick the first model with 
    # that dm cond. Conds across
    # models are the same.
    locations = {} 
    models = get_model_names(hdf)
    for model in models:

        # Get model meta data and compare it too conds
        meta = get_model_meta(hdf, model)
        for ii, dmname in enumerate(meta["dm"]):
            if dmname in conds:
                locations[dmname] = (model, ii)
                conds.remove(dmname)
                    ## conds loses elements!

        # If conds is empty, stop
        if not conds:
            print("All conds found by {0}".format(model))
            break
    
    # Get the data
    dmdata = {}
    for cond, loci in locations.items():
        print("Getting {0}".format(cond))
        
        model, pos = loci
        dm = np.array(read_hdf(hdf, '/' + model + '/dm'))
            ## Get all the dm's data
        dmdata[cond] = dm[:,:,pos].flatten()
            ## pick a col using pos, as this is 
            ## the data matching name
    
    # Calculate all pair-wise correlations
    for pair in pairs:
        print("Correlate: {0}".format(pair))
        
        cond0, cond1 = pair
        x0 = dmdata[cond0]
        x1 = dmdata[cond1]
        
        tau, p_tau = kendalltau(x0, x1)
        r, p_r = pearsonr(x0, x1)
        rho, p_rho = spearmanr(x0, x1)

        # then write it all out.
        csvw.writerow([
                tau, p_tau,
                r, p_r,
                rho, p_rho,
                cond0,
                cond1])
    
    f.close()