# Sampling communities with mobsim

#### 2021-03-22

In addition to the simulation and analysis of spatially-explicit communities, mobsim provides a function to generate samples from simulated or observed communities. The combination of simulated data AND simulated sampling is a powerful approach to test the validity and power of empirical approaches.

# 1 Random sampling

Here, we simulate a community and then generate samples with the function sample_quadrats. By default sample_quadrats distributes a user-defined number of quadrats with user-defined size in the landscape and provides the number of individuals for each species in each quadrat.

The function returns two dataframes. The first includes the abundance of every species in every sampling quadrat and the second the positions of the lower left corners of the quadrats.

The community matrix of samples by species can then be analysed using additional software. For instance the R package vegan is perfectly suited for the analysis of community data. See the vignette Introduction to mobsim for a worked example.

library(mobsim)
sim_com1 <- sim_poisson_community(s_pool = 100, n_sim = 20000)
sample1 <- sample_quadrats(sim_com1)
## Warning in sample_quadrats(sim_com1): There are overlapping sampling squares in
## the design

head(sample1$spec_dat[,1:6]) ## species1 species10 species100 species11 species12 species13 ## site1 6 1 0 2 3 4 ## site2 6 4 1 3 2 2 ## site3 10 2 1 2 1 3 ## site4 11 2 0 2 5 3 ## site5 6 0 0 5 1 8 ## site6 7 4 0 1 5 5 head(sample1$xy_dat)
##                x          y
## site1 0.09441025 0.33092222
## site2 0.76563408 0.74059717
## site3 0.88790931 0.04866594
## site4 0.09883485 0.74617248
## site5 0.59981875 0.61890149
## site6 0.88067087 0.81559684

In sample_quadrats() there is an option to exclude overlapping quadrats from the random sampling design, which is shown here in two examples with different numbers and sizes of the quadrats.

sample2 <- sample_quadrats(sim_com1, n_quadrats= 2, quadrat_area = 0.1,
avoid_overlap = T)

sample3 <- sample_quadrats(sim_com1, n_quadrats= 20, quadrat_area = 0.001,
avoid_overlap = T)

# 2 Transect sampling

In addition to random designs also transects can be sampled-. This requires specifying a position for the lower left quadrat as well as x and y distances between neighbouring quadrats.

sample4 <- sample_quadrats(sim_com1, n_quadrats= 10, quadrat_area = 0.005,
method = "transect", x0 = 0, y0 = 0.5, delta_x = 0.1,
delta_y = 0)

sample5 <- sample_quadrats(sim_com1, n_quadrats= 10, quadrat_area = 0.005,
method = "transect", x0 = 0, y0 = 0, delta_x = 0.1,
delta_y = 0.1)

# 3 Grid sampling

Finally, sampling quadrats can be arranged in a regular lattice. For this design users have to choose distances among the quadrats in x and y dimension as shown in the example.

sample6 <- sample_quadrats(sim_com1, n_quadrats= 25, quadrat_area = 0.005,
method = "grid", x0 = 0, y0 = 0, delta_x = 0.1,
delta_y = 0.1)

sample7 <- sample_quadrats(sim_com1, n_quadrats= 25, quadrat_area = 0.005,
method = "grid", x0 = 0.05, y0 = 0.05, delta_x = 0.2,
delta_y = 0.2)

By default, sample_quadrats() plots the chosen design. However, the plotting can be also deactivated for more efficient computations:

sample7a <- sample_quadrats(sim_com1, n_quadrats= 25, quadrat_area = 0.005,
method = "grid", x0 = 0.05, y0 = 0.05, delta_x = 0.2,
delta_y = 0.2, plot = F)
head(sample7a\$spec_dat[,1:10])
##       species1 species10 species100 species11 species12 species13 species14
## site1        4         4          0         1         1         0         3
## site2        5         3          0         2         3         3         3
## site3        2         1          0         3         2         0         1
## site4        4         3          0         2         0         3         1
## site5        3         0          0         0         1         3         0
## site6        2         3          0         1         2         1         2
##       species15 species16 species17
## site1         1         3         0
## site2         1         3         2
## site3         1         3         2
## site4         1         1         3
## site5         2         2         0
## site6         2         0         3