On Mon, Sep 29, 2008 at 7:05 PM, Vickie Backus
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> I need some help. I'm fitting some data to a general linear model and
> everything works find in R, but when I try to write a Python script and use
> RPy to interface with R, it doesn't work.
>
> Here is my command lines in R;
>
>> library(foreign)
>> library(stats)
>> dat <- read.dbf("D:/rTesting/myDataFile.dbf", as.is=FALSE)
>> glm.test2 <- glm(CIAR ~ ROADDIST + TRAILDIST + ELEV  + COSASP + SINASP +
>> SOLRAD + BURN + TREE +  BAND3 + BAND5 + BAND7,
>> family=binomial(link="logit"), data = dat, na.action=na.exclude,
>> control=glm.control(maxit=50))
>> step2 <-step(glm.test2, steps=500)

OK, I understand what you are trying to do here.  Note that while
"dat" is a simple matrix/array like object which rpy should be able to
convert into python without loss of information, the GLM object will
by default get turned into a simplified dictionary structure.  You
will almost certainly need to turn off rpy's object conversion to
preserve the GLM object (and probably the family object) as is, so
that you can pass this to the step function successfully.

> Here's what I'm doing in my Python Script;
>
> import rpy
> from rpy import r

Why are you doing two style imports?  Anyway, try adding the following
near the start of your code:
rpy.set_default_mode(rpy.NO_CONVERSION)

This should fix your original problem (and maybe the glm.control issue too).

If after the complicated bits you want to get the answers out as python objects,
rpy.set_default_mode(rpy.BASIC_CONVERSION)

The rpy documentation goes into more depth.

> ...
> r.library("foreign")
> r.library("stats")
> dat = r.read_dbf("D:/rTesting/myDataFile.dbf")
> #FIXME:  can't get as_is =" FALSE" to work

In python, FALSE isn't defined as python uses False instead.  Try:

dat = r.read_dbf("D:/rTesting/myDataFile.dbf", as_is=False)

Peter

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to