0

I am having issues with conducting a partial Canonical Correspondence Analysis (pCCA) in R. The data associated with code is quite extensive so I am unable to include it here.

The following code produces the error below it. In the pCCA model, I am attempting to account for both environmental and spatial variables in explaining species matrix. Spatial variables are Latitude and Longitude values. Env2 variables are a host of continuous and a few binary (0,1) environmental variables.

mod2 <-cca(species ~ env2 + spatial)
Error in model.frame.default(~env2 + spatial, na.action = na.pass, xlev = NULL) : invalid type (list) for variable 'env2'

I have used unlist () for both env2 and spatial, but it does not work. Thoughts?

ecology
  • 606
  • 3
  • 9
  • 29
  • 1
    You don't need to provide your actual data, but if you want to know why your code isn't working, providing a toy example dataset that is representative of your actual data is a good way to get better answers, faster. It also makes your problem clearer for others who find your post and want to learn from it. See [mcve] for more. – andrew_reece Jun 03 '18 at 02:12

1 Answers1

2

The right-hand side of formula must have variables, but it seems that you have data frames of several variables. This will not work, but gives a similar error message as in your post (and this is documented). Further, your formula will not define partial CCA, because the formula does not contain function Condition() that defines the terms partialled out.

The formula interface may work if you have numerical matrices as terms, but it won't work with unlist() variables.

If you are using vegan 2.5-1 or newer, you can define a partial CCA without formula interface as cca(species, env2, spatial) and the data frames env2 and spatial are automatically expanded to model matrices, and spatial terms are partialled out before analysing the effects of env2 terms.

Jari Oksanen
  • 3,287
  • 1
  • 11
  • 15