#read the table of biome occupacy and ploidy info in, fix some typos that appear in the dataframe biome_table <- read.csv("single biome ploidy data.csv", stringsAsFactors = FALSE) colnames(biome_table)[1] <- "Genus" biome_table[70,2] <- "parviflora" #create contingency tables for ploidy vs occupancy in the forest biome, assigning multiploid species as low ploidy. forest_ctable_low <- table(biome_table$Forest, biome_table$wgd.low) #create contingency tables for ploidy vs occupancy in the open biome, assigning multiploid species as low ploidy. open_ctable_low <- table(biome_table$Open, biome_table$wgd.low) #create contingency tables for ploidy vs occupancy in the alpine biome, assigning multiploid species as low ploidy. alpine_ctable_low <- table(biome_table$Alpine, biome_table$wgd.low) #as above, but assigning multiploid species to the high plidy group forest_ctable_high <- table(biome_table$Forest, biome_table$wgd.high) open_ctable_high <- table(biome_table$Open, biome_table$wgd.high) alpine_ctable_high <- table(biome_table$Alpine, biome_table$wgd.high) #test each contingency table using chi square test fisher.test(forest_ctable_low) fisher.test(forest_ctable_high) fisher.test(open_ctable_low) fisher.test(open_ctable_high) fisher.test(alpine_ctable_low) fisher.test(alpine_ctable_high) all_pvalues <- unlist( lapply( list( forest_ctable_low, forest_ctable_high, open_ctable_low, open_ctable_high, alpine_ctable_low, alpine_ctable_high ), function(tbl) { chisq.test(tbl)$p.value } ) ) p.adjust(all_pvalues, method = "holm") low_pvalues <- unlist( lapply( list( forest_ctable_low, open_ctable_low, alpine_ctable_low, ), function(tbl) { chisq.test(tbl)$p.value } ) ) p.adjust(low_pvalues, method = "holm") high_pvalues <- unlist( lapply( list( forest_ctable_high, open_ctable_high, alpine_ctable_high, ), function(tbl) { chisq.test(tbl)$p.value } ) ) p.adjust(high_pvalues, method = "holm")