make.density: Creates a Density object

View source: R/ClassConstructors.R

make.densityR Documentation

Creates a Density object


Creates a density grid across the study area describing the distribution of animals.


  region = make.region(), = 20, = NULL,
  constant = numeric(0),
  fitted.model = NULL,
  density.formula = NULL,
  density.surface = list()



the Region object in which the density grid will be created

the intervals in the grid in the x direction

the intervals in the grid in the y direction


a value describing a constant density across the surface. If not supplied a default value of 1 is used for all strata.


gam object created using mgcv with only x and y as explanatory covariates.


a formula of x and/or y describing the density surface.


Object of class list; an sf grid recording the density grid polygons, density values within those polygons and the central x and y coordinates.


There are multiple ways to create the density grid. The most straight forward is to create a grid with constant values (to which high and low areas can later be added) or pass in a fitted mgcv gam. The gam model should only be fitted with x and y as explanatory variables. If you plan on trying multiple animal distributions by adding high and low areas to a constant surface it is recommended to make a copy of the initial flat density grid object as the first step in grid generation is computationally intensive and can take a little while to complete, especially if you have a fine density grid.


Density-class object


Laura Marshall

See Also



# A simple density surface with a constant value of 1 can be created within a rectangular
# Create a region from shapefile <- system.file("extdata", "StAndrew.shp", package = "dssd")
region <- make.region( = "St Andrews bay",
                      shape =

# Create a density object
density <- make.density(region = region,
              = 1000,
                       constant = 1)

# Add some ares of higher / lower density
density <- add.hotspot(object = density,
                       centre = c(-170000, 6255000),
                       sigma = 10000,
                       amplitude = 4)
density <- add.hotspot(object = density,
                       centre = c(-150000, 6240000),
                       sigma = 10000,
                       amplitude = -0.9)

# Plot the density
plot(density, region)

dsims documentation built on Aug. 30, 2022, 5:06 p.m.