| Title: | Isotope Origin Clustering and Assignment Tools |
|---|---|
| Description: | This resource provides tools to create, compare, and post-process spatial isotope assignment models of animal origin. It generates probability-of-origin maps for individuals based on user-provided tissue and environment isotope values (e.g., as generated by IsoMAP, Bowen et al. [2013] <doi:10.1111/2041-210X.12147>) using the framework established in Bowen et al. (2010) <doi:10.1146/annurev-earth-040809-152429>). The package 'isocat' can then quantitatively compare and cluster these maps to group individuals by similar origin. It also includes techniques for applying four approaches (cumulative sum, odds ratio, quantile only, and quantile simulation) with which users can summarize geographic origins and probable distance traveled by individuals. Campbell et al. [2020] establishes several of the functions included in this package <doi:10.1515/ami-2020-0004>. |
| Authors: | Caitlin Campbell [aut, cre] (ORCID: <https://orcid.org/0000-0002-8199-7775>) |
| Maintainer: | Caitlin Campbell <[email protected]> |
| License: | CC0 |
| Version: | 1.0.1 |
| Built: | 2026-07-12 01:19:56 UTC |
| Source: | https://github.com/cjcampbell/isocat |
Function applies hierarchical clustering analysis to similarity matrix, such as one output by 'simmatrixMaker' function. Just a wrapper for pvclust. Output is a pvclust object.
clusterSimmatrix( simmatrix, dist_mthd = "correlation", hclust_mthd = "average", nBoot = 1000, nClusters = FALSE, r = seq(0.7, 1.4, by = 0.1) )clusterSimmatrix( simmatrix, dist_mthd = "correlation", hclust_mthd = "average", nBoot = 1000, nClusters = FALSE, r = seq(0.7, 1.4, by = 0.1) )
simmatrix |
symmetric similarity matrix object. |
dist_mthd |
Distance measure to be used. Defaults to "correlation". See help(pvclust). |
hclust_mthd |
Method of clustering. Defaults to "average". See help(pvclust). |
nBoot |
number of bootstrap replications. Defaults to 1000. See help(pvclust). |
nClusters |
number of clusters to run in parallel using 'doParallel'. Defaults to FALSE (non-parallel). |
r |
Relative size of bootstrap replications. |
# Create probability-of-origin maps to compare. myiso <- rast(isoscape, type="xyz") plot(myiso) myiso_sd <- rast(isoscape_sd, type="xyz") n <- 5 set.seed(42) df <- data.frame( ID = LETTERS[1:n], isotopeValue = sample(-120:-40, n), SD_indv = rep(5, n) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) plot(assignmentModels) # Build a similarity matrix with surfaceSimilarityMatrix. mymatrix <- surfaceSimilarityMatrix(assignmentModels) # Cluster similarity matrix. clust_results <- clusterSimmatrix(mymatrix, dist_mthd = "correlation", hclust_mthd = "average", nBoot = 1000, nClusters = FALSE, r = seq(.7,1.4,by=.1) ) clust_results# Create probability-of-origin maps to compare. myiso <- rast(isoscape, type="xyz") plot(myiso) myiso_sd <- rast(isoscape_sd, type="xyz") n <- 5 set.seed(42) df <- data.frame( ID = LETTERS[1:n], isotopeValue = sample(-120:-40, n), SD_indv = rep(5, n) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) plot(assignmentModels) # Build a similarity matrix with surfaceSimilarityMatrix. mymatrix <- surfaceSimilarityMatrix(assignmentModels) # Cluster similarity matrix. clust_results <- clusterSimmatrix(mymatrix, dist_mthd = "correlation", hclust_mthd = "average", nBoot = 1000, nClusters = FALSE, r = seq(.7,1.4,by=.1) ) clust_results
Function estimates cumulative sum of all values in a surface below the value at a specified longitude and latitude.
cumsumAtSamplingLocation(indivraster, Lat, Lon)cumsumAtSamplingLocation(indivraster, Lat, Lon)
indivraster |
SpatRaster representing normalized probability of origin surface |
Lat |
Integer latitude |
Lon |
Integer longitude |
# Generate example probability surface. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") exampleSurface <- isotopeAssignmentModel( ID = "A", isotopeValue = -100, SD_indv = 5, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate cumulative sum at specific point. set.seed(1) x <- sample( which( !is.na(exampleSurface[]) ), size = 1) pt <- terra::xyFromCell(exampleSurface, x) cumsumAtSamplingLocation(indivraster = exampleSurface, Lat = pt[2], Lon = pt[1])# Generate example probability surface. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") exampleSurface <- isotopeAssignmentModel( ID = "A", isotopeValue = -100, SD_indv = 5, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate cumulative sum at specific point. set.seed(1) x <- sample( which( !is.na(exampleSurface[]) ), size = 1) pt <- terra::xyFromCell(exampleSurface, x) cumsumAtSamplingLocation(indivraster = exampleSurface, Lat = pt[2], Lon = pt[1])
Function that calculates the cumulative sum of values less than or equal to a given value.
cumsumbelow(vals)cumsumbelow(vals)
vals |
Object of numeric or integer class. |
Returns list of values representing cumulative sum of 'val' values less than or equal to the input.
vals <- 1:10 cumsumbelow(vals)vals <- 1:10 cumsumbelow(vals)
Function that counts cells (number and proportion) above given values.
getPrecisionPar(rasterstack, checkVals, method = FALSE, nCluster = FALSE)getPrecisionPar(rasterstack, checkVals, method = FALSE, nCluster = FALSE)
rasterstack |
SpatRaster of probability surfaces |
checkVals |
vector of numeric 'threshold' values against which to calculate precision |
method |
is FALSE by default. If character vector, appends a column recording 'method' used. |
nCluster |
Depreciated. Formerly the number of parallel clusters; retained for back-compatibility. A non-'FALSE' value now issues a message and proceeds serially. |
Returns a dataframe of precision values at given threshold.
myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") assignmentModels <- isotopeAssignmentModel( ID = LETTERS[1:4], isotopeValue = seq(-120, -25, length.out = 4), SD_indv = rep(5, 4), precip_raster = myiso, precip_SD_raster = myiso_sd ) getPrecisionPar(assignmentModels, checkVals = c(0.001, 0.005, 0.01))myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") assignmentModels <- isotopeAssignmentModel( ID = LETTERS[1:4], isotopeValue = seq(-120, -25, length.out = 4), SD_indv = rep(5, 4), precip_raster = myiso, precip_SD_raster = myiso_sd ) getPrecisionPar(assignmentModels, checkVals = c(0.001, 0.005, 0.01))
Three months (July, August, September) of a d2H precipitation isoscape,
provided to demonstrate makeMultiMonthIsoscape.
iso_monthlyiso_monthly
A data.frame with 43200 rows and 5 columns: x and y
coordinates plus three monthly d2H layers d2h_07, d2h_08,
and d2h_09. Convert to a multi-layer SpatRaster with
rast(iso_monthly, type = "xyz").
Bowen G. J., West J.B., Miller C. C., Zhao L. and Zhang T. (2018) IsoMAP: Isoscapes Modeling, Analysis and Prediction (version 1.0). The IsoMAP Project. http://isomap.org
iso_monthly_se, makeMultiMonthIsoscape
iso <- rast(iso_monthly, type = "xyz")iso <- rast(iso_monthly, type = "xyz")
Standard-error surfaces matching iso_monthly: three months
(July, August, September) of the d2H precipitation isoscape prediction error.
iso_monthly_seiso_monthly_se
A data.frame with 43200 rows and 5 columns: x and y
coordinates plus three monthly standard-error layers d2h_se_07,
d2h_se_08, and d2h_se_09. Convert to a multi-layer SpatRaster
with rast(iso_monthly_se, type = "xyz").
Bowen G. J., West J.B., Miller C. C., Zhao L. and Zhang T. (2018) IsoMAP: Isoscapes Modeling, Analysis and Prediction (version 1.0). The IsoMAP Project. http://isomap.org
iso_monthly, makeMultiMonthIsoscape
iso_se <- rast(iso_monthly_se, type = "xyz")iso_se <- rast(iso_monthly_se, type = "xyz")
Example isoscape data
isoscapeisoscape
A data.frame with 43200 rows (x, y and a d2h_GS layer), derived from a cropped raster object.
Campbell C. J. (2018) IsoMAP job 66100, Isoscapes Modeling, Analysis and Prediction (version 1.0). The IsoMAP Project. http://isomap.org
Bowen G. J., West J.B., Miller C. C., Zhao L. and Zhang T. (2018) IsoMAP: Isoscapes Modeling, Analysis and Prediction (version 1.0). IsoMAP job 66100, Caitlin J. Campbell. Isoscapes Modeling, Analysis and Prediction (version 1.0). The IsoMAP Project. http://isomap.org
iso <- rast(isoscape, type="xyz")iso <- rast(isoscape, type="xyz")
Example isoscape standard deviation data
isoscape_sdisoscape_sd
A data.frame with 43200 rows (x, y and a d2h_se_GS layer), derived from a cropped raster object.
Campbell C. J. (2018) IsoMAP job 66100, Isoscapes Modeling, Analysis and Prediction (version 1.0). The IsoMAP Project. http://isomap.org
Bowen G. J., West J.B., Miller C. C., Zhao L. and Zhang T. (2018) IsoMAP: Isoscapes Modeling, Analysis and Prediction (version 1.0). IsoMAP job 66100, Caitlin J. Campbell. Isoscapes Modeling, Analysis and Prediction (version 1.0). The IsoMAP Project. http://isomap.org
iso_sd <- rast(isoscape_sd, type="xyz")iso_sd <- rast(isoscape_sd, type="xyz")
Creates isotope assignment models projections of probable origin. Results returned as a SpatRaster, with layer names corresponding to individual ID.
isotopeAssignmentModel( ID, isotopeValue, SD_indv = NULL, precip_raster, precip_SD_raster, additionalModels = FALSE, additionalModel_name = "CombinedIsotope-OtherModelAssignments", savePath = FALSE, nClusters = FALSE )isotopeAssignmentModel( ID, isotopeValue, SD_indv = NULL, precip_raster, precip_SD_raster, additionalModels = FALSE, additionalModel_name = "CombinedIsotope-OtherModelAssignments", savePath = FALSE, nClusters = FALSE )
ID |
ID value or vector of values (for naming assignment model layers). If missing, will count from 1. |
isotopeValue |
Isotope precipitation value or vector of values. |
SD_indv |
error associated with transfer function fit. Value or vector of values. If NULL (default), no individual-level error is included (isoscape error only). |
precip_raster |
precipitation isoscape SpatRaster or raster. |
precip_SD_raster |
precipitation isoscape standard deviation SpatRaster or raster. |
additionalModels |
optional additional model raster object (e.g. an SDM, rasterized range map, or stack thereof). If specified, function will return isotope assignment rasters and the product of these additionalModels and each assignmentRaster. |
additionalModel_name |
optional filename for additionalModel .grd savepath |
savePath |
If specified, function will save results to this path as a '.grd' file. |
nClusters |
Depreciated. Formerly, integer of cores to run in parallel with doParallel. Default FALSE. |
myiso <- rast(isoscape, type="xyz") plot(myiso) myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = paste0("Example.", 1:3), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd ) plot(assignmentModels) # Add additionalModels: range_raster <- myiso range_raster[] <- as.numeric( 1:ncell(myiso) %% 60 >= 10) plot(range_raster) sdm_raster <- myiso sdm_raster[] <- (1:ncell(sdm_raster))^2 sdm_raster <- sdm_raster / terra::global(sdm_raster, "sum", na.rm = TRUE)[1, 1] plot(sdm_raster) extraModels <- c(range_raster, sdm_raster) assignmentModels <- isotopeAssignmentModel( ID = paste0("Combo.",df$ID), isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, additionalModels = extraModels ) plot(assignmentModels)myiso <- rast(isoscape, type="xyz") plot(myiso) myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = paste0("Example.", 1:3), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd ) plot(assignmentModels) # Add additionalModels: range_raster <- myiso range_raster[] <- as.numeric( 1:ncell(myiso) %% 60 >= 10) plot(range_raster) sdm_raster <- myiso sdm_raster[] <- (1:ncell(sdm_raster))^2 sdm_raster <- sdm_raster / terra::global(sdm_raster, "sum", na.rm = TRUE)[1, 1] plot(sdm_raster) extraModels <- c(range_raster, sdm_raster) assignmentModels <- isotopeAssignmentModel( ID = paste0("Combo.",df$ID), isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, additionalModels = extraModels ) plot(assignmentModels)
Converts normalized probability surface (e.g. one layer output of isotopeAssignmentModel function) to cumulative sum surfaces, i.e., one where the new value of a given cell is equal to the sum of all old values less than or equal to the old value of the cell.
makecumsumSurface(indivraster, rescale = FALSE, rename = FALSE)makecumsumSurface(indivraster, rescale = FALSE, rename = FALSE)
indivraster |
Normalized probability surface SpatRaster |
rescale |
Rescale between 0 and 1? Defaults to FALSE. |
rename |
Character value to append to raster name (e.g. "_odds"). Defaults to FALSE. |
Returns SpatRaster rescaled to Cumulative Sum values.
# Generate example probability surfaces. The isoscape is coarsened here so the # example runs quickly; cumsumbelow() scales with the square of the cell count. myiso <- terra::aggregate(rast(isoscape, type = "xyz"), 5) myiso_sd <- terra::aggregate(rast(isoscape_sd, type = "xyz"), 5) df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Convert to cumulative sum surface. cumulative_sum_surface <- terra::rast( lapply( terra::as.list( assignmentModels ), makecumsumSurface ) ) plot(cumulative_sum_surface)# Generate example probability surfaces. The isoscape is coarsened here so the # example runs quickly; cumsumbelow() scales with the square of the cell count. myiso <- terra::aggregate(rast(isoscape, type = "xyz"), 5) myiso_sd <- terra::aggregate(rast(isoscape_sd, type = "xyz"), 5) df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Convert to cumulative sum surface. cumulative_sum_surface <- terra::rast( lapply( terra::as.list( assignmentModels ), makecumsumSurface ) ) plot(cumulative_sum_surface)
Combines a stack of monthly isoscape maps, monthly isoscape standard error maps, and optionally a precipitation (amount) stack into a single precipitation-weighted mean isoscape and a combined error surface. Each stack must contain layers corresponding to each of the target months.
makeMultiMonthIsoscape(iso_stack, iso_se_stack, precip_stack = NULL)makeMultiMonthIsoscape(iso_stack, iso_se_stack, precip_stack = NULL)
iso_stack |
A SpatRaster containing n layers corresponding to isoscape models for n months. |
iso_se_stack |
A SpatRaster containing n layers corresponding to isoscape standard error maps for n months. |
precip_stack |
Either a SpatRaster containing n layers corresponding to precipitation amounts for n months, or NULL (assumes equal precipitation amounts.) |
If precip_stack is NULL, equal precipitation amounts are assumed for each month.
A list containing a precipitation-weighted mean isoscape ('mean_iso') and a root-sum-of-square combined error map ('iso_se').
myiso <- rast(isoscape, type = "xyz") myiso_sd <- rast(isoscape_sd, type = "xyz") # Two example "months" derived from the bundled isoscape. iso_stack <- c(myiso, myiso + 5) iso_se_stack <- c(myiso_sd, myiso_sd) precip_stack <- c(myiso * 0 + 1, myiso * 0 + 3) # relative weights 1:3 result <- makeMultiMonthIsoscape(iso_stack, iso_se_stack, precip_stack) plot(result$mean_iso) plot(result$iso_se)myiso <- rast(isoscape, type = "xyz") myiso_sd <- rast(isoscape_sd, type = "xyz") # Two example "months" derived from the bundled isoscape. iso_stack <- c(myiso, myiso + 5) iso_se_stack <- c(myiso_sd, myiso_sd) precip_stack <- c(myiso * 0 + 1, myiso * 0 + 3) # relative weights 1:3 result <- makeMultiMonthIsoscape(iso_stack, iso_se_stack, precip_stack) plot(result$mean_iso) plot(result$iso_se)
Converts normalized probability surface (e.g. one layer output of isotopeAssignmentModel function) to Odds Ratio surfaces.
makeOddsSurfaces(probabilitySurface, rename = FALSE)makeOddsSurfaces(probabilitySurface, rename = FALSE)
probabilitySurface |
Normalized probability surface SpatRaster |
rename |
Character value to append to raster name (e.g. "_odds"). Defaults to FALSE. |
Returns SpatRaster rescaled to Odds Ratio values.
# Generate example probability surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Convert to odds ratio surfaces. odds_ratio_surface <- terra::rast( lapply( terra::as.list(assignmentModels), makeOddsSurfaces ) ) plot(odds_ratio_surface)# Generate example probability surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Convert to odds ratio surfaces. odds_ratio_surface <- terra::rast( lapply( terra::as.list(assignmentModels), makeOddsSurfaces ) ) plot(odds_ratio_surface)
Converts normalized probability surfaces (e.g. one layer output of isotopeAssignmentModel function) to quantile surfaces.
makeQuantileSimulationSurface( probabilitySurface, ValidationQuantiles, rename = FALSE, rescale = TRUE )makeQuantileSimulationSurface( probabilitySurface, ValidationQuantiles, rename = FALSE, rescale = TRUE )
probabilitySurface |
Normalized probability surface SpatRaster. |
ValidationQuantiles |
Vector of quantile values from known-origin individuals, against which to compare each value within the probability surface. Each value must be between 0 and 1. |
rename |
Character value to append to raster name (e.g. "_quantileSimulation"). Defaults to FALSE. |
rescale |
If rescale = TRUE, returns surface showing proportion of times each surface cell value fell within the validation quantiles distribution. If rescale = FALSE, returns discrete number of times the cell fell within the distribution. |
Returns SpatRaster rescaled to quantile values.
# Generate example probability surfaces. library(isocat) myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd ) # Example known-origin quantile data. q <- rweibull(20000, 6, .98) q <- sample( q[ q >=0 & q <= 1 ], 10000, replace = TRUE) hist(q) # Convert to quantile surfaces. quantileSimulation_surface <- terra::rast( lapply( terra::as.list(assignmentModels), makeQuantileSimulationSurface, ValidationQuantiles = q) ) plot(quantileSimulation_surface)# Generate example probability surfaces. library(isocat) myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd ) # Example known-origin quantile data. q <- rweibull(20000, 6, .98) q <- sample( q[ q >=0 & q <= 1 ], 10000, replace = TRUE) hist(q) # Convert to quantile surfaces. quantileSimulation_surface <- terra::rast( lapply( terra::as.list(assignmentModels), makeQuantileSimulationSurface, ValidationQuantiles = q) ) plot(quantileSimulation_surface)
Converts normalized probability surface (e.g. one layer output of isotopeAssignmentModel function) to quantile surfaces.
makeQuantileSurfaces(probabilitySurface, rename = FALSE)makeQuantileSurfaces(probabilitySurface, rename = FALSE)
probabilitySurface |
Normalized probability surface SpatRaster |
rename |
Character value to append to raster name (e.g. "_quantile"). Defaults to FALSE. |
Returns SpatRaster rescaled to quantile values.
# Generate example probability surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Convert to quantile surfaces. quantile_surface <- terra::rast( lapply( terra::as.list(assignmentModels), makeQuantileSurfaces) ) plot(quantile_surface)# Generate example probability surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Convert to quantile surfaces. quantile_surface <- terra::rast( lapply( terra::as.list(assignmentModels), makeQuantileSurfaces) ) plot(quantile_surface)
Subset probability-of-origin surfaces by cluster assignment and find mean aggregate probability-of-origin surface for each clustered group.
meanAggregateClusterProbability(indivIDs, clusters, surfaces, nClust = FALSE)meanAggregateClusterProbability(indivIDs, clusters, surfaces, nClust = FALSE)
indivIDs |
Vector of individual ID variables corresponding to surface names. |
clusters |
Vector of cluster IDs, in an order corresponding to 'indivIDs'. |
surfaces |
SpatRaster of probability-of-origin surfaces for all individuals. |
nClust |
Depreciated. Formerly enabled multi-core processing; retained for back-compatibility. A non-'FALSE' value now issues a message and proceeds serially. |
# Create and cluster example assignment surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = LETTERS[1:9], isotopeValue = seq(-120,-25,length.out = 9), SD_indv = rep(5, 9) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) mySimilarityMatrix <- surfaceSimilarityMatrix(assignmentModels) cS <- clusterSimmatrix( simmatrix = mySimilarityMatrix, r = seq(.7,1.4,by=.1) ) # Cut clusters. myheight <- 0.25 df$cluster <- dendextend::cutree(cS$hclust, h = myheight) # Create mean aggregate surfaces.r p meanSurfaces <- meanAggregateClusterProbability( indivIDs = df$ID, clusters = df$cluster, surfaces = assignmentModels, nClust = FALSE )# Create and cluster example assignment surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = LETTERS[1:9], isotopeValue = seq(-120,-25,length.out = 9), SD_indv = rep(5, 9) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) mySimilarityMatrix <- surfaceSimilarityMatrix(assignmentModels) cS <- clusterSimmatrix( simmatrix = mySimilarityMatrix, r = seq(.7,1.4,by=.1) ) # Cut clusters. myheight <- 0.25 df$cluster <- dendextend::cutree(cS$hclust, h = myheight) # Create mean aggregate surfaces.r p meanSurfaces <- meanAggregateClusterProbability( indivIDs = df$ID, clusters = df$cluster, surfaces = assignmentModels, nClust = FALSE )
Function estimates percentile of each non-NA value within a RasterLayer using the empirical cumulative distribution function, and extracts value at location specified. For more information, see help(ecdf).
oddsAtSamplingLocation(indivraster, Lat, Lon)oddsAtSamplingLocation(indivraster, Lat, Lon)
indivraster |
SpatRaster representing normalized probability of origin surface |
Lat |
Integer latitude |
Lon |
Integer longitude |
# Generate example probability surface. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") exampleSurface <- isotopeAssignmentModel( ID = "A", isotopeValue = -100, SD_indv = 5, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate odds ratio at specific point. set.seed(1) x <- sample( which( !is.na(exampleSurface[]) ), size = 1) pt <- terra::xyFromCell(exampleSurface, x) oddsAtSamplingLocation(exampleSurface, Lat = pt[2], Lon = pt[1])# Generate example probability surface. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") exampleSurface <- isotopeAssignmentModel( ID = "A", isotopeValue = -100, SD_indv = 5, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate odds ratio at specific point. set.seed(1) x <- sample( which( !is.na(exampleSurface[]) ), size = 1) pt <- terra::xyFromCell(exampleSurface, x) oddsAtSamplingLocation(exampleSurface, Lat = pt[2], Lon = pt[1])
Create a summary surface showing which RasterLayer in a Stack has the highest value at a given location. For each cell in a RasterStack, this function returns the identity of the RasterLayer with the highest value at that cell. This surface is intended as a visual summary of common origins, not a basis for quantitative analysis.
projectSummaryMaxSurface(surfaces, nClust = FALSE)projectSummaryMaxSurface(surfaces, nClust = FALSE)
surfaces |
SpatRaster where each layer represents a probability-of-origin surface |
nClust |
Depreciated. Formerly enabled multi-core processing; retained for back-compatibility. A non-'FALSE' value now issues a message and proceeds serially. |
# Create and cluster example assignment surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") assignmentModels <- isotopeAssignmentModel( ID = LETTERS[1:4], isotopeValue = seq(-120,-25,length.out = 4), SD_indv = rep(5,4), precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) plot(assignmentModels) # Project mean aggregate surfaces into space. summaryMap <- projectSummaryMaxSurface( surfaces = assignmentModels, nClust = FALSE ) plot(summaryMap)# Create and cluster example assignment surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") assignmentModels <- isotopeAssignmentModel( ID = LETTERS[1:4], isotopeValue = seq(-120,-25,length.out = 4), SD_indv = rep(5,4), precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) plot(assignmentModels) # Project mean aggregate surfaces into space. summaryMap <- projectSummaryMaxSurface( surfaces = assignmentModels, nClust = FALSE ) plot(summaryMap)
Function estimates percentile of each non-NA value within a RasterLayer using the empirical cumulative distribution function, and extracts value at location specified. For more information, see help(ecdf).
quantileAtSamplingLocation(indivraster, Lat, Lon)quantileAtSamplingLocation(indivraster, Lat, Lon)
indivraster |
A SpatRaster representing normalized probability of origin surface |
Lat |
Integer latitude |
Lon |
Integer longitude |
# Generate example probability surface. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") exampleSurface <- isotopeAssignmentModel( ID = "A", isotopeValue = -100, SD_indv = 5, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate quantile probability value at specific point. set.seed(1) x <- sample( which( !is.na(exampleSurface[]) ), size = 1) pt <- terra::xyFromCell(exampleSurface, x) quantileAtSamplingLocation(exampleSurface, Lat = pt[2], Lon = pt[1])# Generate example probability surface. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") exampleSurface <- isotopeAssignmentModel( ID = "A", isotopeValue = -100, SD_indv = 5, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate quantile probability value at specific point. set.seed(1) x <- sample( which( !is.na(exampleSurface[]) ), size = 1) pt <- terra::xyFromCell(exampleSurface, x) quantileAtSamplingLocation(exampleSurface, Lat = pt[2], Lon = pt[1])
RasterLayers must have identical resolutions and extents. The function will automatically normalize surfaces to sum to 1.
schoenersD(rast1, rast2)schoenersD(rast1, rast2)
rast1 |
First object of class SpatRaster |
rast2 |
Second object of class SpatRaster |
Calculates similarity value of two RasterLayers using Schoener's D-metric.
# Generate example probability surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate Schoener's D-metric of spatial similarity between two of the # example probability surfaces. schoenersD(assignmentModels[[1]], assignmentModels[[2]]) ## 0.969156# Generate example probability surfaces. myiso <- rast(isoscape, type="xyz") myiso_sd <- rast(isoscape_sd, type="xyz") df <- data.frame( ID = c(-100, -80, -50), isotopeValue = c(-100, -80, -50), SD_indv = rep(5, 3) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) # Calculate Schoener's D-metric of spatial similarity between two of the # example probability surfaces. schoenersD(assignmentModels[[1]], assignmentModels[[2]]) ## 0.969156
Legacy function that runs on raster::stack. Applies pairwise comparisons of Schoener's D-metric between each RasterLayer in a RasterStack to populate a similarity matrix.
simmatrixMaker(assignmentRasters, nClusters = FALSE, csvSavePath = FALSE)simmatrixMaker(assignmentRasters, nClusters = FALSE, csvSavePath = FALSE)
assignmentRasters |
Input RasterStack |
nClusters |
Clusters to create run in parallel using 'doParallel'. Defaults to FALSE. |
csvSavePath |
Optional savepath to write similarity matrix to csv file. Defaults to FALSE, will not create csv. |
# simmatrixMaker() is a legacy function for raster::stack input; # for SpatRaster input use surfaceSimilarityMatrix() instead. if (requireNamespace("raster", quietly = TRUE)) { myiso <- rast(isoscape, type = "xyz") myiso_sd <- rast(isoscape_sd, type = "xyz") set.seed(42) assignmentModels <- isotopeAssignmentModel( ID = LETTERS[1:5], isotopeValue = sample(-120:-40, 5), SD_indv = rep(5, 5), precip_raster = myiso, precip_SD_raster = myiso_sd ) # Coerce to a RasterStack for the legacy interface. simmatrixMaker(raster::stack(assignmentModels)) }# simmatrixMaker() is a legacy function for raster::stack input; # for SpatRaster input use surfaceSimilarityMatrix() instead. if (requireNamespace("raster", quietly = TRUE)) { myiso <- rast(isoscape, type = "xyz") myiso_sd <- rast(isoscape_sd, type = "xyz") set.seed(42) assignmentModels <- isotopeAssignmentModel( ID = LETTERS[1:5], isotopeValue = sample(-120:-40, 5), SD_indv = rep(5, 5), precip_raster = myiso, precip_SD_raster = myiso_sd ) # Coerce to a RasterStack for the legacy interface. simmatrixMaker(raster::stack(assignmentModels)) }
Populates a similarity matrix from pairwise Schoener's D comparisons between the layers of a SpatRaster.
surfaceSimilarityMatrix(spatrast)surfaceSimilarityMatrix(spatrast)
spatrast |
Input SpatRaster |
# Create probability-of-origin maps to compare. myiso <- rast(isoscape, type="xyz") plot(myiso) myiso_sd <- rast(isoscape_sd, type="xyz") n <- 5 set.seed(42) df <- data.frame( ID = LETTERS[1:n], isotopeValue = sample(-120:-40, n), SD_indv = rep(5, n) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) plot(assignmentModels) # Compare maps with surfaceSimilarityMatrix. surfaceSimilarityMatrix(assignmentModels)# Create probability-of-origin maps to compare. myiso <- rast(isoscape, type="xyz") plot(myiso) myiso_sd <- rast(isoscape_sd, type="xyz") n <- 5 set.seed(42) df <- data.frame( ID = LETTERS[1:n], isotopeValue = sample(-120:-40, n), SD_indv = rep(5, n) ) assignmentModels <- isotopeAssignmentModel( ID = df$ID, isotopeValue = df$isotopeValue, SD_indv = df$SD_indv, precip_raster = myiso, precip_SD_raster = myiso_sd, nClusters = FALSE ) plot(assignmentModels) # Compare maps with surfaceSimilarityMatrix. surfaceSimilarityMatrix(assignmentModels)