-1

I have a mixed data (categorical and continuous) and I want to compute the modified Gower coefficient using the vegandist command

library(vegan)
vegdist(mydata, "altGower")

However, the following error appears:

Error in rowSums(x, na.rm = TRUE) : 'x' must be numeric

I guess it is because the column for the categorical variables are factor variables and non-numeric. If this is the problem is there any other package I can compute these distance using the modified Gower?

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
user2246905
  • 1,029
  • 1
  • 12
  • 31
  • I'm a bit confused as to what you want; are you asking for this adjustment to a new multiplicative scale (what I know as modified gower) *only* for the continuous variables? If so, you can this trivially using the `distance()` function in my analogue package **if** you apply the transformation as described in Anderson et al Ecology Letters 2006 to only the continuous variables. It's going to be difficult to interpret what this coefficient means though: putting quantitative variables on some new multiplicative scale whilst retaining matching for categorical or binary vars. – Gavin Simpson Aug 24 '16 at 19:05

1 Answers1

1

You cannot use vegan::vegdist() with mixed data (this is documented). You should use either cluster::daisy() or FD::gowdis() which are able to handle mixed data. Functions differ in coding categorical data: there are several options in gowdis() (FD package). The cluster package is officially recommended and is probably already installed in your R.

Jari Oksanen
  • 3,287
  • 1
  • 11
  • 15
  • gowdis is useful, however, I cannot use the Modified Gower distance with this code. Do you know if there is another one in which I can use also altGower as in vegdist? – user2246905 Jul 22 '16 at 14:43
  • @user2246905 You can use the modified Gower coefficient with `gowdis()`; notice that the log-transformation of Anderson et al 2006 is something entirely separate from the calculation of the the dissimilarity. In vegan we didn;t include the log transforming code in `vegdist()` but in the `decostand()` function. Hence you could apply, if you really want to, the log-transformation to the quantitative variables using `decostand()` and then pass all the data to `gowdis()`. – Gavin Simpson Aug 24 '16 at 19:21