I am trying to write output from permutation analysis by using below code but it shows error, could you please suggest how I can resolve this error?
R code
###adonis_calculation
BC <- phyloseq::distance(phyloseq_prop, "bray")
pmv =adonis(BC ~Season*Region, as(sample_data(physeqN3), "data.frame"),permutations = 5000)
pmv
write.table(pmv, "permutation.16s.Root.txt")
Error:
Df SumsOfSqs MeanSqs F.Model R2 Pr(>F)
Season 1 1.2435 1.24348 17.229 0.07405 2e-04 ***
Region 2 5.3491 2.67457 37.058 0.31855 2e-04 ***
Season:Region 2 1.3222 0.66110 9.160 0.07874 2e-04 ***
Residuals 123 8.8773 0.07217 0.52866
Total 128 16.7921 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ‘"adonis"’ to a data.frame
Calls: write.table ... data.frame -> as.data.frame -> as.data.frame.default
Execution halted
Many thanks
The output is not in data.frame format, an option is to capture the output with capture.output
capture.output(pmv, file = "permutation.16s.Root.txt")
Using a small reproducible example
library(vegan)
data(dune)
data(dune.env)
pmv <- adonis(dune ~ Management*A1, data = dune.env)
capture.output(pmv, file = "/Users/akrun/tmp/permutation.16s.Root.txt")
-output