Outputs the phylogenetic distance between samples, based on phylogenetic distances of taxa in one sample to the taxa in the other
Usage
ph_comdist(
sample,
phylo,
rand_test = FALSE,
null_model = 0,
randomizations = 999,
abundance = TRUE
)
ph_comdistnt(
sample,
phylo,
rand_test = FALSE,
null_model = 0,
randomizations = 999,
abundance = TRUE
)
Arguments
- sample
(data.frame/character) sample data.frame or path to a sample file
- phylo
(character/phylo) One of: phylogeny as a newick string (will be written to a temp file) - OR path to file with a newick string - OR a an ape
phylo
object. required.- rand_test
(logical) do you want to use null models? Default:
FALSE
- null_model
(integer) which null model to use. See Details.
- randomizations
(numeric) number of randomizations. Default: 999
- abundance
(logical) If
TRUE
(default) computed accounting for abundance. Otherwise, uses presence-absence.
Details
See phylocomr-inputs for expected input formats
Null models
0 - Phylogeny shuffle: This null model shuffles species labels across the entire phylogeny. This randomizes phylogenetic relationships among species.
1 - Species in each sample become random draws from sample pool: This null model maintains the species richness of each sample, but the identities of the species occurring in each sample are randomized. For each sample, species are drawn without replacement from the list of all species actually occurring in at least one sample. Thus, species in the phylogeny that are not actually observed to occur in a sample will not be included in the null communities
2 - Species in each sample become random draws from phylogeny pool: This null model maintains the species richness of each sample, but the identities of the species occurring in each sample are randomized. For each sample, species are drawn without replacement from the list of all species in the phylogeny pool. All species in the phylogeny will have equal probability of being included in the null communities. By changing the phylogeny, different species pools can be simulated. For example, the phylogeny could include the species present in some larger region.
3 - Independent swap: The independent swap algorithm (Gotelli and Entsminger, 2003); also known as ‘SIM9’ (Gotelli, 2000) creates swapped versions of the sample/species matrix.
Taxon name case
In the sample
table, if you're passing in a file, the names in the
third column must be all lowercase; if not, we'll lowercase them for you.
If you pass in a data.frame, we'll lowercase them for your. All phylo
tip/node labels are also lowercased to avoid any casing problems
Examples
sfile <- system.file("examples/sample_comstruct", package = "phylocomr")
pfile <- system.file("examples/phylo_comstruct", package = "phylocomr")
# from data.frame
sampledf <- read.table(sfile, header = FALSE,
stringsAsFactors = FALSE)
phylo_str <- readLines(pfile)
ph_comdist(sample = sampledf, phylo = phylo_str)
#> # A tibble: 6 × 7
#> name clump1 clump2a clump2b clump4 even random
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 clump1 4.25 6.75 8.08 8.71 8.06 8.05
#> 2 clump2a 6.75 4.94 8.72 8.42 8.06 7.82
#> 3 clump2b 8.08 8.72 5.83 7.36 8.06 7.95
#> 4 clump4 8.71 8.42 7.36 6.94 7.88 8.24
#> 5 even 8.06 8.06 8.06 7.87 7.75 8
#> 6 random 8.05 7.82 7.95 8.24 8 7.11
ph_comdistnt(sample = sampledf, phylo = phylo_str)
#> # A tibble: 6 × 7
#> name clump1 clump2a clump2b clump4 even random
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 clump1 2 4.17 4.83 6 4.75 4.88
#> 2 clump2a 4.17 2 6 4.33 4.5 4.62
#> 3 clump2b 4.83 6 2 3 4 3.94
#> 4 clump4 6 4.33 3 2 2 4.10
#> 5 even 4.75 4.5 4 2 6 2.62
#> 6 random 4.88 4.62 3.94 4.10 2.62 4.88
ph_comdist(sample = sampledf, phylo = phylo_str, rand_test = TRUE)
#> $obs
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 4.250000 6.749999 8.083335 8.708335 8.062500 8.046875
#> 2 clump2a 6.750001 4.944444 8.722219 8.416661 8.062505 7.822916
#> 3 clump2b 8.083340 8.722218 5.833330 7.361108 8.062505 7.947916
#> 4 clump4 8.708339 8.416662 7.361108 6.944441 7.875004 8.239582
#> 5 even 8.062500 8.062500 8.062496 7.874995 7.750000 8.000000
#> 6 random 8.046875 7.822917 7.947919 8.239586 8.000000 7.109375
#>
#> $null_mean
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 7.261261 7.969302 7.956369 8.141472 8.056025 8.131757
#> 2 clump2a 7.969302 7.173509 8.086781 7.975545 8.062560 8.197477
#> 3 clump2b 7.956369 8.086781 7.154207 7.744113 8.063019 8.016567
#> 4 clump4 8.141472 7.975545 7.744113 7.157876 7.805554 8.015607
#> 5 even 8.056025 8.062560 8.063019 7.805554 7.286787 7.992352
#> 6 random 8.131757 8.197477 8.016567 8.015607 7.992352 7.009134
#>
#> $null_sd
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 0.315178 0.229624 0.233166 0.232100 0.207360 0.246135
#> 2 clump2a 0.229624 0.319030 0.233981 0.232639 0.206700 0.269111
#> 3 clump2b 0.233166 0.233981 0.312972 0.241023 0.214732 0.254215
#> 4 clump4 0.232100 0.232639 0.241023 0.310306 0.226838 0.247268
#> 5 even 0.207360 0.206700 0.214732 0.226838 0.276014 0.235101
#> 6 random 0.246135 0.269111 0.254215 0.247268 0.235101 0.350861
#>
#> $NRI_or_NTI
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 9.554153 5.309993 -0.544531 -2.442323 -0.031228 0.344859
#> 2 clump2a 5.309981 6.987000 -2.715764 -1.896141 0.000268 1.391845
#> 3 clump2b -0.544551 -2.715760 4.220430 1.589082 0.002394 0.270053
#> 4 clump4 -2.442339 -1.896145 1.589080 0.687820 -0.306166 -0.905798
#> 5 even -0.031228 0.000291 0.002434 -0.306126 -1.678227 -0.032533
#> 6 random 0.344859 1.391843 0.270040 -0.905814 -0.032533 -0.285699
#>
ph_comdistnt(sample = sampledf, phylo = phylo_str, rand_test = TRUE)
#> $obs
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 2.000000 4.166667 4.833334 6.000000 4.750 4.875000
#> 2 clump2a 4.166667 2.000000 6.000000 4.333333 4.500 4.625000
#> 3 clump2b 4.833333 6.000000 2.000000 3.000000 4.000 3.937500
#> 4 clump4 6.000000 4.333334 3.000000 2.000000 2.000 4.104167
#> 5 even 4.750000 4.500000 4.000000 2.000000 6.000 2.625000
#> 6 random 4.875000 4.625000 3.937500 4.104167 2.625 4.875000
#>
#> $null_mean
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 4.718719 2.670172 2.640138 3.554155 3.340841 3.541709
#> 2 clump2a 2.670172 4.740574 2.973974 2.610193 3.349951 3.657942
#> 3 clump2b 2.640138 2.973974 4.672006 2.240909 3.357058 3.363938
#> 4 clump4 3.554155 2.610193 2.240909 4.726387 2.241042 3.337194
#> 5 even 3.340841 3.349951 3.357058 2.241042 4.714214 3.142141
#> 6 random 3.541709 3.657942 3.363938 3.337194 3.142141 4.673674
#>
#> $null_sd
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 0.646080 0.483008 0.463865 0.564852 0.533192 0.636135
#> 2 clump2a 0.483008 0.697049 0.517605 0.462420 0.525938 0.632170
#> 3 clump2b 0.463865 0.517605 0.706497 0.393380 0.541307 0.584956
#> 4 clump4 0.564852 0.462420 0.393380 0.656437 0.398641 0.565941
#> 5 even 0.533192 0.525938 0.541307 0.398641 0.634794 0.572299
#> 6 random 0.636135 0.632170 0.584956 0.565941 0.572299 0.715794
#>
#> $NRI_or_NTI
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 4.208025 -3.098280 -4.728091 -4.330064 -2.642876 -2.095924
#> 2 clump2a -3.098280 3.931681 -5.846209 -3.726356 -2.186663 -1.529744
#> 3 clump2b -4.728090 -5.846207 3.782049 -1.929663 -1.187758 -0.980522
#> 4 clump4 -4.330064 -3.726357 -1.929662 4.153314 0.604659 -1.355218
#> 5 even -2.642876 -2.186664 -1.187758 0.604659 -2.025516 0.903621
#> 6 random -2.095924 -1.529744 -0.980522 -1.355218 0.903621 -0.281263
#>
# from files
sample_str <- paste0(readLines(sfile), collapse = "\n")
sfile2 <- tempfile()
cat(sample_str, file = sfile2, sep = '\n')
pfile2 <- tempfile()
cat(phylo_str, file = pfile2, sep = '\n')
ph_comdist(sample = sfile2, phylo = pfile2)
#> # A tibble: 6 × 7
#> name clump1 clump2a clump2b clump4 even random
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 clump1 4.25 6.75 8.08 8.71 8.06 8.05
#> 2 clump2a 6.75 4.94 8.72 8.42 8.06 7.82
#> 3 clump2b 8.08 8.72 5.83 7.36 8.06 7.95
#> 4 clump4 8.71 8.42 7.36 6.94 7.88 8.24
#> 5 even 8.06 8.06 8.06 7.87 7.75 8
#> 6 random 8.05 7.82 7.95 8.24 8 7.11
ph_comdistnt(sample = sfile2, phylo = pfile2)
#> # A tibble: 6 × 7
#> name clump1 clump2a clump2b clump4 even random
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 clump1 2 4.17 4.83 6 4.75 4.88
#> 2 clump2a 4.17 2 6 4.33 4.5 4.62
#> 3 clump2b 4.83 6 2 3 4 3.94
#> 4 clump4 6 4.33 3 2 2 4.10
#> 5 even 4.75 4.5 4 2 6 2.62
#> 6 random 4.88 4.62 3.94 4.10 2.62 4.88
ph_comdist(sample = sfile2, phylo = pfile2, rand_test = TRUE)
#> $obs
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 4.250000 6.749999 8.083335 8.708335 8.062500 8.046875
#> 2 clump2a 6.750001 4.944444 8.722219 8.416661 8.062505 7.822916
#> 3 clump2b 8.083340 8.722218 5.833330 7.361108 8.062505 7.947916
#> 4 clump4 8.708339 8.416662 7.361108 6.944441 7.875004 8.239582
#> 5 even 8.062500 8.062500 8.062496 7.874995 7.750000 8.000000
#> 6 random 8.046875 7.822917 7.947919 8.239586 8.000000 7.109375
#>
#> $null_mean
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 7.261261 7.969302 7.956369 8.141472 8.056025 8.131757
#> 2 clump2a 7.969302 7.173509 8.086781 7.975545 8.062560 8.197477
#> 3 clump2b 7.956369 8.086781 7.154207 7.744113 8.063019 8.016567
#> 4 clump4 8.141472 7.975545 7.744113 7.157876 7.805554 8.015607
#> 5 even 8.056025 8.062560 8.063019 7.805554 7.286787 7.992352
#> 6 random 8.131757 8.197477 8.016567 8.015607 7.992352 7.009134
#>
#> $null_sd
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 0.315178 0.229624 0.233166 0.232100 0.207360 0.246135
#> 2 clump2a 0.229624 0.319030 0.233981 0.232639 0.206700 0.269111
#> 3 clump2b 0.233166 0.233981 0.312972 0.241023 0.214732 0.254215
#> 4 clump4 0.232100 0.232639 0.241023 0.310306 0.226838 0.247268
#> 5 even 0.207360 0.206700 0.214732 0.226838 0.276014 0.235101
#> 6 random 0.246135 0.269111 0.254215 0.247268 0.235101 0.350861
#>
#> $NRI_or_NTI
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 9.554153 5.309993 -0.544531 -2.442323 -0.031228 0.344859
#> 2 clump2a 5.309981 6.987000 -2.715764 -1.896141 0.000268 1.391845
#> 3 clump2b -0.544551 -2.715760 4.220430 1.589082 0.002394 0.270053
#> 4 clump4 -2.442339 -1.896145 1.589080 0.687820 -0.306166 -0.905798
#> 5 even -0.031228 0.000291 0.002434 -0.306126 -1.678227 -0.032533
#> 6 random 0.344859 1.391843 0.270040 -0.905814 -0.032533 -0.285699
#>
ph_comdistnt(sample = sfile2, phylo = pfile2, rand_test = TRUE)
#> $obs
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 2.000000 4.166667 4.833334 6.000000 4.750 4.875000
#> 2 clump2a 4.166667 2.000000 6.000000 4.333333 4.500 4.625000
#> 3 clump2b 4.833333 6.000000 2.000000 3.000000 4.000 3.937500
#> 4 clump4 6.000000 4.333334 3.000000 2.000000 2.000 4.104167
#> 5 even 4.750000 4.500000 4.000000 2.000000 6.000 2.625000
#> 6 random 4.875000 4.625000 3.937500 4.104167 2.625 4.875000
#>
#> $null_mean
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 4.718719 2.670172 2.640138 3.554155 3.340841 3.541709
#> 2 clump2a 2.670172 4.740574 2.973974 2.610193 3.349951 3.657942
#> 3 clump2b 2.640138 2.973974 4.672006 2.240909 3.357058 3.363938
#> 4 clump4 3.554155 2.610193 2.240909 4.726387 2.241042 3.337194
#> 5 even 3.340841 3.349951 3.357058 2.241042 4.714214 3.142141
#> 6 random 3.541709 3.657942 3.363938 3.337194 3.142141 4.673674
#>
#> $null_sd
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 0.646080 0.483008 0.463865 0.564852 0.533192 0.636135
#> 2 clump2a 0.483008 0.697049 0.517605 0.462420 0.525938 0.632170
#> 3 clump2b 0.463865 0.517605 0.706497 0.393380 0.541307 0.584956
#> 4 clump4 0.564852 0.462420 0.393380 0.656437 0.398641 0.565941
#> 5 even 0.533192 0.525938 0.541307 0.398641 0.634794 0.572299
#> 6 random 0.636135 0.632170 0.584956 0.565941 0.572299 0.715794
#>
#> $NRI_or_NTI
#> name clump1 clump2a clump2b clump4 even random
#> 1 clump1 4.208025 -3.098280 -4.728091 -4.330064 -2.642876 -2.095924
#> 2 clump2a -3.098280 3.931681 -5.846209 -3.726356 -2.186663 -1.529744
#> 3 clump2b -4.728090 -5.846207 3.782049 -1.929663 -1.187758 -0.980522
#> 4 clump4 -4.330064 -3.726357 -1.929662 4.153314 0.604659 -1.355218
#> 5 even -2.642876 -2.186664 -1.187758 0.604659 -2.025516 0.903621
#> 6 random -2.095924 -1.529744 -0.980522 -1.355218 0.903621 -0.281263
#>