[R-sig-eco] RDA with only dummy variable in environmental matrix

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Jun 22 20:57:37 CEST 2010


On Tue, 2010-06-22 at 07:15 -0700, amelie_can wrote:
> Hello Zoltan, 
> 
> thank you for your reply. When I tried what you suggested, the rda
> calculation did not proceed and I received this error message: "Error in
> colMeans(x, na.rm = TRUE) : 'x' must be numeric". 
> 
> This is the same example I used yesterday, but with the changes you
> proposed: 
> mat.sp = matrix(c(40, 20, 37, 49, 52, 34, 35, 87, 90, 45, 49, 52, 34, 35,
> 87,5,39,99,8,45),nrow = 4, ncol=5, dimnames = list(c("sites1", "sites2",
> "sites3","sites4"),c("sp1", "sp2", "sp3", "sp4", "sp5")))
> mat.env = matrix(c("NAT","NAT","NR","REST"),4,1, dimnames = list(c("sites1",
> "sites2", "sites3","sites4"),c("TYPE")))
> as.factor(mat.env[,1])
^^^^^^^^^^^^^^^^^^^^^^^^
That doesn't do anything as you don't assign it.

To use the automagical expansion of factors to appropriate model matrix
variables, you need to use the formula interface, as per most R
modelling function I know.

> env <- data.frame(Type = factor(c("NAT","NAT","NR","REST")))
> rda(mat.sp ~ Type, data = env)

By the way, you can't store your factor in a matrix - only numerics or
characters are allowed and a matrix must contain elements of all the
same type. Store things in data frames and convert them to matrices
(using data.matrix() ) if you need a matrix; generally you won't and the
data.frame will suffice.

HTH

G


> summary(mat.env)
> 
> rda = rda (mat.sp,mat.env)
> summary(rda)
> plot(rda, scaling=1, type="points")
> 
> Do you know what is the problem? 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-sig-ecology mailing list