def confidence_interval(self): """The size of the 1-alpha confidence interval""" coh_var = np.zeros((self.input.data.shape[0], self.input.data.shape[0], self._L), 'd') for i in range(self.input.data.shape[0]): for j in range(i): if i != j: coh_var[i, j] = tsu.jackknifed_coh_variance( self.spectra[i], self.spectra[j], self.eigs, adaptive=self._adaptive ) idx = triu_indices(self.input.data.shape[0], 1) coh_var[idx[0], idx[1], ...] = coh_var[idx[1], idx[0], ...].conj() coh_mat_xform = tsu.normalize_coherence(self.coherence, 2 * self.df - 2) lb = coh_mat_xform + dist.t.ppf(self.alpha / 2, self.df - 1) * np.sqrt(coh_var) ub = coh_mat_xform + dist.t.ppf(1 - self.alpha / 2, self.df - 1) * np.sqrt(coh_var) # convert this measure with the normalizing function tsu.normal_coherence_to_unit(lb, 2 * self.df - 2, lb) tsu.normal_coherence_to_unit(ub, 2 * self.df - 2, ub) return ub - lb
""" if i != j: coh_var[i, j] = utils.jackknifed_coh_variance( tspectra[i], tspectra[j], eigs, adaptive=True, ) """ This measure is normalized, based on the number of tapers: """ coh_mat_xform = utils.normalize_coherence(coh_mat, 2 * K - 2) """ We calculate 95% confidence intervals based on the jack-knife variance calculation: """ t025_limit = coh_mat_xform + dist.t.ppf(.025, K - 1) * np.sqrt(coh_var) t975_limit = coh_mat_xform + dist.t.ppf(.975, K - 1) * np.sqrt(coh_var) utils.normal_coherence_to_unit(t025_limit, 2 * K - 2, t025_limit) utils.normal_coherence_to_unit(t975_limit, 2 * K - 2, t975_limit)
""" if i != j: coh_var[i, j] = utils.jackknifed_coh_variance( tspectra[i], tspectra[j], eigs, adaptive=True, ) """ This measure is normalized, based on the number of tapers: """ coh_mat_xform = utils.normalize_coherence(coh_mat, 2 * K - 2) """ We calculate 95% confidence intervals based on the jack-knife variance calculation: """ t025_limit = coh_mat_xform + dist.t.ppf(.025, K - 1) * np.sqrt(coh_var) t975_limit = coh_mat_xform + dist.t.ppf(.975, K - 1) * np.sqrt(coh_var) utils.normal_coherence_to_unit(t025_limit, 2 * K - 2, t025_limit) utils.normal_coherence_to_unit(t975_limit, 2 * K - 2, t975_limit) if L < n_samples: freqs = np.linspace(0, 1 / (2 * TR), L)