0

I'm not really sure what is happening considering it works on my computer at work, but doesn't transfer over when I'm on my laptop at home :/. For background, I am working with microbial community data using unifrac distances and trying to see how my different sample types cluster together.

Anywho, first I create a square distance matrix using my unifrac data file and my meta data.

generate.square.dist.matrix(unifrac,metadata,1)
unifrac.matrix.all = dist.matrix1
unifrac.dist.all = square.dist.matrix

Then run my NMDS

nmds.all = metaMDS(unifrac.dist.all, k = 4, trymax = 500, distance = "bray")

but when I attempt to extract my scores...

nmds.all.scores = as.data.frame(scores(nmds.all))

I receive the following error: "Error in x$species[, choices, drop = FALSE] : incorrect number of dimensions".

2
  • You need to provide reproducible data and identify all relevant packages that you have loaded with library() commands. I cannot find any source for the function generate.square.dist.matrix() and your other commands seem to involve assignment using undefined objects, dist.matrix1 and square.dist.matrix.
    – dcarlson
    Commented Jun 3, 2022 at 4:03
  • I apologize. I am using vegan and ggplot2, and generate.square.dist.matrix() is a custom function. The answer below nipped it in the bud, thank you all! Commented Jun 3, 2022 at 21:40

1 Answer 1

0

There is no reproducible example, but I can still reproduce this. There is a bug in scores function, and it fails when the metaMDS result object has no species scores. It will not have species scores if you supply dissimilarity matrix as input, because dissimilarities have no information of species. I'll fix this in vegan. Meanwhile you can circumvent the problem by asking only site scores so that the function will not try to extract the non-existent species scores:

scores(nmds.all, display="site")
2
  • The bug is fixed now in github. The bug was introduced in release 2.6-2. Commented Jun 3, 2022 at 8:21
  • Thank you for the help. Rather new to the R world and I had a feeling it was something as simple as this. Commented Jun 3, 2022 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.