library(microbenchmark)
install.packages('microbenchmark')
library(microbenchmark)
library(adespatial)  # Assuming this is the package with beta.div.comp
library(readr)  # For reading CSV files
df <- read_csv("~/.julia/dev/MetaCommunityMetrics/data/metacomm_rodent_df.csv")
library(data.table)  # For reading CSV files
df <- read.csv("~/.julia/dev/MetaCommunityMetrics/data/metacomm_rodent_df.csv")
df
library(dplyr)
df %>%
filter(Sampling_date_order == 50)
df %>%
filter(Sampling_date_order == 50)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence)
library(tidyverse)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude))
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
as.matrix()
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
as.matrix()%>%
filter(rowSums(.) == 0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
as.matrix()%>%
filter(rowSums(.) = 0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
as.matrix()%>%
filter(rowSums(.) == 0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
filter(rowSums(.) == 0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
filter(rowSums(.) !== 0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
filter(rowSums(.) != 0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
filter(colSums(.) !=0) %>%
filter(rowSums(.) != 0)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
select(which(colSums(.) !=0)
)
df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
select(which(colSums(.) !=0)) %>%
filter(rowSums(.) != 0)
test_data <- matrix(sample(c(0, 1, 2, 3), 80, replace = TRUE), nrow = 10, ncol = 8)
# Manually set some rows and columns to have a sum of zero
test_data[3, ] <- 0   # Set all abundances in row 3 to 0
test_data[ , 5] <- 0
test_data
test_data%>%
select(which(colSums(.) !=0)) %>%
filter(rowSums(.) != 0)
test_df <- as.data.frame(test_data)
test_df
test_df %>%
select(which(colSums(.) !=0))
test_df %>%
select(which(colSums(.) !=0)) %>%  filter(rowSums(.) != 0)
matrix_with_presence <- df %>%
filter(Sampling_date_order == 50) %>%
select(-Abundance) %>%
pivot_wider(names_from = Species, values_from = Presence, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
select(which(colSums(.) !=0)) %>%
filter(rowSums(.) != 0)
matrix_with_presence
?beta.div.comp
?microbenchmark
install.packages(bench)
install.packages("bench")
library(bench)
?mark
?beta.div.comp
mark(beta.div.comp(sample_matrix_abundance, coef = "J", quant =true),
iterations = 10000,
check = TRUE,
time_unit = "us")
mark(beta.div.comp(matrix_with_abundance, coef = "J", quant =true),
iterations = 10000,
check = TRUE,
time_unit = "us")
matrix_with_abundance <- df %>%
filter(Sampling_date_order == 50) %>%
select(-Presence) %>%
pivot_wider(names_from = Species, values_from = Abundance, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
select(which(colSums(.) !=0)) %>%
filter(rowSums(.) != 0)
### The binary matrix
matrix_with_presence <- df %>%
filter(Sampling_date_order == 50) %>%
select(-Abundance) %>%
pivot_wider(names_from = Species, values_from = Presence, values_fill=0) %>%
select(-c(Year, Month, Day, Sampling_date_order, plot, Longitude, Latitude)) %>%
select(which(colSums(.) !=0)) %>%
filter(rowSums(.) != 0)
mark(beta.div.comp(matrix_with_abundance, coef = "J", quant =true),
iterations = 10000,
check = TRUE,
time_unit = "us")
mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE),
iterations = 10000,
check = TRUE,
time_unit = "us")
mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE),
iterations = 10,
check = TRUE,
time_unit = "us")
mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE),
iterations = 10000,
check = TRUE,
time_unit = "us")
result<-mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE),
iterations = 10000,
check = TRUE,
time_unit = "us")
beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE)
result
result$median
result$time
View(result$time)
View(result$time[[1]])
result$time[[1]]
mean(result$time)
mean(result$time[[1]])
result<-mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE),
beta.div.comp(matrix_with_abundance, coef = "J", quant = FALSE)
beta.div.comp(matrix_with_presence, coef = "J", quant = FALSE)
result<-mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE),
beta.div.comp(matrix_with_abundance, coef = "J", quant = FALSE),
beta.div.comp(matrix_with_presence, coef = "J", quant = FALSE),
iterations = 10000,
check = TRUE,
time_unit = "us")
dat <- data.frame(x = runif(100, 1, 1000), y=runif(10, 1, 1000))
dat
dat[dat$x > 500, ]
dat[which(dat$x > 500), ]
subset(dat, x > 500)
beta_diversity_1 <- mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = TRUE),
iterations = 10000,
check = TRUE,
time_unit = "us")
beta_diversity_1
mean(beta_diversity_1$time[[1]])
mean(beta_diversity_1$time[[1]])*1000
mean(beta_diversity_1$time[[1]])/1000
str(mean(beta_diversity_1$time[[1]]))
mean(beta_diversity_1$time[[1]])*1000
as.numeric(beta_diversity_1$time[[1]])
beta_diversity_1$time[[1]]
as.numeric(beta_diversity_1$time[[1]])
mean(as.numeric(beta_diversity_1$time[[1]]))*1e+6
beta_diversity_1
beta_diversity_1_mean_time_<-mean(as.numeric(beta_diversity_1$time[[1]]))*1e+6
beta_diversity_1_mean_time<-mean(as.numeric(beta_diversity_1$time[[1]]))*1e+6
beta_diversity_1_mean_time
beta_diversity_1
beta_diversity_1$memory
beta_diversity_1$mem_alloc
as.numeric(beta_diversity_1$mem_alloc)
beta_diversity_1_mean_time_us<-mean(as.numeric(beta_diversity_1$time[[1]]))*1e+6
beta_diversity_1_mem_kib<-as.numeric(beta_diversity_1$mem_alloc)/1024
beta_diversity_1_mem_kib
beta_diversity_1
as.numeric(beta_diversity_1$mem_alloc)
beta_diversity_1_mem_kib<-as.numeric(beta_diversity_1$mem_alloc)
beta_diversity_1$mem_alloc
as.numeric(beta_diversity_1$mem_alloc)
beta_diversity_1$time[[1]])
beta_diversity_1$time[[1]]
as.numeric(beta_diversity_1$time[[1]])
as.numeric(beta_diversity_1$mem_alloc)
beta_diversity_1$mem_alloc
as.numeric(beta_diversity_1$mem_alloc)/1024
beta_diversity_1_mean_time_us
beta_diversity_1$time[[1]]
mean(beta_diversity_1$time[[1]])
as.numeric(mean(beta_diversity_1$time[[1]]))
beta_diversity_1_mean_time_us<-as.numeric(mean(beta_diversity_1$time[[1]]))*1e+6
beta_diversity_1_mean_time_us
print(as.numeric(mean(beta_diversity_1$time[[1]]))*1e+6, as.numeric(beta_diversity_1$mem_alloc)/1024)
print(as.numeric(mean(beta_diversity_1$time[[1]]))*1e+6, (as.numeric(beta_diversity_1$mem_alloc)/1024))
print((as.numeric(mean(beta_diversity_1$time[[1]]))*1e+6), (as.numeric(beta_diversity_1$mem_alloc)/1024))
execution_time_microseconds <- as.numeric(mean(beta_diversity_1$time[[1]])) * 1e+6
memory_usage_kib <- as.numeric(beta_diversity_1$mem_alloc) / 1024
# Print the results
cat("Execution Time (Microseconds):", execution_time_microseconds, "\n")
cat("Memory Usage (KiB):", memory_usage_kib, "\n")
beta_diversity_2 <- mark(beta.div.comp(matrix_with_abundance, coef = "J", quant = FALSE),
iterations = 10000,
check = TRUE,
time_unit = "us")
beta_diversity_2
execution_time_microseconds <- as.numeric(mean(beta_diversity_2$time[[1]])) * 1e+6
memory_usage_kib <- as.numeric(beta_diversity_2$mem_alloc) / 1024
# Print the results
cat("Execution Time (Microseconds):", execution_time_microseconds, "\n")
cat("Memory Usage (KiB):", memory_usage_kib, "\n")
beta_diversity_3 <- mark(beta.div.comp(matrix_with_presence, coef = "J", quant = FALSE),
iterations = 10000,
check = TRUE,
time_unit = "us")
execution_time_microseconds <- as.numeric(mean(beta_diversity_3$time[[1]])) * 1e+6
memory_usage_kib <- as.numeric(beta_diversity_3$mem_alloc) / 1024
cat("Execution Time (Microseconds):", execution_time_microseconds, "\n")
cat("Memory Usage (KiB):", memory_usage_kib, "\n")
beta_diversity_3
beta_diversity_2
beta_diversity_1
df
beta.div.comp(matrix_with_presence, coef = "J", quant = FALSE)
mean_spatial_beta_div_comp <-()
mean_spatial_beta_div_comp <-[]
mean_spatial_beta_div_comp <-list()
mean_spatial_beta_div_comp
spatial_beta_div_comp <-list()
df$Sampling_date_order
time=1
df %>%
filter(Sampling_date_order == time)
mean(beta_diversity_3$time[[1]])
mean(beta_diversity_2$time[[1]])
mean(beta_diversity_1$time[[1]])
beta_diversity_2$mem_alloc
execution_time_microseconds <- mean(beta_diversity_2$time[[1]])
memory_usage_kib <- as.numeric(beta_diversity_2$mem_alloc) / 1024
# Print the results
cat("Execution Time (Microseconds):", execution_time_microseconds, "\n")
cat("Memory Usage (KiB):", memory_usage_kib, "\n")
execution_time_microseconds <- mean(beta_diversity_2$time[[1]])
execution_time_microseconds
execution_time_microseconds <- mean(beta_diversity_2$time[[1]])) * 1e+6
execution_time_microseconds <- mean(beta_diversity_2$time[[1]])) * 1e+6
execution_time_microseconds <- mean(beta_diversity_2$time[[1]])* 1e+6
memory_usage_kib <- as.numeric(beta_diversity_2$mem_alloc) / 1024
# Print the results
cat("Execution Time (Microseconds):", execution_time_microseconds, "\n")
cat("Memory Usage (KiB):", memory_usage_kib, "\n")
