Thank you ofr your kind response, I think it is working now
MULTIVARIANCE ANALYSIS - PERMANOVA: Permutational multivariate analysis of variance
library(reprex)
library(vegan)
library(readxl)
load data
Permanova_fieldlayer <- read_excel("C:/Users/Usuario/Dropbox/SLU restoration/Permanova_fieldlayer.xlsx")
str(Permanova_fieldlayer)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 54 obs. of 37 variables:
Treatment : chr "Burning" "Burning" "Burning" "Burning" ...
ID : num 1935 1935 1935 2746 2746 ...
Timeline : chr "Before" "After" "Follow up" "Before" ...
Vaccinium myrtillus : num 23 24 21 24 23 22 24 21 21 24 ...
Vaccinium vitis-idaea : num 22 24 25 24 21 24 23 22 25 23 ...
Deschampsia flexuosa : num 7 7 17 1 2 3 4 5 16 10 ...
Linnaea borealis : num 9 0 2 8 0 3 7 1 3 3 ...
Luzula pilosa : num 0 0 0 0 0 0 1 0 0 0 ...
Juniperus comunis : num 0 0 0 0 0 0 0 0 0 0 ...
Melampyrum sylvaticum : num 0 0 0 0 0 2 1 0 4 0 ...
Lycopodium annotinum : num 0 0 0 0 0 0 2 0 0 1 ...
Maianthemum bifolium : num 0 0 0 0 0 0 0 0 0 0 ...
Empetrum nigrum : num 2 0 0 6 0 0 1 0 0 3 ...
Calluna vulgaris : num 0 0 0 1 0 0 0 0 0 0 ...
Andromeda polifolia : num 0 0 0 0 0 0 0 0 0 0 ...
Rubus chamaemorus : num 0 0 0 0 0 0 1 0 1 0 ...
Vaccinium uglinosum : num 0 0 0 0 0 0 0 0 0 0 ...
Gymnocarpium dryopteris : num 0 0 0 0 0 0 0 0 0 0 ...
Trientalis europaea : num 1 0 0 0 0 0 0 0 0 0 ...
Melampyrum pratense : num 0 0 2 1 0 1 0 0 3 0 ...
Epibolium angustifolium : num 0 4 9 0 2 8 0 9 12 0 ...
Equisetum pratense : num 0 0 0 0 0 1 0 0 0 0 ...
Equisetum sylvaticum : num 0 0 0 0 1 0 0 0 3 1 ...
Orthilia secunda : num 0 0 0 0 0 0 0 0 0 0 ...
Deschampsia cespitosa : num 0 0 0 0 0 0 0 0 1 0 ...
Rubus idaeus : num 0 0 1 0 0 0 0 1 0 0 ...
Solidago virgaurea : num 0 0 0 0 0 0 0 0 0 0 ...
Calamagrostis purpurea : num 0 0 0 0 0 0 0 0 0 0 ...
Godyera repen : num 0 0 0 0 0 0 0 0 0 0 ...
Vaccinium oxycoccos : num 0 0 0 2 0 0 0 0 0 0 ...
Diphasiastrum complanatum: num 0 0 0 0 0 0 0 0 0 0 ...
Listera cordata : num 0 0 0 0 0 0 0 0 0 0 ...
Ranunculus lapponicus : num 0 0 0 0 0 0 0 0 0 0 ...
Melampyrum sp. : num 0 0 0 0 0 0 0 0 0 0 ...
Carex sp : num 0 0 0 2 0 0 0 0 0 0 ...
Rhododendron tomentosum : num 0 0 0 1 0 0 0 0 0 0 ...
$ Equisetum palustre : num 0 0 0 0 0 0 0 0 0 0 ...
Permanova_fieldlayer$Treatment <- as.factor(Permanova_fieldlayer$Treatment)
Permanova_fieldlayer$Timeline <- as.factor(Permanova_fieldlayer$Timeline)
Permanova_fieldlayer$ID <- as.factor(Permanova_fieldlayer$ID)
Permanova_fieldlayer$Group <- paste(Permanova_fieldlayer$Treatment, Permanova_fieldlayer$Timeline)
- Transform the data
FL.mat<-sqrt(FL.matrix)#square root transform
2. Calculate dissimilarity matrix between sites based on species occurence
FL.dist<-vegdist(FL.mat, method='bray')
set.seed(36)
3.test homogeneity of dispersion among groups (different treatments and timeline),
which is a condition (assumption) for adonis.
dispersion<-betadisper(FL.dist, group=Permanova_fieldlayer$Group)
WARNING### some squared distances are negative and changed to zero!!!!!!
permutest(dispersion)
Permutation test for homogeneity of multivariate dispersions
Permutation: free
Number of permutations: 999
Response: Distances
Df Sum Sq Mean Sq F N.Perm Pr(>F)
Groups 8 0.028468 0.0035585 0.9517 999 0.479
Residuals 45 0.168254 0.0037390
plot(dispersion, hull=FALSE, ellipse=TRUE) ##sd ellipse
Results show homogeonous dispersion
perform permanova to test if field layer community is influenced by treatment and timeline
FL.div
Permutation test for adonis under reduced model
Terms added sequentially (first to last)
Permutation: free
Number of permutations: 999
adonis2(formula = FL.dist ~ Treatment + Timeline, data = Permanova_fieldlayer, permutations = 999, method = "bray", strata = "ID")
Df SumOfSqs R2 F Pr(>F)
Treatment 2 0.27191 0.10486 3.0737 0.001 ***
Timeline 2 0.15391 0.05935 1.7399 0.069 .
Residual 49 2.16737 0.83579
Total 53 2.59319 1.00000
Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1
does it really take into account repeated measures within each treatment??
POST HOC
library(devtools)
install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")
install.packages("Rtools")
library(pairwiseAdonis)
Martinez Arbizu, P. (2019). pairwiseAdonis: Pairwise multilevel comparison using adonis.
R package version 0.3
For strata, extract factors into a new data.frame
fac <- data.frame(Treatment=Permanova_fieldlayer$Treatment, Timeline = rep( c('before','after' .... [TRUNCATED]
dim(FL.dist)
NULL
posthoc_FL <-pairwise.adonis2(FL.dist~Treatment+Timeline, data=fac, strata="ID")
Error in [.data.frame
(mdat1, , strata) : undefined columns selected
In addition: Warning messages:
1: In betadisper(FL.dist, group = Permanova_fieldlayer$Group) :
some squared distances are negative and changed to zero
2: package ‘devtools’ was built under R version 3.5.3
3: package ‘usethis’ was built under R version 3.5.3
source('~/.active-rstudio-document', echo=TRUE)