def altPDF(peaks,mu,sigma=None,exc=None,method="RFT"): """ altPDF: Returns probability density using a truncated normal distribution that we define as the distribution of local maxima in a GRF under the alternative hypothesis of activation parameters ---------- peaks: float or list of floats list of peak heigths mu: sigma: returns ------- fa: float or list probability density of the peaks heights under Ha !!! todo : change lists to numpy arrays """ peaks = (peaks,) if not isinstance(peaks, (tuple, list)) else peaks if method == "RFT": # assert type(sigma) is in [float, int] # assert sigma is not None normal = sst.norm(mu,sigma) num = 1/sigma * normal.pdf(peaks) den = 1. - normal.cdf(exc) fa = num/den elif method == "CS": fa = [peakdistribution.peakdens3D(y-mu,1) for y in peaks] return fa
def nulPDF(peaks,exc=None,method="RFT"): #Returns probability density using the exponential function that defines the distribution of local maxima in a GRF under the null hypothesis of no activation as introduced in Cheng & Schwartzman, 2005 peaks = (peaks,) if not isinstance(peaks, (tuple, list)) else peaks if method == "RFT": f0 = [exc*np.exp(-exc*(x-exc)) for x in peaks] elif method == "CS": f0 = [peakdistribution.peakdens3D(x,1) for x in peaks] return f0
xn = np.arange(-10,10,0.01) twocol = Paired_12.mpl_colors plt.figure(figsize=(7,5)) plt.hist(ps,lw=0,facecolor=twocol[0],normed=True,bins=np.arange(-2,10,0.3),label="observed distribution") plt.xlim([-2,10]) plt.ylim([0,0.5]) plt.plot(xn,stats.norm.pdf(xn),color=twocol[1],lw=3,label="null distribution") plt.show() peaks = cluster.cluster(spm) peaks['pval'] = peakdistribution.peakp(peaks.peak.tolist()) bum = BUM.bumOptim(peaks["pval"].tolist(),starts=10) modelfit = neuropower.TFpeakfit(peaks['peak'].tolist(),bum['pi1']) xn = np.arange(-10,10,0.01) twocol = Paired_12.mpl_colors plt.figure(figsize=(7,5)) plt.hist(peaks['peak'].tolist(),lw=0,facecolor=twocol[0],normed=True,bins=np.arange(-2,10,0.3),label="observed distribution") plt.xlim([-2,10]) plt.ylim([0,0.5]) plt.plot(xn,[(1-bum["pi1"])*peakdistribution.peakdens3D(p,1) for p in xn],color=twocol[3],lw=3,label="null distribution") plt.plot(xn,[bum["pi1"]*peakdistribution.peakdens3D(p-modelfit['delta'],1) for p in xn],color=twocol[5],lw=3,label="alternative distribution") plt.plot(xn,neuropower.mixprobdens(modelfit["delta"],bum["pi1"],xn),color=twocol[1],lw=3,label="fitted distribution") plt.title("histogram") plt.xlabel("peak height") plt.ylabel("density") plt.legend(loc="upper right",frameon=False) plt.show()