示例#1
0
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
示例#2
0
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)
示例#3
0
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)
示例#4
0
文件: Stats.py 项目: wangdi2014/cgat
    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()
示例#5
0
文件: Stats.py 项目: CGATOxford/cgat
    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()
示例#6
0
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)
示例#7
0
def setup():
    r("install.packages('batchmeans', repos='http://cran.us.r-project.org')")
    r.require('batchmeans')
示例#8
0
def setup():
    r("install.packages('mcmc', repos='http://cran.us.r-project.org')")
    r.require('mcmc')