### Supporting Information to the paper Zeleny, D. Bias in community-weighted mean analysis of plant functional traits and species indicator values. Journal of Vegetation Science. ---- ### Appendix S4. R-code for all analyses. ## 1a. 2D simulated community data based on Fridley et al. (2007) ---- # 4 scenarios x 10 levels of beta diversity x 1000 artificial communities per combination # calculates correlation, regression and fourth corner, and test the relationship using # standard+modified test (correlation) and test 2, 4, 6 (fourth corner). No test done for # regression, just R2 and b0 + b1 reported) library (weimea) # version 0.63, see Appendix S5 library (vegan) # version 2.4-0 library (lattice) no.perm <- 1000 combination <- expand.grid (perm = 1:no.perm, no.comm = 1:10, scenario = 1:4) require (parallel) cl <- makeCluster (8) # modify this according to the number of cores available clusterExport (cl, c ('combination')) res.comb <- parRapply (cl, x = combination, FUN = function (comb) { # comb[1] is scenario, comb[2] is number of communities require (weimea) scenario <- comb[3] no.comm <- comb[2] res.temp <- list () comm <- sample.comm.2 (simul.comm.2 (gr1.length = 1000, gr2.length = no.comm*1000, totS = no.comm*100, max.niche = c(1000, 1000), min.niche = c(1000/2, 1000/2), plotting = F), Np = 50, pa = F, no.ind = 500) env <- comm$sample.x1 env <- if (scenario == 3 || scenario == 4) sample (env) else env M <- if (scenario == 2 || scenario == 4) weimea::wm (speatt = sample (comm$simul.comm$m1), sitspe = comm$a.mat) else weimea::wm (speatt = comm$simul.comm$m1, sitspe = comm$a.mat) res.temp[['cor']] <- test.MR (M = M, env = env, method = 'cor', test = c('standard', 'modified')) res.temp[['lm']] <- test.MR (M = M, env = env, method = 'lm', test = c('standard', 'modified')) res.temp[['four2']] <- test.MR (M = M, env = env, method = 'four', fc.test = 2, test = NULL, chessel = TRUE) res.temp[['four4']] <- test.MR (M = M, env = env, method = 'four', fc.test = 4, test = NULL, chessel = TRUE) res.temp[['four6']] <- test.MR (M = M, env = env, method = 'four', fc.test = 6, test = NULL, chessel = TRUE) return (res.temp) }) stopCluster (cl) res.comb.df0 <- do.call (rbind.data.frame , lapply (res.comb, FUN = function (res.comb.temp) as.matrix (t(unlist (c (unlist (res.comb.temp$cor$out[[1]]), unlist (res.comb.temp$lm$out[[1]]), res.comb.temp$four2$out[1,], res.comb.temp$four4$out[1,], res.comb.temp$four6$out[1,])))))) res.comb.df <- cbind (combination, res.comb.df0) names (res.comb.df) <- c("perm", "no.comm", "scenario", "cor.r.obs", "cor.t.obs", "cor.P.par", "cor.P.sta", "cor.P.mod", "cor.P.LR", "cor.P.two", "lm.coef1", "lm.coef2", "lm.rsq.obs", "lm.rsq.adj.sta", "lm.rsq.adj.mod", "lm.rsq.adj.mod2", "lm.F.obs", "lm.P.par", "lm.P.sta", "lm.P.mod", "lm.P.LR", "lm.P.two", "names", "fourthcorner", "fc.P.2", "names", "fourthcorner", "fc.P.4", "names", "fourthcorner", "fc.P.6") save (res.comb.df, file = 'res.comb.df.r') # save this object for plotting results later ## 1b. 2D simulated community data - calculating beta diversity ---- # 4 scenarios x 10 levels of beta diversity x 1000 artificial communities per combination no.perm <- 1000 combination <- expand.grid (perm = 1:no.perm, no.comm = 1:10, scenario = 1:4) require (parallel) cl <- makeCluster (8) # modify this according to the number of cores available clusterExport (cl, c ('combination')) res.comb.div <- parRapply (cl, x = combination, FUN = function (comb) { # comb[1] is scenario, comb[2] is number of communities require (weimea) scenario <- comb[3] no.comm <- comb[2] res.div.temp <- list () comm <- sample.comm.2 (simul.comm.2 (gr1.length = 1000, gr2.length = no.comm*1000, totS = no.comm*100, max.niche = c(1000, 1000), min.niche = c(1000/2, 1000/2), plotting = F), Np = 50, pa = F, no.ind = 500) res.div.temp[['alpha']] <- mean (rowSums (comm$a.mat > 0)) res.div.temp[['gamma']] <- sum (colSums (comm$a.mat) > 0) res.div.temp[['beta.whit']] <- res.div.temp[['gamma']]/res.div.temp[['alpha']] res.div.temp[['whit.dist']] <- betadiv.ia (comm$a.mat) return (res.div.temp) }) stopCluster (cl) res.comb.div.df0 <- do.call (rbind.data.frame , res.comb.div) names (res.comb.div.df) <- c("alpha", "gamma", "beta.whit", "whit.dist") save (res.comb.div.df, file = 'res.comb.div.df.r') # save this object for plotting results later ## 2a. 1D simulated data of Dray & Legendre (2008) ---- # evaluation of standard and modified permutation tests; for comparison with Table 1. & 2. from # Dray & Legendre (2008) and Table A1 in Appendix 1 of ter Braak et al. (2012) require (weimea) require (parallel) cl <- makeCluster(8) # to be run parallel on 8 cores - modify according to the number of cores available no.perm <- 1000 # number of simulated dataset created - 1000 perm <- 999 # number of permutations for standard and modified permutation tests combination <- expand.grid (perm = 1:no.perm, no.spec = c(30, 50, 100), no.sites = c(30, 50, 100), mi.tol = c(10, 30, 60), scenario = 1:4) clusterExport (cl, list ('combination')) res.dray <- parRapply (cl, combination, FUN = function (comb){ #comb[2] = no.spec, comb[3] = no.sites, comb[4] = mi.tol, comb[5] = scenario require (weimea) comm <- simul.RLQ (scenario = comb[5], mi.tol = comb[4], n = comb[3], p = comb[2]) M <- wm (sitspe = comm$sitspe, speatt = comm$speatt) res.temp <- list () res.temp$out <- test.MR (M = M, env = comm$env, method = 'cor', test = c('standard', 'modified'), perm = 999)$out res.temp$par <- comb return (res.temp) }) stopCluster (cl) res.dray.df <- do.call (rbind, lapply (res.dray, FUN = function (res) c(res$par, do.call (cbind, res$out$`mi / x`)[1,]))) res.dray.df.agg0 <- aggregate (cbind (P.sta, P.mod) ~ scenario + no.spec + no.sites + mi.tol , data = res.dray.df, FUN = function (x) sum (x < 0.05)/no.perm) res.dray.df.agg <- cbind (aggregate (P.sta ~ no.spec + no.sites + mi.tol , data = res.dray.df, sum)[,3:1], # this adds the combinations of mi.tol x no.sites x no.spec matrix (res.dray.df.agg0$P.sta, ncol = 4, byrow = T, dimnames = list (NULL, paste ('P.sta', 1:4, sep = '.'))), # matrix of P.sta for four scenarios matrix (res.dray.df.agg0$P.mod, ncol = 4, byrow = T, dimnames = list (NULL, paste ('P.mod', 1:4, sep = '.')))#, # matrix of P.mod for four scenarios # matrix (res.dray.df.agg0$P.LR, ncol = 4, byrow = T, dimnames = list (NULL, paste ('P.LR', 1:4, sep = '.'))), # matrix of P.LR for four scenarios # matrix (res.dray.df.agg0$P.two, ncol = 4, byrow = T, dimnames = list (NULL, paste ('P.two', 1:4, sep = '.'))) # matrix of P.two for four scenarios ) write.table (res.dray.df.agg, file = 'res.dray.df.agg.csv', sep = ',', col.names = NA) save (res.dray.df.agg, file = 'res.dray.df.agg.r') ## 2b Calculating beta diversity of each combination (no.spe x no.sites x mi.tol) for Dray & Legendre (2012) model ---- require (weimea) require (parallel) cl <- makeCluster(8) # to be run parallel on 8 cores no.perm <- 1000 # number of simulated dataset created combination <- expand.grid (perm = 1:no.perm, no.spec = c(30, 50, 100), no.sites = c(30, 50, 100), mi.tol = c(10, 30, 60), scenario = 1) # all scenarios have the same species comp. matrix clusterExport (cl, list ('combination')) set.seed (1000) res.beta <- parRapply (cl, combination, FUN = function (comb){ #comb[2] = no.spec, comb[3] = no.sites, comb[4] = mi.tol, comb[5] = scenario require (weimea) comm <- simul.RLQ (scenario = comb[5], mi.tol = comb[4], n = comb[3], p = comb[2]) comm.1N <- simul.RLQ (scenario = comb[5], mi.tol = comb[4], n = comb[3], p = comb[2], add.noise = TRUE) list(betadiv.ia (comm$sitspe), betadiv.ia (comm.1N$sitspe)) }) stopCluster (cl) agg.mean <- aggregate (unlist (lapply (res.beta, FUN = function (x) x[[1]])), by = combination[,-1], FUN = mean) agg.sd <- aggregate (unlist (lapply (res.beta, FUN = function (x) x[[1]])), by = combination[,-1], FUN = sd) agg.mean.1N <- aggregate (unlist (lapply (res.beta, FUN = function (x) x[[2]])), by = combination[,-1], FUN = mean) agg.sd.1N <- aggregate (unlist (lapply (res.beta, FUN = function (x) x[[2]])), by = combination[,-1], FUN = sd) write.table (file = 'agg.betadiv.ia.csv', cbind (agg.mean[,-5], beta.ia = paste (formatC(agg.mean$x, digits = 3, format = 'f'), 'plusminus', formatC(agg.sd$x, digits = 3, format = 'f'), sep = ''), beta.ia.1N = paste (formatC(agg.mean.1N$x, digits = 3, format = 'f'), 'plusminus', formatC(agg.sd.1N$x, digits = 3, format = 'f'), sep = '')), sep = ',', col.names = NA) ## 3a. Detail power analysis for weighted-mean approach (standard and modified test) and fourth-corner approach (sequential test) (scenario 1N, parallel version) ---- # mi.tol = 30, no.spec in seq 10, 100 by 10, no.samples in seq 10, 100, by 10 require (weimea) require (parallel) no.perm <- 1000 perm <- 999 cl <- makeCluster(8) combination <- expand.grid (perm = 1:no.perm, no.spec = seq (10, 100, by = 10), no.sites = seq (10, 100, by = 10), mi.tol = 30, scenario = 1) clusterExport (cl, list ('combination')) res.power <- parRapply (cl, combination, FUN = function (comb){ #comb[2] = no.spec, comb[3] = no.sites, comb[4] = mi.tol, comb[5] = scenario require (weimea) comm <- simul.RLQ (scenario = comb[5], mi.tol = comb[4], n = comb[3], p = comb[2], add.noise = TRUE) M <- wm (sitspe = comm$sitspe, speatt = comm$speatt) res.temp <- list () res.temp$out.modif <- test.MR (M = M, env = comm$env, method = 'cor', test = c('standard', 'modified'), perm = 999)$out res.temp$out.fc <- test.MR (M = M, env = comm$env, method = 'four', fc.test = 6, perm = 999)$out res.temp$par <- comb return (res.temp) }) stopCluster (cl) save (res.power, file = 'res.power.r') # 3b. Detail power analysis ---- # mi.tol in seq 10, 80 by = 10, no.spec and no.sample 30, 50 or 100 no.perm <- 1000 perm <- 999 cl <- makeCluster(8) combination <- expand.grid (perm = 1:no.perm, no.spec = c(30, 50, 100), no.sites = c(30, 50, 100), mi.tol = seq (10, 80, by = 10), scenario = 1) clusterExport (cl, list ('combination')) res.power.mi <- parRapply (cl, combination, FUN = function (comb){ #comb[2] = no.spec, comb[3] = no.sites, comb[4] = mi.tol, comb[5] = scenario require (weimea) comm <- simul.RLQ (scenario = comb[5], mi.tol = comb[4], n = comb[3], p = comb[2], add.noise = TRUE) M <- wm (sitspe = comm$sitspe, speatt = comm$speatt) res.temp <- list () res.temp$out.modif <- test.MR (M = M, env = comm$env, method = 'cor', test = c('standard', 'modified'), perm = 999)$out res.temp$out.fc <- test.MR (M = M, env = comm$env, method = 'four', fc.test = 6, perm = 999)$out res.temp$par <- comb return (res.temp) }) stopCluster (cl) save (res.power.mi, file = 'res.power.mi.r') ### 4. Drawing figures from summary analysis ---- library (lattice) load ('res.comb.df.r') # results calculated by weimea res.comb.df$scenario <- paste ('Scenario', res.comb.df$scenario, sep = ' ') ## Fig. 2: Relationship of Pearson's r correlation coefficient x betadiversity x scenario---- tiff (file = 'Fig2_Pearsons_r-beta-scenario.tif', width = 6, height = 3, units = 'in', res = 600, compression = 'lzw', type = 'cairo') t.value.min <- qt (.025, df = 48) t.value.max <- qt (.975, df = 48) t2r <- function (t, n) t/(sqrt (n-2+t^2)) h <- t2r (t.value.min, n = 50) trellis.par.set (list (box.rectangle = list (col = 'black'), box.umbrella = list (lty = 'solid', col = 'black'), box.dot = list (col = 2), plot.symbol = list (pch = '-', cex = 1.5, col = 'darkgrey'), add.line = list (col = 'grey'))) bwplot (cor.r.obs ~ no.comm | as.factor(scenario), data = res.comb.df, as.table = T, between = list (x = 1, y = 1), pch = '|', horiz = F, xlab = list ('Beta diversity', cex = 1), ylab = list (expression (paste ("Pearson's ", italic (r))), cex = 1), panel = function (...) {panel.bwplot (...); panel.abline (h = c(-h, +h), lty = 'dashed')}, scales = list (alternating = c(1,1), cex = 0.5), strip = strip.custom (style = 1, bg = 'grey90', par.strip.text = list (cex = 1)), par.strip.text = list (lines = 1.5), do.out = T, box.ratio = 0.75, layout = c(4,1)) dev.off () # Summary for the text: quantile (res.comb.df[res.comb.df$no.comm == 1&res.comb.df$scenario == 'Scenario 2', 'cor.r.obs'], probs = c(0.025, 0.975)) # Scenario 2, most homogeneous dataset (no.comm = 1), Pearson's r, quantiles sum (res.comb.df[res.comb.df$no.comm == 1&res.comb.df$scenario == 'Scenario 2', 'cor.P.par'] < 0.05)/1000 # 0.583 = 58% quantile (res.comb.df[res.comb.df$no.comm == 10&res.comb.df$scenario == 'Scenario 2', 'cor.r.obs'], probs = c(0.025, 0.975)) # Scenario 2, most heterogeneous dataset (no.comm = 1), Pearson's r, quantiles sum (res.comb.df[res.comb.df$no.comm == 10&res.comb.df$scenario == 'Scenario 2', 'cor.P.par'] < 0.05)/1000 # 0.167 = 17% quantile (res.comb.df[res.comb.df$no.comm == 1&(res.comb.df$scenario == 'Scenario 3'|res.comb.df$scenario == 'Scenario 4'), 'cor.r.obs'], probs = c(0.025, 0.975)) # Scenario 3-4, most heterogeneous dataset (no.comm = 1), Pearson's r, quantiles sum (res.comb.df[res.comb.df$no.comm == 1&(res.comb.df$scenario == 'Scenario 3'|res.comb.df$scenario == 'Scenario 4'), 'cor.P.par'] < 0.05)/2000 # 0.0565 = ~ 6% ## Fig. 3: The number of significant results of standard parametric test x betadiversity x scenario ---- agg.P.par <- aggregate (cor.P.par ~ no.comm + scenario, data = res.comb.df, FUN = function (x) sum ((x)<0.05)/1000) tiff (file = 'Fig3_cor_par_sign-beta-scenario.tif', width = 6, height = 3, units = 'in', res = 600, compression = 'lzw', type = 'cairo') trellis.par.set (list (box.rectangle = list (col = 'black'), box.umbrella = list (lty = 'solid', col = 'black'), box.dot = list (col = 2), add.line = list (col = 'grey'), plot.symbol = list (col= 'black'))) barchart (cor.P.par ~ no.comm | as.factor(scenario), data = agg.P.par, as.table = T, between = list (x = 1, y = 1), horiz = F, xlab = list ('Beta diversity', cex = 1), ylab = list (expression (paste ("Proportion of signif. correlations")), cex = 1), scales = list (alternating = c(1,1), cex = 0.5), strip = strip.custom (style = 1, bg = 'grey90', par.strip.text = list (cex = 1)), par.strip.text = list (lines = 1.5), box.ratio = 1, panel = function (...) {panel.barchart (..., col = 'grey50', border = 'grey20'); panel.abline (h = 0.05, lty = 'dashed', col = 'lightgrey')}, origin = 0, layout = c(4,1)) dev.off () ## Fig. 4: The number of significant results of modified permutation test + 4corner perm test (model 6) x betadiversity x scenario ---- agg.P.cor.mod <- aggregate (cbind (cor.P.mod) ~ no.comm + scenario, data = res.comb.df, FUN = function (x) sum ((x)<0.05)/1000) agg.P.fc <- aggregate (fc.P.6 ~ no.comm + scenario, data = res.comb.df, FUN = function (x) sum ((x)<0.05)/1000) agg.P.cor.mod.fc.2 <- cbind (agg.P.cor.mod, fc.P.6 = agg.P.fc[,3]) tiff (file = 'Fig4_mod.fc.P.beta-scenario.tif', width = 6, height = 3, units = 'in', res = 600, compression = 'lzw', type = 'cairo') trellis.par.set (list (box.rectangle = list (col = 'black'), box.umbrella = list (lty = 'solid', col = 'black'), box.dot = list (col = 2), add.line = list (col = 'grey'), plot.symbol = list (col= 'black'), superpose.polygon = list (col = c('white', 'darkgrey')))) barchart (cor.P.mod + fc.P.6 ~ no.comm | as.factor(scenario), data = agg.P.cor.mod.fc.2, as.table = T, between = list (x = 1, y = 1), horiz = F, xlab = list ('Beta diversity', cex = 1), ylab = list (expression (paste ("Proportion of signif. correlations")), cex = 1), scales = list (alternating = c(1,1), cex = 0.5), strip = strip.custom (style = 1, bg = 'grey90', par.strip.text = list (cex = 1)), par.strip.text = list (lines = 1.5), box.ratio = 2, panel = function (...) {panel.barchart (..., col = c('white', 'darkgrey')); panel.abline (h = 0.05, lty = 'dashed', col = 'lightgrey')}, origin = 0, layout = c(4,1), auto.key = list (column = 1, space = 'inside', x = 1, y = .8, corner = c(1,1), text = c('modif.', 'fourth.'), points = FALSE, rectangles = TRUE, cex = .7, between = 1.5)) dev.off () ## App S2, Fig S1: Relationship of R2 from lm regression x betadiversity x scenario---- tiff (file = 'AppS2-Figs1_Rsq_obs-beta-scenario.tif', width = 6, height = 3, units = 'in', res = 600, compression = 'lzw', type = 'cairo') trellis.par.set (list (box.rectangle = list (col = 'black'), box.umbrella = list (lty = 'solid', col = 'black'), box.dot = list (col = 2), plot.symbol = list (pch = '-', cex = 1.5, col = 'darkgrey'), add.line = list (col = 'grey'))) bwplot (lm.rsq.obs ~ no.comm | as.factor(scenario), data = res.comb.df, as.table = T, between = list (x = 1, y = 1), pch = '|', horiz = F, xlab = list ('Beta diversity', cex = 1), ylab = list (expression (paste ("Coefficient of determination (", italic (r)^2, ")")), cex = 1), scales = list (alternating = c(1,1), cex = 0.5), strip = strip.custom (style = 1, bg = 'grey90', par.strip.text = list (cex = 1)), par.strip.text = list (lines = 1.5), do.out = T, box.ratio = 0.75, layout = c(4,1)) dev.off () ## App S2, Fig S2: Relationship of fourth corner's r correlation coefficient x betadiversity x scenario---- tiff (file = 'AppS2_FigS2_fc_r-beta-scenario.tif', width = 6, height = 3, units = 'in', res = 600, compression = 'lzw', type = 'cairo') trellis.par.set (list (box.rectangle = list (col = 'black'), box.umbrella = list (lty = 'solid', col = 'black'), box.dot = list (col = 2), plot.symbol = list (pch = '-', cex = 1.5, col = 'darkgrey'), add.line = list (col = 'grey'))) bwplot (fourthcorner ~ no.comm | as.factor(scenario), data = res.comb.df, as.table = T, between = list (x = 1, y = 1), pch = '|', horiz = F, xlab = list ('Beta diversity', cex = 1), ylab = list (expression (paste ("Fourthcorner ", italic (r))), cex = 1), panel = function (...) panel.bwplot (...), scales = list (alternating = c(1,1), cex = 0.5), strip = strip.custom (style = 1, bg = 'grey90', par.strip.text = list (cex = 1)), par.strip.text = list (lines = 1.5), do.out = T, box.ratio = 0.75, layout = c(4,1)) dev.off () ## App S2, Fig S3: The number of significant results of the fourth-corner perm test (2,4,6) x betadiversity x scenario ---- agg.P.fc <- aggregate (cbind (fc.P.2, fc.P.4, fc.P.6) ~ no.comm + scenario, data = res.comb.df, FUN = function (x) sum ((x)<0.05)/1000) tiff (file = 'AppS2-FigS3_fc.P.beta-scenario.tif', width = 6, height = 3, units = 'in', res = 600, compression = 'lzw', type = 'cairo') trellis.par.set (list (box.rectangle = list (col = 'black'), box.umbrella = list (lty = 'solid', col = 'black'), box.dot = list (col = 2), add.line = list (col = 'grey'), plot.symbol = list (col= 'black'), superpose.polygon = list (col = c('black', 'darkgrey', 'lightgrey')))) barchart (fc.P.2 + fc.P.4 + fc.P.6 ~ no.comm | as.factor(scenario), data = agg.P.fc, as.table = T, between = list (x = 1, y = 1), horiz = F, xlab = list ('Beta diversity', cex = 1), ylab = list (expression (paste ("Proportion of signif. correlations")), cex = 1), scales = list (alternating = c(1,1), cex = .5), strip = strip.custom (style = 1, bg = 'grey90', par.strip.text = list (cex = 1)), par.strip.text = list (lines = 1), box.ratio = 2, panel = function (...) {panel.barchart (..., col = c('black', 'darkgrey', 'lightgrey')); panel.abline (h = 0.05, lty = 'dashed', col = 'lightgrey')}, origin = 0, auto.key = list (column = 1, space = 'inside', x = 1, y = .8, corner = c(1,1), text = c('model 2', 'model 4', 'sequential'), points = FALSE, rectangles = TRUE, cex = .6, between = .8), layout = c(4,1)) dev.off () ## App S3, Fig S1: Power analysis using Dray & Legendre (2012) model ---- load ('res.power.r') res.power.modif.df <- do.call (rbind, lapply (res.power, FUN = function (res) c(res$par, res$out.modif$`mi.n / x.n`$P.mod))) colnames (res.power.modif.df)[6] <- 'P.mod' no.perm <- 1000 res.power.modif.df.agg <- aggregate (P.mod ~ no.spec + no.sites, data = res.power.modif.df, FUN = function (x) sum (x < 0.05)/no.perm) res.power.fc.df <- do.call (rbind, lapply (res.power, FUN = function (res) c(res$par, P.fc6 = res$out.fc$P.value))) res.power.fc.df.agg <- aggregate (P.fc6 ~ no.spec + no.sites, data = res.power.fc.df, FUN = function (x) sum (x < 0.05)/no.perm) load ('res.power.mi.r') res.power.modif.mi.df <- do.call (rbind, lapply (res.power.mi, FUN = function (res) c(res$par, res$out.modif$`mi.n / x.n`$P.mod))) colnames (res.power.modif.mi.df)[6] <- 'P.mod' res.power.modif.mi.df.agg <- aggregate (P.mod ~ mi.tol + no.spec + no.sites, data = res.power.modif.mi.df, FUN = function (x) sum (x < 0.05)/no.perm) res.power.names <- factor (apply (res.power.modif.mi.df.agg[, c('no.spec', 'no.sites')], 1, paste, collapse = '+'), levels = c('30+30', '30+50', '30+100', '50+30', '50+50', '50+100', '100+30', '100+50', '100+100'), ordered = T) res.power.fc.mi.df <- do.call (rbind, lapply (res.power.mi, FUN = function (res) c(res$par, P.fc6 = res$out.fc$P.value))) res.power.fc.mi.df.agg <- aggregate (P.fc6 ~ mi.tol + no.spec + no.sites, data = res.power.fc.mi.df, FUN = function (x) sum (x < 0.05)/no.perm) tiff (filename = 'AppS3_FigS1_power.analysis.tif', width = 6, height = 6, units = 'in', res = 600, compression = 'lzw', pointsize = 8) par (mfrow = c (2,2)) contour (as.matrix (reshape (res.power.modif.df.agg[,c(1,2,3)], v.names = "P.mod", idvar = "no.spec", direction = 'wide', timevar = 'no.sites')[,-1]), ylab = list ('Number of samples', cex = 1.5), xlab = list ('Number of species', cex = 1.5), main = list ('Modified permutation test', cex = 1.5), axes = F, labcex = 1, lwd= 0.5) axis (1, at = seq (0.05, .95, by = 0.1), label = seq (10, 100, by = 10)) axis (2, at = seq (0.05, .95, by = 0.1), label = seq (10, 100, by = 10), las = 2) box () title (main = '(a)', cex.main = 1.5, adj = 0, font = 2) matplot (y = matrix (res.power.modif.mi.df.agg$P.mod, nrow = 8, dimnames = list(NULL,levels (res.power.names))), x = seq (10, 80, by = 10), type = 'b', pch = c(16,16,16,1,1,1,15,15,15), lty = rep (c('solid', 'dotted', 'dashed'), 3), col = 'black', las = 1, xlab = list ('Average species tolerance', cex = 1.5), ylab = list ('Power', cex = 1.5), main = list ('Modified permutation test', cex = 1.5), ylim = c(0,1)) legend (x = 10, y = 0.3, legend = c(30, 50, 100), title = 'No. species', pch = c(16, 1, 15), bty = 'n') legend (x = 30, y = 0.3, legend = c(30, 50, 100), title = 'No. samples', lty = c('solid', 'dotted', 'dashed'), bty = 'n') title (main = '(b)', cex.main = 1.5, adj = 0, font = 2) contour (as.matrix (reshape (res.power.fc.df.agg[,c(1,2,3)], v.names = "P.fc6", idvar = "no.spec", direction = 'wide', timevar = 'no.sites')[,-1]), ylab = list ('Number of samples', cex = 1.5), xlab = list ('Number of species', cex = 1.5), main = list ('Sequential test based on f-c', cex = 1.5), axes = F, labcex = 1, lwd= 0.5) axis (1, at = seq (0.05, .95, by = 0.1), label = seq (10, 100, by = 10)) axis (2, at = seq (0.05, .95, by = 0.1), label = seq (10, 100, by = 10), las = 2) box () title (main = '(c)', cex.main = 1.5, adj = 0, font = 2) matplot (y = matrix (res.power.fc.mi.df.agg$P.fc6, nrow = 8, dimnames = list(NULL,levels (res.power.names))), x = seq (10, 80, by = 10), type = 'b', pch = c(16,16,16,1,1,1,15,15,15), lty = rep (c('solid', 'dotted', 'dashed'), 3), col = 'black', las = 1, xlab = list ('Average species tolerance', cex = 1.5), ylab = list ('Power', cex = 1.5), main = list ('Sequential test based on f-c', cex = 1.5), ylim = c(0,1)) legend (x = 10, y = 0.3, legend = c(30, 50, 100), title = 'No. species', pch = c(16, 1, 15), bty = 'n') legend (x = 30, y = 0.3, legend = c(30, 50, 100), title = 'No. samples', lty = c('solid', 'dotted', 'dashed'), bty = 'n') title (main = '(d)', cex.main = 1.5, adj = 0, font = 2) dev.off () ## App S3, Fig S2: Comparison of barplots for weighted-mean approach (standard+modified+two-step test) and fourth-corner approach (2, 4, and sequential) ---- load (file = 'res.dray.df.agg.r') w.mean <- matrix (as.numeric (res.dray.df.agg[18,4:11]), nrow = 2, byrow = T, dimnames = list (c('P.sta', 'P.mod'), c('scenario.1', 'scenario.2', 'scenario.3', 'scenario.4'))) # f.corner <- read.delim ('clipboard', row.names = 1) # dput (f.corner) f.corner <- structure(list(scenario.1 = c(1L, 1L, 1L), scenario.2 = c(0.937, 0.05, 0.05), scenario.3 = c(0.047, 0.931, 0.047), scenario.4 = c(0.059, 0.052, 0.004)), .Names = c("scenario.1", "scenario.2", "scenario.3", "scenario.4"), class = "data.frame", row.names = c("P.2", "P.4", "P.6")) # then draw the figure: tiff (filename = 'AppS3-FigS2_comparison-tests-weimea-fourcorner.tif', width = 6, height = 3, units = 'in', res = 600, compression = 'lzw', type = 'cairo', pointsize = 7) par (mfrow = c(1,2), mar = c(4.1, 5.1, 4.1, 2.1)) barplot (w.mean, beside = T, main = list ('(a) Weighted-mean approach', cex = 1.5), las = 1, xlab = list ('Scenario', cex = 1.5), ylab = list (expression (paste ('Proportion of signif. results')), cex = 1.5), names.arg = 1:4, cex.axis = 1.2, cex.names = 1.2) #title (main = '(a)', adj = 0, cex = 1.5) abline (h = 0.05, col = 'darkgrey', lty = 'dashed') legend ('topright', legend = c('standard', 'modified'), pch = 22, pt.bg = grey.colors (2), col = 'black', pt.cex = 2, bty = 'n') barplot (as.matrix (f.corner), beside = T, main = list ('(b) Fourth-corner approach', cex = 1.5), las = 1, xlab = list ('Scenario', cex = 1.5), ylab = list (expression (paste ('Proportion of signif. results')), cex = 1.5), names.arg = 1:4, cex.axis = 1.2, cex.names = 1.2) #title (main = '(b)', adj = 0, cex = 1.5) abline (h = 0.05, col = 'darkgrey', lty = 'dashed') legend ('topright', legend = c('model 2', 'model 4', 'sequential'), pch = 22, pt.bg = grey.colors (3), col = 'black', pt.cex = 2, bty = 'n') dev.off ()