Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ codemeta.json
^README_files$
^LICENSE\.md$
^examples$
^\.claude$
^\.github$
^doc$
^Meta$
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Rproj.user
.Rproj.user
.Rhistory
README.html
.claude/settings.local.json


# C++
.o
Expand All @@ -21,4 +24,3 @@ revdep/

# Mac
.DS_Store
README.html
3 changes: 0 additions & 3 deletions CRAN-SUBMISSION

This file was deleted.

12 changes: 7 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Package: mobsim
Type: Package
Title: Spatial Simulation and Scale-Dependent Analysis of Biodiversity Changes
Version: 0.3.2
Version: 0.3.3
Authors@R: c(
person("Felix", "May", email = "felix.may@fu-berlin.de",
role = c("aut", "cre","cph"),
comment = c(ORCID = "0000-0002-1106-8188")),
person("Alban", "Sagouis", email = "alban.sagouis@idiv.de",
role = "aut",
comment = c(ORCID = "0000-0002-3827-1063")),
person("German Centre for Integrative Biodiversity Research (iDiv) Halle-Jena-Leipzig",
person("German Centre for Integrative Biodiversity Research Halle-Jena-Leipzig",
role = "fnd", comment = c(ROR = "01jty7g66")),
person("Freie Universität Berlin",
role = "fnd", comment = c(ROR = "046ak2485"))
Expand All @@ -24,7 +24,7 @@ Description: Simulation, analysis and sampling of spatial
decay of similarity.
License: GPL (>= 3)
Depends:
R (>= 4.0.0)
R (>= 4.1.0)
Imports:
Rcpp,
vegan,
Expand All @@ -33,20 +33,22 @@ Imports:
utils,
graphics,
stats,
spatstat.geom,
spatstat.explore,
methods
Suggests:
quarto,
spatstat.geom,
spatstat.random,
testthat (>= 3.0.0),
mockery,
vctrs
LinkingTo: Rcpp
Config/testthat/edition: 3
Config/testthat/parallel: false
Config/testthat/start-first: *utils*, *create_motherpoints*, *simulation*, *sampling*
VignetteBuilder: quarto
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Language: en-GB
Encoding: UTF-8
URL: https://github.com/MoBiodiv/mobsim
Expand Down
19 changes: 19 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@
S3method(plot,community)
S3method(plot,dist_decay)
S3method(plot,divar)
S3method(plot,mother_map)
S3method(plot,sad)
S3method(plot,spec_sample_curve)
S3method(summary,community)
S3method(summary,sad)
S3method(torusify,community)
S3method(torusify,data.frame)
S3method(torusify,mother_map)
S3method(torusify,numeric)
export(abund_rect)
export(community)
export(community2ppp)
export(community_to_sad)
export(create_motherpoints)
export(create_random_ID)
export(dist_decay)
export(dist_decay_quadrats)
export(div_rand_rect)
export(div_rect)
export(divar)
export(drift_x_motherpoints)
export(drift_x_species)
export(drift_y_motherpoints)
export(drift_y_species)
export(jitter_motherpoints)
export(jitter_species)
export(rThomas_rcpp)
export(rare_curve)
export(replace_individuals)
export(sample_quadrats)
export(sampling_grids)
export(sampling_one_quadrat)
Expand All @@ -31,7 +46,11 @@ export(sim_thomas_community)
export(sim_thomas_coords)
export(spec_sample)
export(spec_sample_curve)
export(torusify)
importFrom(Rcpp,sourceCpp)
importFrom(methods,is)
importFrom(sads,rsad)
importFrom(spatstat.explore,marktable)
importFrom(spatstat.geom,owin)
importFrom(spatstat.geom,ppp)
useDynLib(mobsim, .registration = TRUE)
54 changes: 27 additions & 27 deletions R/Diversity_Area_Relationships.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ div_rand_rect <- function(
n_rect = 100,
exclude_zeros = FALSE
) {
dx_plot <- comm$x_min_max[2] - comm$x_min_max[1]
dy_plot <- comm$y_min_max[2] - comm$y_min_max[1]
dx_plot <- comm$x_min_max[[2]] - comm$x_min_max[[1]]
dy_plot <- comm$y_min_max[[2]] - comm$y_min_max[[1]]

area <- dx_plot * dy_plot * prop_area
square_size <- sqrt(area)
Expand All @@ -139,13 +139,13 @@ div_rand_rect <- function(

xpos <- stats::runif(
n_rect,
min = comm$x_min_max[1],
max = comm$x_min_max[2] - dx_rect
min = comm$x_min_max[[1]],
max = comm$x_min_max[[2]] - dx_rect
)
ypos <- stats::runif(
n_rect,
min = comm$y_min_max[1],
max = comm$y_min_max[2] - dy_rect
min = comm$y_min_max[[1]],
max = comm$y_min_max[[2]] - dy_rect
)

div_plots <- mapply(
Expand All @@ -154,7 +154,7 @@ div_rand_rect <- function(
ypos,
MoreArgs = list(xsize = dx_rect, ysize = dy_rect, comm = comm)
)
if (exclude_zeros == TRUE)
if (isTRUE(exclude_zeros))
div_plots <- div_plots[, div_plots["n_species", ] > 0]

return(c(
Expand Down Expand Up @@ -220,8 +220,8 @@ divar <- function(
stop("DiVAR requires a community object as input. See ?community.")

n_scales <- length(prop_area)
dx_plot <- comm$x_min_max[2] - comm$x_min_max[1]
dy_plot <- comm$y_min_max[2] - comm$y_min_max[1]
dx_plot <- comm$x_min_max[[2]] - comm$x_min_max[[1]]
dy_plot <- comm$y_min_max[[2]] - comm$y_min_max[[1]]

div_area <- sapply(
prop_area,
Expand Down Expand Up @@ -314,11 +314,11 @@ abund_rect <- function(x0, y0, xsize, ysize, comm) {
x <- comm$census$x
y <- comm$census$y

# logical vector which trees are in the sampling rectangle
in_rect <- (x >= x0 & x < (x0 + xsize) & y >= y0 & y < (y0 + ysize))
# logical vector which trees are in the sampling rectangle
in_rect <- (x >= x0 & x < (x0 + xsize) & y >= y0 & y < (y0 + ysize))

abund <- table(comm$census$species[in_rect])
return(abund)
abund <- table(comm$census$species[in_rect])
return(abund)
}

#' Distance decay of similarity
Expand All @@ -345,6 +345,7 @@ abund_rect <- function(x0, y0, xsize, ysize, comm) {
#'@export
#'
dist_decay <- function(
comm,
prop_area = 0.005,
n_samples = 20,
method = "bray",
Expand All @@ -354,12 +355,12 @@ dist_decay <- function(

if (length(prop_area) != 1L) stop("prop_area has to be of length 1")

if (!is(comm, "community"))
stop("dist_decay requires a community object as input. See ?community.")
if (!is(comm, "community"))
stop("dist_decay requires a community object as input. See ?community.")

dx_plot <- comm$x_min_max[2] - comm$x_min_max[1]
dy_plot <- comm$y_min_max[2] - comm$y_min_max[1]
area <- dx_plot * dy_plot * prop_area
dx_plot <- comm$x_min_max[[2]] - comm$x_min_max[[1]]
dy_plot <- comm$y_min_max[[2]] - comm$y_min_max[[1]]
area <- dx_plot * dy_plot * prop_area

samples1 <- sample_quadrats(
comm,
Expand All @@ -379,12 +380,12 @@ dist_decay <- function(
similarity = as.numeric(similarity)
)

# order by increasing distance
dat_out <- dat_out[order(dat_out$distance), ]
# order by increasing distance
dat_out <- dat_out[order(dat_out$distance), ]

class(dat_out) <- c("dist_decay", "data.frame")
class(dat_out) <- c("dist_decay", "data.frame")

return(dat_out)
return(dat_out)
}

#' Distance decay of similarity with user-defined quadrats
Expand Down Expand Up @@ -424,12 +425,12 @@ dist_decay_quadrats <- function(samples, method = "bray", binary = FALSE) {
similarity = as.numeric(similarity)
)

# order by increasing distance
dat_out <- dat_out[order(dat_out$distance), ]
# order by increasing distance
dat_out <- dat_out[order(dat_out$distance), ]

class(dat_out) <- c("dist_decay", "data.frame")
class(dat_out) <- c("dist_decay", "data.frame")

return(dat_out)
return(dat_out)
}


Expand Down Expand Up @@ -503,4 +504,3 @@ plot.dist_decay <- function(x, ...) {
#
# return(abund.plots[,1])
# }
#
68 changes: 34 additions & 34 deletions R/Sample_quadrats.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ sample_quadrats <- function(

quadrat_size <- sqrt(quadrat_area)

community_size <- (comm$x_min_max[2] - comm$x_min_max[1]) *
(comm$y_min_max[2] - comm$y_min_max[1])
community_size <- (comm$x_min_max[[2]] - comm$x_min_max[[1]]) *
(comm$y_min_max[[2]] - comm$y_min_max[[1]])

if (quadrat_size < community_size) {
# This works as long as we use square quadrats

if (n_quadrats == 1L) {
xy_dat <- sampling_one_quadrat(
xmin = comm$x_min_max[1],
xmax = comm$x_min_max[2] - quadrat_size,
ymin = comm$y_min_max[1],
ymax = comm$y_min_max[2] - quadrat_size,
xmin = comm$x_min_max[[1]],
xmax = comm$x_min_max[[2]] - quadrat_size,
ymin = comm$y_min_max[[1]],
ymax = comm$y_min_max[[2]] - quadrat_size,
seed = seed
)
} else {
Expand All @@ -80,20 +80,20 @@ sample_quadrats <- function(
xy_dat <- sampling_random_spatstat(
n_quadrats = n_quadrats,
min_dist = min_dist,
xmin = comm$x_min_max[1],
xmax = comm$x_min_max[2] - quadrat_size,
ymin = comm$y_min_max[1],
ymax = comm$y_min_max[2] - quadrat_size,
xmin = comm$x_min_max[[1]],
xmax = comm$x_min_max[[2]] - quadrat_size,
ymin = comm$y_min_max[[1]],
ymax = comm$y_min_max[[2]] - quadrat_size,
seed = seed
)
} else {
xy_dat <- sampling_random_bruteforce(
n_quadrats = n_quadrats,
min_dist = min_dist,
xmin = comm$x_min_max[1],
xmax = comm$x_min_max[2] - quadrat_size,
ymin = comm$y_min_max[1],
ymax = comm$y_min_max[2] - quadrat_size,
xmin = comm$x_min_max[[1]],
xmax = comm$x_min_max[[2]] - quadrat_size,
ymin = comm$y_min_max[[1]],
ymax = comm$y_min_max[[2]] - quadrat_size,
seed = seed
)
} # end of no spatstat
Expand All @@ -102,10 +102,10 @@ sample_quadrats <- function(
xy_dat <- sampling_random_overlap(
n_quadrats = n_quadrats,
min_dist = min_dist,
xmin = comm$x_min_max[1],
xmax = comm$x_min_max[2] - quadrat_size,
ymin = comm$y_min_max[1],
ymax = comm$y_min_max[2] - quadrat_size,
xmin = comm$x_min_max[[1]],
xmax = comm$x_min_max[[2]] - quadrat_size,
ymin = comm$y_min_max[[1]],
ymax = comm$y_min_max[[2]] - quadrat_size,
seed = seed
)
}
Expand All @@ -114,10 +114,10 @@ sample_quadrats <- function(
if (method == "transect") {
xy_dat <- sampling_transects(
n_quadrats = n_quadrats,
xmin = comm$x_min_max[1],
xmax = comm$x_min_max[2],
ymin = comm$y_min_max[1],
ymax = comm$y_min_max[2],
xmin = comm$x_min_max[[1]],
xmax = comm$x_min_max[[2]],
ymin = comm$y_min_max[[1]],
ymax = comm$y_min_max[[2]],
x0 = x0,
y0 = y0,
delta_x = delta_x,
Expand All @@ -129,10 +129,10 @@ sample_quadrats <- function(
if (method == "grid") {
xy_dat <- sampling_grids(
n_quadrats = n_quadrats,
xmin = comm$x_min_max[1],
xmax = comm$x_min_max[2],
ymin = comm$y_min_max[1],
ymax = comm$y_min_max[2],
xmin = comm$x_min_max[[1]],
xmax = comm$x_min_max[[2]],
ymin = comm$y_min_max[[1]],
ymax = comm$y_min_max[[2]],
x0 = x0,
y0 = y0,
delta_x = delta_x,
Expand All @@ -156,8 +156,8 @@ sample_quadrats <- function(
comm_tab <- table(comm$census$species)

xy_dat <- data.frame(
x = comm$x_min_max[1],
y = comm$y_min_max[1]
x = comm$x_min_max[[1]],
y = comm$y_min_max[[1]]
)

rownames(xy_dat) <- "site1"
Expand All @@ -171,13 +171,13 @@ sample_quadrats <- function(
}

# plot sampling design
if (plot == TRUE) {
if (isTRUE(plot)) {
plot(comm)
graphics::rect(
xy_dat$x,
xy_dat$y,
xy_dat$x + quadrat_size,
xy_dat$y + quadrat_size,
xleft = xy_dat$x,
ybottom = xy_dat$y,
xright = xy_dat$x + quadrat_size,
ytop = xy_dat$y + quadrat_size,
lwd = 2,
col = grDevices::adjustcolor("white", alpha.f = 0.6)
)
Expand Down Expand Up @@ -243,7 +243,7 @@ sampling_random_spatstat <- function(
#' Creates coordinates (lower left corner of a quadrat) randomly distributed but without overlapping each
#' other
#'
#' This function works without having the \code{spatstat.random} package install.
#' This function works without having the \code{spatstat.random} package installed.
#'
#' @inheritParams sampling_random_spatstat
#'
Expand Down
Loading
Loading