[R-sig-eco] Model specification with RPy/vegan integration
Gregory, Matthew
matt.gregory at oregonstate.edu
Mon Jun 30 19:27:23 CEST 2008
Hi all,
(This might be a bit tangetial and technical question for this
listserve. Please advise if there is a more appropriate venue.)
I'm trying to call vegan 'cca' from Python using Rpy. I read my species
and environmental data into R data frames without an issue and can even
run the 'full' cca model without a problem, e.g.
from rpy import *
set_default_mode(NO_CONVERSION)
# Import the vegan library
r.library('vegan')
# Open up the data files and read into data frames
spp_file = r.read_csv('spp.csv', header=r.TRUE)
env_file = r.read_csv('env.csv', header=r.TRUE)
spp = r.data_frame(spp_file, row_names='FCID')
env = r.data_frame(env_file, row_names='FCID')
# Squareroot transform the species matrix
spp = r.sqrt(spp)
# Create the vegan CCA
out_cca = r.cca(spp, env)
However, when I try to specify the model to only include a subset of the
environmental variables, e.g.
# Create the vegan CCA
model = r("spp ~ ANNPRE + ANNTMP + DEM + SLPPCT")
out_cca = r.cca(model, env)
I get the error "Error in eval(expr, envir, enclos) : object "spp" not
found". Note that running the subsetted model in the R console works
correctly as expected. Furthermore, I can run example code from the RPy
pages which uses the '~' notation to specify models and it works
correctly as well. I'm sure I have a silly little syntax error, but I'm
just not seeing it.
Thanks for help,
matt
More information about the R-sig-ecology
mailing list