def __init__(self, vox_stat, vox_map, vox_stat_ranking, max_stat_dist, min_stat_dist, snpm_ptail_clusters, snpm_ptail_nulls, snpm_ntail_clusters, snpm_ntail_nulls): """ Parameters ---------- All TimeFreqSnPMResults arguments, plus snpm_ptail_clusters: list List of ScoredStatClusters, for each (t,f) point snpm_ptail_nulls: ndarray Array of positive-tail null distributions for each (t,f) point snpm_ntail_clusters: list List of ScoredStatClusters, for each (t,f) point snpm_ntail_nulls: ndarray Array of negative-tail null distributions for each (t,f) point """ super(TimeFreqSnPMClusters, self).__init__( vox_stat, vox_map, vox_stat_ranking, max_stat_dist, min_stat_dist ) t, f = self.t.shape[1:] assert t*f==len(snpm_ptail_clusters) or \ (t==len(snpm_ptail_clusters) and \ f==len(snpm_ptail_clusters[0])), \ 'Not enough pos-tail clusters for every time-freq point' assert t*f==len(snpm_ntail_clusters) or \ (t==len(snpm_ntail_clusters) and \ f==len(snpm_ntail_clusters[0])), \ 'Not enough neg-tail clusters for every time-freq point' self.ptail_clusters = tablify_list(snpm_ptail_clusters, t, f) self.ptail_nulls = snpm_ptail_nulls self.ntail_clusters = tablify_list(snpm_ntail_clusters, t, f) self.ntail_nulls = snpm_ntail_nulls
def pscore_clusters(self, tail, corrected_dims=(), pooled_dims=()): """ Returns ------- scores A list of p values for each list of clusters (at each (t,f) point) scored against the null """ if len(corrected_dims) or len(pooled_dims): raise NotImplementedError( 'Not yet combining time-freq dimensions for correction/pooling' ) pvalues = [] if tail.lower()=='pos': clusters = self.ptail_clusters nulls = np.sort(self.ptail_nulls, axis=0) else: clusters = self.ntail_clusters nulls = np.sort(self.ntail_nulls, axis=0) n_perm = float(nulls.shape[0]) nt, nf = nulls.shape[1:] for t in xrange(nt): for f in xrange(nf): if not clusters[t][f]: pvalues.append([]) continue ntf = nulls[:,t,f] wscores = [ci.wscore for ci in clusters[t][f]] pvalues.append( 1.0 - ntf.searchsorted(wscores, side='left')/n_perm ) return tablify_list(pvalues, nt, nf)