R Under development (unstable) (2023-08-20 r84995 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(Rarity) > data(spid.occ) > > # Preparation of rarity weights > rarity.weights <- rWeights(spid.occ, extended = TRUE) Rarity cut-off points: occurMA 0.0357142857142857 / 2 occurWP 0.339285714285714 / 19 > > # Generation of an assemblage matrix > assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 50, replace = TRUE), + assemblage.2 = sample(c(0, 1), 50, replace = TRUE), + assemblage.3 = sample(c(0, 1), 50, replace = TRUE), + assemblage.4 = sample(c(0, 1), 50, replace = TRUE), + assemblage.5 = sample(c(0, 1), 50, replace = TRUE)) > # Random attribution of names to the sampled species > rownames(assemblages.matrix) <- sample(rownames(spid.occ), 50, replace = FALSE) > > > # Test 1: A vector - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Isr(W = curW, assemblages = curA) > result Isr Richness 8.546 25.000 > tot.res <- result[1] > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > # Testing NAs > curW[2] <- NA > result <- Isr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Isr Richness 8.546 25.000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 2: A vector - W matrix > curW <- as.matrix(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Isr(W = curW, assemblages = curA) > result Isr_W1 Isr_W2 Isr_W Richness 6.204 2.342 8.546 25.000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > tot.res <- c(tot.res, + result["Isr_W"]) > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Isr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Isr_W1 Isr_W2 Isr_W Richness 6.204 2.342 8.546 25.000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 3: A matrix - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix > > result <- Isr(W = curW, assemblages = curA) > result IsrValue Richness assemblage.1 8.546 25 assemblage.2 8.332 23 assemblage.3 8.334 27 assemblage.4 5.026 26 assemblage.5 6.565 24 > tot.res <- c(tot.res, + result[1, 1]) > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[2] <- NA > result <- Isr(W = curW, assemblages = curA) W contains NA values, they will be removed > result IsrValue Richness assemblage.1 8.546 25 assemblage.2 8.332 23 assemblage.3 8.334 27 assemblage.4 5.026 26 assemblage.5 6.565 24 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Test 4: A matrix - W matrix > curW <- rarity.weights > curA <- assemblages.matrix > > result <- Isr(W = curW, assemblages = curA) > result Isr_W1 Isr_W2 Isr_W Richness assemblage.1 6.204 2.342 8.546 25 assemblage.2 5.102 3.230 8.332 23 assemblage.3 5.102 3.231 8.334 27 assemblage.4 2.102 2.924 5.026 26 assemblage.5 5.051 1.513 6.565 24 > tot.res <- c(tot.res, + result[1, 3]) > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Isr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Isr_W1 Isr_W2 Isr_W Richness assemblage.1 6.204 2.342 8.546 25 assemblage.2 5.102 3.230 8.332 23 assemblage.3 5.102 3.231 8.334 27 assemblage.4 2.102 2.924 5.026 26 assemblage.5 5.051 1.513 6.565 24 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > tot.res Isr Isr_W 8.546 8.546 8.546 8.546 > > > > > #### TEST WITH ABUNDANCES #### > > # Generation of an assemblage matrix > assemblages.matrix <- cbind(assemblage.1 = sample(0:25, 50, replace = TRUE), + assemblage.2 = sample(0:25, 50, replace = TRUE), + assemblage.3 = sample(0:25, 50, replace = TRUE), + assemblage.4 = sample(0:25, 50, replace = TRUE), + assemblage.5 = sample(0:25, 50, replace = TRUE)) > # Random attribution of names to the sampled species > rownames(assemblages.matrix) <- sample(rownames(spid.occ), 50, replace = FALSE) > > > # Test 1: A vector - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Isr(W = curW, assemblages = curA, abundance = TRUE) > result Isr Richness 239.887 48.000 > tot.res <- result[1] > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > # Testing NAs > curW[2] <- NA > result <- Isr(W = curW, assemblages = curA, abundance = TRUE) W contains NA values, they will be removed > result Isr Richness 239.887 48.000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 2: A vector - W matrix > curW <- as.matrix(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Isr(W = curW, assemblages = curA, abundance = TRUE) > result Isr_W1 Isr_W2 Isr_W Richness 173.142 66.753 239.887 48.000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > tot.res <- c(tot.res, + result["Isr_W"]) > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Isr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Isr_W1 Isr_W2 Isr_W Richness 10.204 5.501 15.705 48.000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 3: A matrix - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix > > result <- Isr(W = curW, assemblages = curA, abundance = TRUE) > result IsrValue Richness assemblage.1 239.887 48 assemblage.2 178.524 46 assemblage.3 186.354 48 assemblage.4 147.430 48 assemblage.5 256.242 49 > tot.res <- c(tot.res, + result[1, 1]) > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[2] <- NA > result <- Isr(W = curW, assemblages = curA, abundance = TRUE) W contains NA values, they will be removed > result IsrValue Richness assemblage.1 239.887 48 assemblage.2 178.524 46 assemblage.3 186.354 48 assemblage.4 147.430 48 assemblage.5 256.242 49 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Test 4: A matrix - W matrix > curW <- rarity.weights > curA <- assemblages.matrix > > result <- Isr(W = curW, assemblages = curA, abundance = TRUE) > result Isr_W1 Isr_W2 Isr_W Richness assemblage.1 173.142 66.753 239.887 48 assemblage.2 114.969 63.543 178.524 46 assemblage.3 122.111 64.247 186.354 48 assemblage.4 103.417 44.034 147.430 48 assemblage.5 178.366 77.886 256.242 49 > tot.res <- c(tot.res, + result[1, 3]) > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Isr(W = curW, assemblages = curA, abundance = TRUE) W contains NA values, they will be removed > result Isr_W1 Isr_W2 Isr_W Richness assemblage.1 173.142 66.753 239.887 48 assemblage.2 114.969 63.543 178.524 46 assemblage.3 122.111 64.247 186.354 48 assemblage.4 103.417 44.034 147.430 48 assemblage.5 178.366 77.886 256.242 49 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > tot.res Isr Isr_W 239.887 239.887 239.887 239.887 > > > > #### TEST WITH NORMALISATION #### > > # Generation of an assemblage matrix > assemblages.matrix <- cbind(assemblage.1 = sample(0:25, 50, replace = TRUE), + assemblage.2 = sample(0:25, 50, replace = TRUE), + assemblage.3 = sample(0:25, 50, replace = TRUE), + assemblage.4 = sample(0:25, 50, replace = TRUE), + assemblage.5 = sample(0:25, 50, replace = TRUE)) > # Random attribution of names to the sampled species > rownames(assemblages.matrix) <- sample(rownames(spid.occ), 50, replace = FALSE) > > > # Test 1: A vector - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) > result Isr Richness 0.04610022 45.00000000 > tot.res <- result[1] > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > # Testing NAs > curW[2] <- NA > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) W contains NA values, they will be removed > result Isr Richness 0.04611474 45.00000000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 2: A vector - W matrix > curW <- as.matrix(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) > result Isr_W1 Isr_W2 Isr_W Richness 0.04166667 0.05514493 0.04610022 45.00000000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > tot.res <- c(tot.res, + result["Isr_W"]) > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) W contains NA values, they will be removed > result Isr_W1 Isr_W2 Isr_W Richness 0.04166667 0.05514493 0.04610022 45.00000000 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 3: A matrix - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix > > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) > result IsrValue Richness assemblage.1 0.04610022 45 assemblage.2 0.05987055 47 assemblage.3 0.06070133 48 assemblage.4 0.05819270 47 assemblage.5 0.06588150 48 > tot.res <- c(tot.res, + result[1, 1]) > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[2] <- NA > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) W contains NA values, they will be removed > result IsrValue Richness assemblage.1 0.04611474 45 assemblage.2 0.05988941 47 assemblage.3 0.06072045 48 assemblage.4 0.05821103 47 assemblage.5 0.06590225 48 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Test 4: A matrix - W matrix > curW <- rarity.weights > curA <- assemblages.matrix > > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) > result Isr_W1 Isr_W2 Isr_W Richness assemblage.1 0.04166667 0.05514493 0.04610022 45 assemblage.2 0.05783848 0.06400780 0.05987055 47 assemblage.3 0.05825086 0.06569440 0.06070133 48 assemblage.4 0.05825086 0.05805513 0.05819270 47 assemblage.5 0.06633676 0.06493378 0.06588150 48 > tot.res <- c(tot.res, + result[1, 3]) > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Isr(W = curW, assemblages = curA, normalise = TRUE) W contains NA values, they will be removed > result Isr_W1 Isr_W2 Isr_W Richness assemblage.1 0.04166667 0.05514493 0.04610022 45 assemblage.2 0.05783848 0.06400780 0.05987055 47 assemblage.3 0.05825086 0.06569440 0.06070133 48 assemblage.4 0.05825086 0.05805513 0.05819270 47 assemblage.5 0.06633676 0.06493378 0.06588150 48 > if(any(is.na(result)) | any(result[grep("Isr", names(result))] < 0)) + { + stop("Error in the test") + } > > > if(any(diff(tot.res)) > 0) + { + stop("Different values found for the same indices") + } Warning message: In any(diff(tot.res)) : coercing argument of type 'double' to logical > > proc.time() user system elapsed 0.34 0.14 0.46