How do I Create Chao1 values?

Hi,

I need to create one chao1 value for each row. However, when I use the following functions---chaodist(), vegdist(), chao1(), or aggregate()---they all end up creating errors. I have added my codes and some repeatable data. Could one of you awesome people please help me create a chao1 value? Dput and codes are below. Thanks in advance!!!

CODES

require(vegan)
require(tidyverse)
require(ggplot2)
require(OTUtable)

#Upload data
species.dat <- structure(list(...

#Put raw data into long format
species.dat_long <- as.data.frame (species.dat) %>% tibble::rownames_to_column(var = "Plot") # Turn rownames into a column

#Add site column (ANOVA needs at least three names per site)
long_data_new <- species.dat_long %>% mutate(Site = case_when(str_detect(Plot, "D") ~ "Decatur", str_detect(Plot, "H") ~ "Field Station", str_detect(Plot, "C") ~ "Cedartown", TRUE ~ "Unknown"))

#first try
vegdist(species.dat_long$, method="chao")

#second try
agg <- aggregate(Decatur, data=long_data_new , chao)

#third try
chaodist(species.dat$Decatur)

DPUT

structure(list(s__Clostridium_XlVa_unclassified = c(0.001848, 0, 0.00488, 0.004071, 0, 0.002439, 0.012116, 0.011045, 0, 0.004917, 0.002289, 0.001408), s__Gracilibacteraceae_unclassified = c(0.001848, 0, 0, 0.001357, 0.012309, 0.012197, 0.012116, 0.007363, 0, 0, 0.002289, 0), s__Jahnella_unclassified = c(0.00739, 0.004204, 0.00244, 0.001357, 0.004103, 0.004879, 0.006058, 0.005523, 0, 0.004917, 0.004578, 0), s__Luteimonas_unclassified = c(0.003695, 0.002102, 0, 0.004071, 0, 0, 0.006058, 0.007363, 0.013913, 0, 0.006866, 0), s__Propionivibrio_unclassified = c(0.001848, 0, 0, 0.005428, 0, 0.007318, 0.012116, 0.018408, 0, 0, 0, 0), s__Rhodoferax_koreense = c(0.005543, 0.01051, 0.014641, 0.010856, 0, 0, 0, 0, 0, 0, 0, 0), s__Rhodopseudomonas_unclassified = c(0.012933, 0.004204, 0.00488, 0.009499, 0.002051, 0.002439, 0, 0.001841, 0.001988, 0, 0, 0)), class = "data.frame", row.names = c("D15B", "D610B", "D15F", "D610F", "HR15B", "HR610B", "HR15F", "HR610F", "C15B", "C610B", "C15F", "C610F"))

vegdist requires all numeric data.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(stringr)
library(tidyr)
library(tibble)
library(vegan)
#> Loading required package: permute
#> Loading required package: lattice
#> This is vegan 2.5-7


df1 <- structure(list(s__Clostridium_XlVa_unclassified = c(0.001848, 0, 0.00488, 0.004071, 0, 0.002439, 0.012116, 0.011045, 0, 0.004917, 0.002289, 0.001408), s__Gracilibacteraceae_unclassified = c(0.001848, 0, 0, 0.001357, 0.012309, 0.012197, 0.012116, 0.007363, 0, 0, 0.002289, 0), s__Jahnella_unclassified = c(0.00739, 0.004204, 0.00244, 0.001357, 0.004103, 0.004879, 0.006058, 0.005523, 0, 0.004917, 0.004578, 0), s__Luteimonas_unclassified = c(0.003695, 0.002102, 0, 0.004071, 0, 0, 0.006058, 0.007363, 0.013913, 0, 0.006866, 0), s__Propionivibrio_unclassified = c(0.001848, 0, 0, 0.005428, 0, 0.007318, 0.012116, 0.018408, 0, 0, 0, 0), s__Rhodoferax_koreense = c(0.005543, 0.01051, 0.014641, 0.010856, 0, 0, 0, 0, 0, 0, 0, 0), s__Rhodopseudomonas_unclassified = c(0.012933, 0.004204, 0.00488, 0.009499, 0.002051, 0.002439, 0, 0.001841, 0.001988, 0, 0, 0)), class = "data.frame", row.names = c("D15B", "D610B", "D15F", "D610F", "HR15B", "HR610B", "HR15F", "HR610F", "C15B", "C610B", "C15F", "C610F"))

df1 <- rownames_to_column(df1, var = "Plot") 
pivot_longer(df1,cols = rowname) %>% select(-name,value,everything())
#> Error: Can't subset columns that don't exist.
#> x Column `rowname` doesn't exist.
df2 <- df1 %>% mutate(Site = case_when(str_detect(Plot, "D") ~ "Decatur", str_detect(Plot, "H") ~ "Field Station", str_detect(Plot, "C") ~ "Cedartown", TRUE ~ "Unknown"))

# data must be all numeric
df2 <- df2[,2:8]

vegdist(df2,method="chao")
#> Warning in vegdist(df2, method = "chao"): results may be meaningless with non-
#> integer data in method "chao"
#>             1          2          3          4          5          6          7
#> 2  0.15792622                                                                  
#> 3  0.21053981 0.24999431                                                       
#> 4  0.00000000 0.29629630 0.29629630                                            
#> 5  0.36843754 0.77778580 0.82353873 0.66666667                                 
#> 6  0.26315340 0.81818182 0.76191522 0.40740741 0.33332195                      
#> 7  0.52630679 0.84210526 0.81250480 0.55555556 0.64178714 0.18946478           
#> 8  0.15789774 0.77777275 0.74999765 0.29629630 0.71427740 0.14285160 0.03571775
#> 9  0.52633528 0.70000000 0.91999165 0.62962963 0.93750172 0.94736878 0.87719345
#> 10 0.73684660 0.83333333 0.72728289 0.85185185 0.81817779 0.75000000 0.62500000
#> 11 0.57894887 0.73214536 0.79999964 0.70370370 0.59319120 0.55552892 0.25000000
#> 12 0.94735793 1.00000000 0.81818859 0.88888889 1.00000000 0.91667805 0.75000000
#>             8          9         10         11
#> 2                                             
#> 3                                             
#> 4                                             
#> 5                                             
#> 6                                             
#> 7                                             
#> 8                                             
#> 9  0.82143065                                 
#> 10 0.67855965 1.00000000                      
#> 11 0.39285645 0.59619054 0.57140182           
#> 12 0.78571290 1.00000000 0.50000000 0.85713394

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.