rpy2

extract coefficients from R lme model in rpy2

谁说我不能喝 提交于 2019-12-12 01:45:04
问题 I need to extract the results of an R lme model called in python using rpy2. Extracting the coefficients with rx2 as follows : model = nlme.lme(fixed=fixed, data=dfr, random=random, method="REML") print model.rx2("coefficients") Yields all the coefficients as follows: $fixed (Intercept) log.var1 12.571692 -2.929928 $random $random$item (Intercept) log.var1 12545646546 -5.189606e-16 8.276929e-16 $random$category (Intercept) log.var1 0001544848484/DLMX -3.1909917 2.3938670 I want to extract the

rpy2 cannot find installed external R packages

人走茶凉 提交于 2019-12-12 00:26:19
问题 I've done this before (~1 year ago now), but want to use R again via rpy2. I've confirmed that I can load default packages when I do this: from rpy2 import robjects plot = robjects.r.get('plot') Now, when I try to load an external package like so, from rpy2.robjects.packages import importr betareg = importr('betareg') I get the following error: Traceback (most recent call last): File "<ipython-input-1-b1ed20534ab9>", line 1, in <module> runfile('C:/Users/Patrick/OneDrive/FIDS/betareg.py',

how can theme_classic be accessed in rpy2 from ggplot2?

强颜欢笑 提交于 2019-12-11 20:01:18
问题 How can theme_classic be accessed from rpy2 in Python? I.e. this: http://www.inside-r.org/packages/cran/ggplot2/docs/theme_classic Is there a way to use it from rpy2? 回答1: Yes there is. If using the manual mapping in rpy2.robjects.lib.ggplot2 , is it currently missing from there, but a way to patch this should be: import rpy2.robjects.lib.ggplot2 as ggplot2 class ThemeClassic(ggplot2.Theme): _constructor = ggplot2.ggplot2.theme_classic @classmethod def new(cls): res = cls(cls._constructor())

Runing R code on `python` with SyntaxError: keyword can't be an expression error Message

北战南征 提交于 2019-12-11 11:58:58
问题 I'm looking to run some R code on python I already installed the R package robustbase on ubunto using apt-get install r-cran-robustbase and rpy packege as well. from the python console I can successfully run from rpy import * and r.library("robustbase") but when I run result = robjects.FloatVector([11232.1, 234.2, 3445532344.3, 34302.3, 203.9, 232223.3, 3434.55]) print(result.r_repr()) r(adjboxStats(c(11232.1, 234.2, 3445532344.3, 34302.3, 203.9, 232223.3, 3434.55), coef = 2.5, a = -4, b = 3,

correlation for two lists of data

谁说胖子不能爱 提交于 2019-12-11 11:42:48
问题 These two lists contain data something like this: a = [1 2 1 3 1 2 1 1 1 2 1 1 2 1 4 1 ] b = [ 3480. 7080. 10440. 13200. 16800. 20400. 23880. 27480. 30840. 38040. 41520. 44880. 48480. 52080. 55680. 59280.] How to find correlation using python by importing rpy2 , I mean cor function. And the o/p has to lie between -1 and +1. 回答1: from rpy2.robjects.vectors import FloatVector from rpy2.robjects.packages import importr stats = importr('stats') a=[1, 2, 1, 3, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 4, 1 ]

Install rpy2 with custom R installation

孤者浪人 提交于 2019-12-11 10:55:05
问题 I have a custom installation of R in ~/R-3.2.2/bin/ When I run sudo pip install rpy2 I get Warning: Tried to guess R's HOME but no command (R) in the PATH. Traceback (most recent call last): File "<string>", line 17, in <module> File "/tmp/pip-build-ITKmkR/rpy2/setup.py", line 330, in <module> ri_ext = getRinterface_ext() File "/tmp/pip-build-ITKmkR/rpy2/setup.py", line 231, in getRinterface_ext r_home = _get_r_home() File "/tmp/pip-build-ITKmkR/rpy2/setup.py", line 63, in _get_r_home r_home

python rpy2 module: refresh global R environment

与世无争的帅哥 提交于 2019-12-11 10:29:40
问题 The documentation for rpy2 states that the robjects.r object gives access to an R global environment. Is there a way to "refresh" this global environment to its initial state? I would like to be able to restore the global environment to the state it was in when the rpy2.robjects module was imported but not yet used. In this manner, I don't have to worry about memory leaks on long running jobs or other unexpected side effects. Yes, refreshing the environment could introduce a different

rpy2 access R named list items by name, low-level interface

泄露秘密 提交于 2019-12-11 08:08:44
问题 How do I access elements of a named list by name? I have 3 functions, all of which return a ListSexpVector of class htest . One of them has 5 elements, ['method', 'parameter', 'statistic', 'p.value', 'data.name'] , others have a different number, and order. I am interested in extracting the p.value , statistic and parameter from this list. In R I can use $ , like so: p.value <- fit$p.value statistic <- fit$statistic param <- fit$parameter The best equivalent I found in rpy2 goes like: p_val =

Running rpy2 in parallel using multiprocessing raises weird exception that cannot be caught

主宰稳场 提交于 2019-12-11 06:49:50
问题 So this is a problem that I have not been able to solve, and neither do I know of a good way to make a MCVE out of. Essentially, it has been briefly discussed here, but as the comments show, there was some disagreement, and the final verdict is still out. Hence I am posting a similar question again, hoping to get a better answer. Background I have sensor data from a couple of thousand sensors, that I get every minute. My interest lies in forecasting the data. For this I am using the ARIMA

Rpy2 pandas2ri.ri2py() is converting NA values to integers

给你一囗甜甜゛ 提交于 2019-12-11 05:43:07
问题 I'm using Rpy2 version 2.8.4 in conjunction with R 3.3.0 and python 2.7.10 to create an R dataframe import rpy2.robjects as ro from rpy2.robjects import r from rpy2.robjects import pandas2ri df = ro.DataFrame({'Col1': ro.vectors.IntVector([1, 2, 3, 4, 5]), 'Col2': ro.vectors.StrVector(['a', 'b', 'c', 'd', 'e']), 'Col3': ro.vectors.FactorVector([1, 2, 3, ro.NA_Integer, ro.NA_Integer])}) print df | Col2 | Col3 | Col1 | ---------------------- 1 | a | 1 | 1 | 2 | b | 2 | 2 | 3 | c | 3 | 3 | 4 | d