def integrated_autocorr4r(x): r.require('coda') # r.assign('x', x) # print(r('spectrum0(x, max.freq=0.1)')) # print(r('spectrum0(x, max.freq=0.5)')) # print(r('spectrum0(x, max.freq=0.5)')) value = r['spectrum0'](x)[0][0] / np.var(x, ddof=1) return value
def test_1(): x = generate_AR1(0.95, 1, 50**2+25, random_state=0) val = integrated_autocorr5(x, size='sqrt')[0] r.require('batchmeans') r.assign('x', x) ref = r('(bm(x)$se)^2 * length(x) / var(x)')[0] np.testing.assert_almost_equal(val, ref)
def test_1(): y = generate_AR1(0.95, 1, 10000) tau = integrated_autocorr3(y) r.require('mcmc') r.assign('x', y) r('popvar = (var(x)*(nrow(x)-1)/nrow(x))') r('init = initseq(x)') tau_ref = r('initseq(x)$var.pos / popvar')[0] print(tau, tau_ref) np.testing.assert_array_almost_equal(tau, tau_ref)
def plot(self, hardcopy=None): if hardcopy: R.png(hardcopy, width=1024, height=768, type="cairo") R.require('qvalue') # build a qobj R.assign("pval", self.mPValues) R.assign("pi0", self.mPi0) R.assign("qval", self.mQValues) R.assign("lambda", self.mLambda) R("""qobj <-list( pi0=pi0, qvalues=qval, pvalues=pval, lambda=lambda)""") R(""" class(qobj) <- "qvalue" """) R("""qplot(qobj)""") if hardcopy: R.dev_off()
def install_package(package, upgrade=False, force=False): if not upgrade: exists = r.suppressPackageStartupMessages(r.require(package))[0] if exists: print("SKIPPING ", package) return utils = rpackages.importr('utils') utils.chooseCRANmirror(ind=1) print("INSTALLING ", package, "; force=", force) utils.install_packages(package, force=force)
def setup(): r("install.packages('batchmeans', repos='http://cran.us.r-project.org')") r.require('batchmeans')
def setup(): r("install.packages('mcmc', repos='http://cran.us.r-project.org')") r.require('mcmc')