0

I get the error as in the title, when I try to do betadisper on my dissimilarity matrix. When looking at my environment it clearly says 'dist'.

as.dist() doesn't help

#fhf is a phyloseq object

veganotu = function(physeq) {
    require("vegan")
    OTU = otu_table(physeq)
    if (taxa_are_rows(OTU)) {
        OTU = t(OTU)
    }
    return(as(OTU, "matrix"))
}

Group <- sample_names(fhf)
dissimilarity_matrix <- vegdist(veganotu(fhf), method="bray")
homogen <- betadisper(dissimilarity_matrix ~ Group)
anova(homogen)

I expect a result similar to this, but with other values:

Analysis of Variance Table

Response: Distances Df Sum Sq Mean Sq F value Pr(>F) Groups 5 0.021037 0.0042074 1.5524 0.252 Residuals 11 0.029813 0.0027103

Error message:

Error in betadisper(dissimilarity_matrix ~ Group) : distances 'd' must be a 'dist' object

1 Answers1

1

betadisper does not accept formula. You must write betadisper(dissimilarity_matrix, Group).

Jari Oksanen
  • 3,287
  • 1
  • 11
  • 15
  • The problem was the package "proxy". Unloading it made it work. The ~ works. – Arne Claeys Jun 01 '19 at 19:19
  • `~` does not work. That's sure, because the function is written so that `~` does not work. The function checks that the first argument is a `"dist"` object, and even when `d` is a `"dist"` object, `d ~ Group` is not. – Jari Oksanen Jun 01 '19 at 20:38
  • Weird that it works then with no warnings or errors. – Arne Claeys Jun 03 '19 at 07:51