Closed kfontanez closed 10 years ago
I don't recommend trying NMDS, or any sample-ordination, with only 3 samples. You should probably just inspect the distance values directly. I can't verify that it is the only problem, since I don't have your data, but I am not surprised that NMDS complains.
Oh, I see. The ordination is being done implicitly within the plot_heatmap
function by default. This is clearly explained in its documentation. If you just want to display the heatmap, but don't want to use any clustering technique to order the axes, you can specify the axis ordering explicitly with options to the plot_heatmap
function, and no ordination will be attempted internally.
I could partially reproduce your issue on example data, but only get warnings. I think there is an even more severe issue with your data in this case. Some all-zero entries, or maybe one of the samples is exactly the same as another? It is impossible for me to troubleshoot without a reproducible example of your issue, which always means providing/specifying a dataset. The additional errors you've shown do not result from any of the calls to plot_heatmap
that I have tried.
Here is an example at least illustrating the problem of using NMDS-ordering with only two samples...
Partially reproduce the issue with just ordination, and then with plot_heatmap
, using an arbitrary subset of the GlobalPatterns
dataset.
library("phyloseq")
data("GlobalPatterns")
# Keep only 3 large samples that have about the same library size, for
# convenience
keep3samples = c("LMEpi24M", "M11Fcsw", "M31Tong")
gp3 = prune_samples(keep3samples, GlobalPatterns)
# Keep the most abundant 40 OTUs in this subset.
gp3 = prune_taxa(names(sort(taxa_sums(gp3), TRUE)[1:40]), gp3)
gp3
## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 40 taxa and 3 samples ]
## sample_data() Sample Data: [ 3 samples by 7 sample variables ]
## tax_table() Taxonomy Table: [ 40 taxa by 7 taxonomic ranks ]
## phy_tree() Phylogenetic Tree: [ 40 tips and 39 internal nodes ]
ordinate(gp3, "NMDS", "bray")
## Square root transformation
## Wisconsin double standardization
## Run 0 stress 0
## Run 1 stress 0
## ... procrustes: rmse 0.1831 max resid 0.2345
## Run 2 stress 0
## ... procrustes: rmse 0.3703 max resid 0.4948
## Run 3 stress 0
## ... procrustes: rmse 0.1692 max resid 0.2085
## Run 4 stress 0
## ... procrustes: rmse 0.1849 max resid 0.23
## Run 5 stress 0
## ... procrustes: rmse 0.152 max resid 0.1892
## Run 6 stress 0
## ... procrustes: rmse 0.1075 max resid 0.1271
## Run 7 stress 0
## ... procrustes: rmse 0.02285 max resid 0.02293
## Run 8 stress 0
## ... procrustes: rmse 0.1813 max resid 0.2318
## Run 9 stress 0
## ... procrustes: rmse 0.03845 max resid 0.04173
## Run 10 stress 0
## ... procrustes: rmse 0.3805 max resid 0.486
## Run 11 stress 0
## ... procrustes: rmse 0.3464 max resid 0.4863
## Run 12 stress 0
## ... procrustes: rmse 0.05561 max resid 0.05975
## Run 13 stress 0
## ... procrustes: rmse 0.1767 max resid 0.2157
## Run 14 stress 0
## ... procrustes: rmse 0.3144 max resid 0.4322
## Run 15 stress 0
## ... procrustes: rmse 0.382 max resid 0.4697
## Run 16 stress 0
## ... procrustes: rmse 0.06563 max resid 0.07325
## Run 17 stress 0
## ... procrustes: rmse 0.0436 max resid 0.04735
## Run 18 stress 0
## ... procrustes: rmse 0.136 max resid 0.1589
## Run 19 stress 0
## ... procrustes: rmse 0.2962 max resid 0.3806
## Run 20 stress 0
## ... procrustes: rmse 0.2849 max resid 0.356
##
## Call:
## metaMDS(comm = veganify(physeq), distance = distance)
##
## global Multidimensional Scaling using monoMDS
##
## Data: wisconsin(sqrt(veganify(physeq)))
## Distance: bray
##
## Dimensions: 2
## Stress: 0
## Stress type 1, weak ties
## No convergent solutions - best solution after 20 tries
## Scaling: centring, PC rotation
## Species: expanded scores based on 'wisconsin(sqrt(veganify(physeq)))'
plot_heatmap(gp3, taxa.label = "Genus")
The warning preceding the previous plot is expected because an ordination should not be attempted with only 3 samples. You can avoid this error and ordination altogether by various options in the plot_heatmap
function. Here I will give the precise order of the samples to display, and then order the taxa by their phylum name.
plot_heatmap(gp3, taxa.label = "Genus", sample.order = sample_names(gp3), taxa.order = "Phylum")
plot_heatmap(gp3, taxa.label = "Genus", sample.label = "SampleType", sample.order = sample_names(gp3),
taxa.order = "Phylum")
I will close this issue for now unless/until further problems can be verified with a reproducible example. Hope this explanation helps solve at least part of the problem.
joey
Joey-
Thank you for your work to help resolve this issue. Explicitly setting the sample order and taxa order actually did fix my problem. Avoiding the ordination altogether was definitely the solution.
Thank you! Kristina
Joey-
I am trying to make a heatmap of log2 fold changes in abundance among samples. I have done this successfully before but this particular dataset is having issues. The error suggests there are missing values or NAs in my otu_table, which there are not. The values are finite and present in the matrix. What is wrong?
Thanks, Kristina