mutliple regression using rpy

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • libiger
    New Member
    • Mar 2007
    • 1

    #1

    mutliple regression using rpy

    Hi,

    I am trying to perform multiple regression in python using rpy.
    I can get it to work for two arrays, however when I try to regress a matrix and an array (as in the following code) I get an error message (below.)
    Can someone please help?

    Thanks,
    Ondrej


    Code:
    from rpy import *
    
    phenotypes = array([4,5,4,3])
    X = array([1,2,3,4],[3,2,4,5],[6,5,4,3])
    d = r.data_frame(x=X, y=phenotypes)
    model = r("y~x")
    set_default_mode(NO_CONVERSION)
    linear_model = r.lm(model, data = d)
    set_default_mode(BASIC_CONVERSION)
    print r.summary(linear_model)
    
    
    Traceback (most recent call last):
      File "genback.py", line 242, in ?
        linear_model = r.lm(model, data = d)
    rpy.RException: Error in eval(expr, envir, enclos) : object "x" not found
    Last edited by bartonc; Mar 27 '07, 09:33 PM. Reason: added [code][/code] tags
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by libiger
    Hi,

    I am trying to perform multiple regression in python using rpy.
    I can get it to work for two arrays, however when I try to regress a matrix and an array (as in the following code) I get an error message (below.)
    Can someone please help?

    Thanks,
    Ondrej


    Code:
    from rpy import *
    
    phenotypes = array([4,5,4,3])
    X = array([1,2,3,4],[3,2,4,5],[6,5,4,3])
    d = r.data_frame(x=X, y=phenotypes)
    model = r("y~x")
    set_default_mode(NO_CONVERSION)
    linear_model = r.lm(model, data = d)
    set_default_mode(BASIC_CONVERSION)
    print r.summary(linear_model)
    
    
    Traceback (most recent call last):
      File "genback.py", line 242, in ?
        linear_model = r.lm(model, data = d)
    rpy.RException: Error in eval(expr, envir, enclos) : object "x" not found
    I don't use that package, but one thing stands out:
    Code:
    d = r.data_frame(x=X, y=phenotypes)
    Ok; get d from the object r's data_frame() method.
    Code:
    model = r("y~x")
    ? What does r do when called instead of using an access method?
    Code:
    linear_model = r.lm(model, data = d)
    Ok; get linear_model from the object r's lm() method.

    Comment

    Working...