本文整理汇总了Python中rpy2.robjects.packages.importr方法的典型用法代码示例。如果您正苦于以下问题:Python packages.importr方法的具体用法?Python packages.importr怎么用?Python packages.importr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rpy2.robjects.packages
的用法示例。
在下文中一共展示了packages.importr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_matchit
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def install_matchit(self):
from rpy2.robjects.packages import importr
import rpy2.robjects.packages as rpackages
from rpy2.robjects.vectors import StrVector
import rpy2.robjects as robjects
package_names = ["MatchIt"]
names_to_install = [x for x in package_names if not rpackages.isinstalled(x)]
if len(names_to_install) > 0:
robjects.r.options(download_file_method='curl')
utils = rpackages.importr('utils')
utils.chooseCRANmirror(ind=0)
utils.chooseCRANmirror(ind=0)
utils.install_packages(StrVector(names_to_install))
return importr("MatchIt")
示例2: install_grf
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def install_grf(self):
from rpy2.robjects.packages import importr
import rpy2.robjects.packages as rpackages
from rpy2.robjects.vectors import StrVector
import rpy2.robjects as robjects
robjects.r.options(download_file_method='curl')
package_names = ["grf"]
utils = rpackages.importr('utils')
utils.chooseCRANmirror(ind=0)
utils.chooseCRANmirror(ind=0)
names_to_install = [x for x in package_names if not rpackages.isinstalled(x)]
if len(names_to_install) > 0:
utils.install_packages(StrVector(names_to_install))
return importr("grf")
示例3: install_bart
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def install_bart(self):
import rpy2.robjects.packages as rpackages
from rpy2.robjects.packages import importr
from rpy2.robjects.vectors import StrVector
import rpy2.robjects as robjects
robjects.r.options(download_file_method='curl')
# install.packages("rJava")
rj = importr("rJava", robject_translations={'.env': 'rj_env'})
rj._jinit(parameters="-Xmx16g", force_init=True)
print("rJava heap size is", np.array(rj._jcall(rj._jnew("java/lang/Runtime"), "J", "maxMemory"))[0] / 1e9,
"GB.", file=sys.stderr)
package_names = ["bartMachine"]
utils = rpackages.importr('utils')
utils.chooseCRANmirror(ind=0)
utils.chooseCRANmirror(ind=0)
names_to_install = [x for x in package_names if not rpackages.isinstalled(x)]
if len(names_to_install) > 0:
utils.install_packages(StrVector(names_to_install))
return importr("bartMachine")
示例4: pi0est
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def pi0est(p, lambda_qvalue=None):
"""Wrapper for qvalue::pi0est"""
qvalue = importr("qvalue")
rp = rpy2.robjects.vectors.FloatVector(p)
# with suppress_stdout():
if lambda_qvalue is None:
pi0res = qvalue.pi0est(rp)
else:
if not isinstance(lambda_qvalue, Iterable):
lambda_qvalue = [lambda_qvalue]
rlambda = rpy2.robjects.vectors.FloatVector(lambda_qvalue)
pi0res = qvalue.pi0est(rp, rlambda)
pi0 = np.array(pi0res.rx2('pi0'))[0]
pi0_lambda = np.array(pi0res.rx2('pi0.lambda'))
lambda_vec = np.array(pi0res.rx2('lambda'))
pi0_smooth = np.array(pi0res.rx2('pi0.smooth'))
return pi0, pi0_lambda, lambda_vec, pi0_smooth
示例5: importable
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def importable(self) -> bool:
try:
import rpy2.robjects.packages as rpackages
rpackages.importr(self.package_name, robject_translations={".env": "env"})
return True
except Exception:
return False
示例6: format_code
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def format_code(self, code: str, notebook: bool, **options) -> str:
import rpy2.robjects.packages as rpackages
format_r = rpackages.importr(
self.package_name, robject_translations={".env": "env"}
)
formatted_code = format_r.tidy_source(text=code, output=False, **options)
return "\n".join(formatted_code[0])
示例7: installRSynth
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def installRSynth():
from rpy2.robjects.packages import importr
utils = importr('utils')
utils.install_packages('Synth')
示例8: installRCausalImpact
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def installRCausalImpact():
from rpy2.robjects.packages import importr
utils = importr('utils')
utils.install_packages('CausalImpact')
示例9: base
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def base():
return importr('base')
示例10: wgcna
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def wgcna():
return importr('WGCNA')
示例11: stats
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def stats():
return importr('stats')
示例12: graphics
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def graphics():
return importr('graphics')
示例13: grdevices
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def grdevices():
return importr('grDevices')
示例14: qvalue
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def qvalue(p, lambda_qvalue=None):
"""Wrapper for qvalue::qvalue"""
qvalue = importr("qvalue")
rp = rpy2.robjects.vectors.FloatVector(p)
if lambda_qvalue is None:
q = qvalue.qvalue(rp)
else:
if not isinstance(lambda_qvalue, Iterable):
lambda_qvalue = [lambda_qvalue]
rlambda = rpy2.robjects.vectors.FloatVector(lambda_qvalue)
q = qvalue.qvalue(rp, **{'lambda':rlambda})
qval = np.array(q.rx2('qvalues'))
pi0 = np.array(q.rx2('pi0'))[0]
return qval, pi0
示例15: fit_and_evaluate
# 需要导入模块: from rpy2.robjects import packages [as 别名]
# 或者: from rpy2.robjects.packages import importr [as 别名]
def fit_and_evaluate(x,z,t,y,df):
'''
Fit and evaluate non-parametric regression using Darolles, Fan, Florens and Renault (2011)
Implemented in the `np` package in R.
See [the np package documation](https://cran.r-project.org/web/packages/np/np.pdf) for details.
'''
npr=importr('np')
y_R = robjects.FloatVector(list(y.flatten()))
(x_eval, t_eval), y_true = test_points(df, 10000)
mod = npr.npregiv(y_R, t, z, x=x, zeval=t_eval, xeval=x_eval,
method="Tikhonov", p=0, optim_method ="BFGS")
return ((y_true - to_array(mod.rx2('phi.eval')))**2).mean()