I am new in RPy, so excuse me, if my question is trivial. I'm trying to write the top solution from this topic: Screening (multi)collinearity in a regression model in Python, but I get following error:
rpy.RPy_RException: Error in x$terms : $ operator is invalid for atomic vectors
Code I wrote:
from rpy import *
r.set_seed(42)
a=r.rnorm(100)
b=r.rnorm(100)
m=r.model_matrix('~a+b')
What am I doing wrong?
EDIT: using reply written by agstudy (thank You for help!) I prepared solution working for rpy2
from rpy2 import robjects
rset_seed = robjects.r('set.seed')
fmla = robjects.Formula('~a+b')
model_matrix = robjects.r('model.matrix')
rnorm = robjects.r('rnorm')
rset_seed(42)
env = fmla.environment
env['a']=rnorm(100)
env['b']=rnorm(100)
m=model_matrix(fmla)