Learn R Programming

nimbleSCR (version 0.2.1)

calculateDensity: NIMBLE function to calculate the density of individuals alive in each habitat cell.

Description

calculateDensity is a NIMBLE function to calculate number of individual activity centers (s) in each habitat cell.

Usage

calculateDensity(s, habitatGrid, indicator, numWindows, nIndividuals)

Arguments

s

Matrix of x- and y-coordinates of individual AC locations.

habitatGrid

Matrix of habitat window indices. Cell values should correspond to the order of habitat windows in spatial probabilities (e.g. prob1To2Hab as used in the function dcatState1Alive2Dead) or in lowerCoords and upperCoords as used in the dbernppAC function. #' @param indicator Vector of binary arguments specifying whether the individuals are considered alive (indicator = 1) or not (indicator = 0).

indicator

Vector of binary arguments specifying whether the individuals are considered alive (indicator = 1) or not (indicator = 0).

numWindows

Scalar Number of habitat windows.

nIndividuals

Scalar Number of individuals.

Author

Cyril Milleret

Examples

Run this code
lowerCoords <- matrix(c(0, 0, 1, 0, 0, 1, 1, 1), nrow = 4, byrow = TRUE)
upperCoords <- matrix(c(1, 1, 2, 1, 1, 2, 2, 2), nrow = 4, byrow = TRUE)  
logIntensities <- log(rep(1,4))
logSumIntensity <- log(sum(c(1:4))) 
habitatGrid <- matrix(c(1:4), nrow = 2, byrow = TRUE)
numGridRows <- nrow(habitatGrid)
numGridCols <- ncol(habitatGrid)

s <- matrix(NA,nrow=10,ncol=2)
for(i in 1:10){
  s[i,] <- rbernppAC(n=1, lowerCoords, upperCoords, logIntensities, logSumIntensity, 
                     habitatGrid, numGridRows, numGridCols)
}

calculateDensity(s = s,
                 habitatGrid = habitatGrid,
                 indicator = rep(1, 10),
                 numWindows = prod(dim(habitatGrid)),
                 nIndividuals = 10
)

Run the code above in your browser using DataLab