| Title: | Estimate and Simulate from Location Dependent Marked Point Processes |
|---|---|
| Description: | A suite of tools for estimating, assessing model fit, simulating from, and visualizing location dependent marked point processes characterized by regularity in the pattern. You provide a reference marked point process, a set of raster images containing location specific covariates, and select the estimation algorithm and type of mark model. 'ldmppr' estimates the process and mark models and allows you to check the appropriateness of the model using a variety of diagnostic tools. Once a satisfactory model fit is obtained, you can simulate from the model and visualize the results. Documentation for the package 'ldmppr' is available in the form of a vignette. |
| Authors: | Lane Drew [aut, cre, cph] (ORCID: <https://orcid.org/0009-0006-5427-4092>), Andee Kaplan [aut] (ORCID: <https://orcid.org/0000-0002-2940-889X>) |
| Maintainer: | Lane Drew <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.1.3.9000 |
| Built: | 2026-06-01 09:51:03 UTC |
| Source: | https://github.com/lanedrew/ldmppr |
Performs global envelope tests for nonparametric L, F, G, J, E, and V summary
functions (spatstat/GET).
These tests assess goodness-of-fit of the estimated model relative to a reference marked point pattern.
The reference marked point pattern can be supplied directly via reference_data (a marked ppp object),
or derived internally from a ldmppr_fit object.
check_model_fit( reference_data = NULL, t_min = 0, t_max = 1, process = c("self_correcting"), process_fit = NULL, anchor_point = NULL, raster_list = NULL, scaled_rasters = FALSE, mark_model = NULL, xy_bounds = NULL, include_comp_inds = FALSE, thinning = TRUE, edge_correction = "none", competition_radius = 15, n_sim = 2500, save_sims = TRUE, verbose = TRUE, seed = 0, parallel = FALSE, num_cores = max(1L, parallel::detectCores() - 1L), set_future_plan = FALSE, mark_mode = NULL, fg_correction = c("km", "rs"), max_attempts = NULL )check_model_fit( reference_data = NULL, t_min = 0, t_max = 1, process = c("self_correcting"), process_fit = NULL, anchor_point = NULL, raster_list = NULL, scaled_rasters = FALSE, mark_model = NULL, xy_bounds = NULL, include_comp_inds = FALSE, thinning = TRUE, edge_correction = "none", competition_radius = 15, n_sim = 2500, save_sims = TRUE, verbose = TRUE, seed = 0, parallel = FALSE, num_cores = max(1L, parallel::detectCores() - 1L), set_future_plan = FALSE, mark_mode = NULL, fg_correction = c("km", "rs"), max_attempts = NULL )
reference_data |
(optional) a marked |
t_min |
minimum value for time. |
t_max |
maximum value for time. |
process |
type of process used (currently supports |
process_fit |
either an |
anchor_point |
(optional) vector of (x,y) coordinates of the point to condition on.
If |
raster_list |
(optional) list of raster objects used for mark prediction.
Required when |
scaled_rasters |
|
mark_model |
a mark model object used when |
xy_bounds |
(optional) vector of bounds as |
include_comp_inds |
|
thinning |
|
edge_correction |
type of edge correction to apply ( |
competition_radius |
positive numeric distance used when |
n_sim |
number of simulated datasets to generate. |
save_sims |
|
verbose |
|
seed |
integer seed for reproducibility. |
parallel |
|
num_cores |
number of workers to use when |
set_future_plan |
|
mark_mode |
(optional) mark generation mode: |
fg_correction |
correction used for F/G/J summaries ( |
max_attempts |
maximum number of simulation attempts when rejection occurs due to non-finite summaries. |
This function relies on the spatstat package for the calculation of the point pattern metrics
and the GET package for the global envelope tests. The L, F, G, J, E, and V functions are a collection of
non-parametric summary statistics that describe the spatial distribution of points and marks in a point pattern.
See the documentation for Lest(), Fest(), Gest(),
Jest(), Emark(), and Vmark() for more information.
Also, see the global_envelope_test() function for more information on the global envelope tests.
an object of class "ldmppr_model_check".
Baddeley, A., Rubak, E., & Turner, R. (2015). *Spatial Point Patterns: Methodology and Applications with R*. Chapman and Hall/CRC Press, London. ISBN 9781482210200. Available at: https://www.routledge.com/Spatial-Point-Patterns-Methodology-and-Applications-with-R/Baddeley-Rubak-Turner/p/book/9781482210200.
Myllymäki, M., & Mrkvička, T. (2023). GET: Global envelopes in R. arXiv:1911.06583 [stat.ME]. doi:10.48550/arXiv.1911.06583.
# Note: The example below is provided for illustrative purposes and may take some time to run. data(small_example_data) file_path <- system.file("extdata", "example_mark_model.rds", package = "ldmppr") mark_model <- load_mark_model(file_path) raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) scaled_raster_list <- scale_rasters(rasters) reference_data <- generate_mpp( locations = small_example_data[, c("x", "y")], marks = small_example_data$size, xy_bounds = c(0, 25, 0, 25) ) estimated_parameters <- c( 0.05167978, 8.20702166, 0.02199940, 2.63236890, 1.82729512, 0.65330061, 0.86666748, 0.04681878 ) # Keep parallel=FALSE in examples to avoid setup overhead. example_model_fit <- check_model_fit( reference_data = reference_data, t_min = 0, t_max = 1, process = "self_correcting", process_fit = estimated_parameters, raster_list = scaled_raster_list, scaled_rasters = TRUE, mark_model = mark_model, xy_bounds = c(0, 25, 0, 25), include_comp_inds = TRUE, thinning = TRUE, edge_correction = "none", competition_radius = 10, n_sim = 100, save_sims = FALSE, verbose = TRUE, seed = 90210, parallel = FALSE ) plot(example_model_fit, which = 'combined')# Note: The example below is provided for illustrative purposes and may take some time to run. data(small_example_data) file_path <- system.file("extdata", "example_mark_model.rds", package = "ldmppr") mark_model <- load_mark_model(file_path) raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) scaled_raster_list <- scale_rasters(rasters) reference_data <- generate_mpp( locations = small_example_data[, c("x", "y")], marks = small_example_data$size, xy_bounds = c(0, 25, 0, 25) ) estimated_parameters <- c( 0.05167978, 8.20702166, 0.02199940, 2.63236890, 1.82729512, 0.65330061, 0.86666748, 0.04681878 ) # Keep parallel=FALSE in examples to avoid setup overhead. example_model_fit <- check_model_fit( reference_data = reference_data, t_min = 0, t_max = 1, process = "self_correcting", process_fit = estimated_parameters, raster_list = scaled_raster_list, scaled_rasters = TRUE, mark_model = mark_model, xy_bounds = c(0, 25, 0, 25), include_comp_inds = TRUE, thinning = TRUE, edge_correction = "none", competition_radius = 10, n_sim = 100, save_sims = FALSE, verbose = TRUE, seed = 90210, parallel = FALSE ) plot(example_model_fit, which = 'combined')
Estimate spatio-temporal point process parameters by maximizing the (approximate)
full log-likelihood using nloptr.
estimate_process_parameters( data, process = c("self_correcting"), grids, budgets, parameter_inits = NULL, delta = NULL, parallel = FALSE, num_cores = max(1L, parallel::detectCores() - 1L), set_future_plan = FALSE, strategy = c("local", "global_local", "multires_global_local"), global_algorithm = "NLOPT_GN_CRS2_LM", local_algorithm = "NLOPT_LN_BOBYQA", starts = list(global = 1L, local = 1L, jitter_sd = 0.35, seed = 1L), finite_bounds = NULL, refine_best_delta = TRUE, rescore_control = list(enabled = TRUE, top = 5L, objective_tol = 1e-06, param_tol = 0.1, avoid_bound_solutions = TRUE, bound_eps = 1e-08), verbose = TRUE )estimate_process_parameters( data, process = c("self_correcting"), grids, budgets, parameter_inits = NULL, delta = NULL, parallel = FALSE, num_cores = max(1L, parallel::detectCores() - 1L), set_future_plan = FALSE, strategy = c("local", "global_local", "multires_global_local"), global_algorithm = "NLOPT_GN_CRS2_LM", local_algorithm = "NLOPT_LN_BOBYQA", starts = list(global = 1L, local = 1L, jitter_sd = 0.35, seed = 1L), finite_bounds = NULL, refine_best_delta = TRUE, rescore_control = list(enabled = TRUE, top = 5L, objective_tol = 1e-06, param_tol = 0.1, avoid_bound_solutions = TRUE, bound_eps = 1e-08), verbose = TRUE )
data |
a data.frame or matrix. Must contain either columns |
process |
type of process used (currently supports |
grids |
a |
budgets |
a |
parameter_inits |
(optional) numeric vector of length 8 giving initialization values
for the model parameters. If |
delta |
(optional) numeric scalar or vector. Used only when
If |
parallel |
|
num_cores |
number of workers to use when |
set_future_plan |
|
strategy |
character string specifying the estimation strategy:
|
global_algorithm, local_algorithm
|
NLopt algorithms to use for the global and local optimization stages, respectively. |
starts |
a list controlling restart and jitter behavior:
|
finite_bounds |
(optional) list with components |
refine_best_delta |
|
rescore_control |
controls candidate rescoring and bound-handling behavior in multi-resolution fitting. Can be either:
Defaults are:
|
verbose |
|
For the self-correcting process, arrival times must lie on and can be
supplied directly in data as time, or constructed from size
via the gentle-decay (power-law) mapping power_law_mapping using
delta. When delta is a vector, the model is fit for each candidate
value and the best objective is selected.
This function supports multi-resolution estimation via a ldmppr_grids
schedule. If multiple grid levels are provided, the coarsest level may use a global
optimizer followed by local refinement, and subsequent levels run local refinement only.
an object of class "ldmppr_fit" containing the best nloptr fit and
(optionally) stored fits from global restarts and/or a delta search.
Møller, J., Ghorbani, M., & Rubak, E. (2016). Mechanistic spatio-temporal point process models for marked point processes, with a view to forest stand data. Biometrics, 72(3), 687-696. doi:10.1111/biom.12466.
# Load example data data(small_example_data) # Define grids and budgets ub <- c(1, 25, 25) g <- ldmppr_grids(upper_bounds = ub, levels = list(c(10,10,10))) b <- ldmppr_budgets( global_options = list(maxeval = 150), local_budget_first_level = list(maxeval = 50, xtol_rel = 1e-2), local_budget_refinement_levels = list(maxeval = 25, xtol_rel = 1e-2) ) # Estimate parameters using a single delta value fit <- estimate_process_parameters( data = small_example_data, grids = g, budgets = b, delta = 1, strategy = "global_local", global_algorithm = "NLOPT_GN_CRS2_LM", local_algorithm = "NLOPT_LN_BOBYQA", starts = list(global = 2, local = 2, jitter_sd = 0.25, seed = 1), verbose = TRUE ) coef(fit) logLik(fit) # Estimate parameters using multiple delta values (delta search) g2 <- ldmppr_grids(upper_bounds = ub, levels = list(c(8,8,8), c(12,12,12))) fit_delta <- estimate_process_parameters( data = small_example_data, # x,y,size grids = g2, budgets = b, delta = c(0.35, 0.5, 0.65, 0.9, 1.0), parallel = TRUE, set_future_plan = TRUE, num_cores = 2, strategy = "multires_global_local", starts = list(local = 1), refine_best_delta = FALSE, verbose = FALSE ) plot(fit_delta)# Load example data data(small_example_data) # Define grids and budgets ub <- c(1, 25, 25) g <- ldmppr_grids(upper_bounds = ub, levels = list(c(10,10,10))) b <- ldmppr_budgets( global_options = list(maxeval = 150), local_budget_first_level = list(maxeval = 50, xtol_rel = 1e-2), local_budget_refinement_levels = list(maxeval = 25, xtol_rel = 1e-2) ) # Estimate parameters using a single delta value fit <- estimate_process_parameters( data = small_example_data, grids = g, budgets = b, delta = 1, strategy = "global_local", global_algorithm = "NLOPT_GN_CRS2_LM", local_algorithm = "NLOPT_LN_BOBYQA", starts = list(global = 2, local = 2, jitter_sd = 0.25, seed = 1), verbose = TRUE ) coef(fit) logLik(fit) # Estimate parameters using multiple delta values (delta search) g2 <- ldmppr_grids(upper_bounds = ub, levels = list(c(8,8,8), c(12,12,12))) fit_delta <- estimate_process_parameters( data = small_example_data, # x,y,size grids = g2, budgets = b, delta = c(0.35, 0.5, 0.65, 0.9, 1.0), parallel = TRUE, set_future_plan = TRUE, num_cores = 2, strategy = "multires_global_local", starts = list(local = 1), refine_best_delta = FALSE, verbose = FALSE ) plot(fit_delta)
Extract covariate values from a set of rasters
extract_covars(locations, raster_list)extract_covars(locations, raster_list)
locations |
a matrix/data.frame of (x,y) locations. |
raster_list |
a list of SpatRaster objects. |
a data.frame of covariates (no ID column; unique names).
# Load example raster data raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE ) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) # Scale the rasters scaled_raster_list <- scale_rasters(rasters) # Load example locations locations <- small_example_data %>% dplyr::select(x, y) %>% as.matrix() # Extract covariates example_covars <- extract_covars(locations, scaled_raster_list) head(example_covars)# Load example raster data raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE ) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) # Scale the rasters scaled_raster_list <- scale_rasters(rasters) # Load example locations locations <- small_example_data %>% dplyr::select(x, y) %>% as.matrix() # Extract covariates example_covars <- extract_covars(locations, scaled_raster_list) head(example_covars)
Creates an object of class "ppp" that represents a marked point pattern in the two-dimensional plane.
generate_mpp(locations, marks = NULL, xy_bounds = NULL)generate_mpp(locations, marks = NULL, xy_bounds = NULL)
locations |
a data.frame or matrix of (x,y) locations. If a data.frame is supplied, it must contain columns named "x" and "y". |
marks |
a vector of marks. |
xy_bounds |
a vector of domain bounds (2 for x, 2 for y). |
a ppp object with marks.
# Load example data data(small_example_data) # Generate a marked point process generate_mpp( locations = small_example_data %>% dplyr::select(x, y), marks = small_example_data$size, xy_bounds = c(0, 25, 0, 25) )# Load example data data(small_example_data) # Generate a marked point process generate_mpp( locations = small_example_data %>% dplyr::select(x, y), marks = small_example_data$size, xy_bounds = c(0, 25, 0, 25) )
ldmppr_budgets() defines per-stage optimization options (budgets) used by
estimate_process_parameters for NLopt via nloptr.
ldmppr_budgets( global_options = NULL, local_budget_first_level = NULL, local_budget_refinement_levels = NULL )ldmppr_budgets( global_options = NULL, local_budget_first_level = NULL, local_budget_refinement_levels = NULL )
global_options |
(optional) list of NLopt options used for the global stage
(only relevant when |
local_budget_first_level |
(optional) list of NLopt options used for the local stage at the first (coarsest) grid level. |
local_budget_refinement_levels |
(optional) list of NLopt options used for local refinement
on subsequent (finer) grid levels in multi-resolution strategies. If |
The returned object is an S3 class. Use summary() and as.data.frame()
methods to inspect.
an object of class "ldmppr_budgets".
ldmppr_grids-class for methods and details.
b <- ldmppr_budgets( global_options = list(maxeval = 150), local_budget_first_level = list(maxeval = 300, xtol_rel = 1e-5), local_budget_refinement_levels = list(maxeval = 150, xtol_rel = 1e-5) ) bb <- ldmppr_budgets( global_options = list(maxeval = 150), local_budget_first_level = list(maxeval = 300, xtol_rel = 1e-5), local_budget_refinement_levels = list(maxeval = 150, xtol_rel = 1e-5) ) b
Objects of class ldmppr_budgets define optimizer budget/options used by
estimate_process_parameters.
## S3 method for class 'ldmppr_budgets' print(x, ...) ## S3 method for class 'ldmppr_budgets' summary(object, ...) ## S3 method for class 'summary.ldmppr_budgets' print(x, ...) ## S3 method for class 'ldmppr_budgets' as.data.frame(x, ...) ## S3 method for class 'ldmppr_budgets' length(x) ## S3 method for class 'ldmppr_budgets' x[i, ...] ## S3 method for class 'ldmppr_budgets' as.list(x, ...)## S3 method for class 'ldmppr_budgets' print(x, ...) ## S3 method for class 'ldmppr_budgets' summary(object, ...) ## S3 method for class 'summary.ldmppr_budgets' print(x, ...) ## S3 method for class 'ldmppr_budgets' as.data.frame(x, ...) ## S3 method for class 'ldmppr_budgets' length(x) ## S3 method for class 'ldmppr_budgets' x[i, ...] ## S3 method for class 'ldmppr_budgets' as.list(x, ...)
x |
an object of class |
... |
unused. |
object |
an object of class |
i |
indices of local stages to keep: 1 = first level, 2 = refinement levels. |
A ldmppr_budgets is a list with (at minimum):
global_options: list of NLopt options for the global stage (e.g., maxeval, maxtime).
local_budget_first_level: list of NLopt options for the local stage at the first/coarsest grid level.
local_budget_refinement_levels: optional list of NLopt options for local refinement levels
(used only when estimate_process_parameters(strategy = "multires_global_local")).
print()prints a brief description of configured budgets.
summary()returns a summary.ldmppr_budgets.
as.data.frame()a compact table of the global/local budget entries (when present).
length()number of available local budget stages (1 or 2).
[ ]subset local budget stages (keeps global options).
as.list()returns the underlying list structure.
print(ldmppr_budgets): Print a brief summary of optimization budgets.
summary(ldmppr_budgets): Summarize an optimization budget specification.
print(summary.ldmppr_budgets): Print a summary produced by summary.ldmppr_budgets().
as.data.frame(ldmppr_budgets): Convert budgets to a data.frame.
length(ldmppr_budgets): Number of available local budget stages.
[: Subset local budget stages (keeps global options).
as.list(ldmppr_budgets): Extract the underlying list representation.
Objects of class ldmppr_fit are returned by estimate_process_parameters.
They contain the best-fitting optimization result (and optionally multiple fits,
e.g. from a delta search) along with metadata used to reproduce the fit.
## S3 method for class 'ldmppr_fit' print(x, ...) ## S3 method for class 'ldmppr_fit' coef(object, ...) ## S3 method for class 'ldmppr_fit' logLik(object, ...) ## S3 method for class 'ldmppr_fit' summary(object, ...) ## S3 method for class 'summary.ldmppr_fit' print(x, ...) ## S3 method for class 'ldmppr_fit' plot(x, ...) as_nloptr(x, ...) ## S3 method for class 'ldmppr_fit' as_nloptr(x, ...) ## S3 method for class 'ldmppr_fit' nobs(object, ...) ## S3 method for class 'ldmppr_fit' as.data.frame(x, ...)## S3 method for class 'ldmppr_fit' print(x, ...) ## S3 method for class 'ldmppr_fit' coef(object, ...) ## S3 method for class 'ldmppr_fit' logLik(object, ...) ## S3 method for class 'ldmppr_fit' summary(object, ...) ## S3 method for class 'summary.ldmppr_fit' print(x, ...) ## S3 method for class 'ldmppr_fit' plot(x, ...) as_nloptr(x, ...) ## S3 method for class 'ldmppr_fit' as_nloptr(x, ...) ## S3 method for class 'ldmppr_fit' nobs(object, ...) ## S3 method for class 'ldmppr_fit' as.data.frame(x, ...)
x |
an object of class |
... |
additional arguments (not used). |
object |
an object of class |
A ldmppr_fit is a list with (at minimum):
process: process name (e.g. "self_correcting")
fit: best optimization result (currently an nloptr object)
mapping: mapping information (e.g. chosen delta, objectives)
grid: grid definitions used by likelihood approximation
print()prints a brief summary of the fit.
coef()returns the estimated parameter vector.
logLik()returns the log-likelihood at the optimum.
summary()returns a summary.ldmppr_fit.
plot()plots diagnostics for multi-fit runs, if available.
print(ldmppr_fit): Print a brief summary of a fitted model.
coef(ldmppr_fit): Extract the estimated parameter vector.
logLik(ldmppr_fit): Log-likelihood at the optimum.
summary(ldmppr_fit): Summarize a fitted model.
plot(ldmppr_fit): Plot diagnostics for a fitted model.
as_nloptr(ldmppr_fit): Extract the underlying nloptr result.
nobs(ldmppr_fit): Number of observations used in the fitted model.
as.data.frame(ldmppr_fit): Coerce fit summary to a one-row data frame.
print(summary.ldmppr_fit): Print a summary produced by summary.ldmppr_fit.
as_nloptr(): Extract the underlying nloptr result.
ldmppr_grids() constructs a multi-resolution grid schedule used by
estimate_process_parameters. The returned object is an S3 class
with helper methods; see ldmppr_grids-class.
ldmppr_grids(upper_bounds, levels, labels = NULL, include_endpoints = TRUE)ldmppr_grids(upper_bounds, levels, labels = NULL, include_endpoints = TRUE)
upper_bounds |
a vector |
levels |
a list describing the grid schedule. Each entry can be either:
|
labels |
(optional) character vector of length equal to |
include_endpoints |
|
an object of class "ldmppr_grids".
ldmppr_grids-class for methods and details.
# A 3-level coarse-to-fine schedule (counts per dimension) g <- ldmppr_grids( upper_bounds = c(1, 50, 50), levels = list( c(25, 25, 25), c(75, 75, 75), c(100, 100, 100) ) ) g length(g) summary(g) # Explicit vectors (single level) g2 <- ldmppr_grids( upper_bounds = c(1, 50, 50), levels = list(list( x = seq(0, 50, by = 2), y = seq(0, 50, by = 2), t = seq(0, 1, length.out = 30) )) ) as.data.frame(g2)# A 3-level coarse-to-fine schedule (counts per dimension) g <- ldmppr_grids( upper_bounds = c(1, 50, 50), levels = list( c(25, 25, 25), c(75, 75, 75), c(100, 100, 100) ) ) g length(g) summary(g) # Explicit vectors (single level) g2 <- ldmppr_grids( upper_bounds = c(1, 50, 50), levels = list(list( x = seq(0, 50, by = 2), y = seq(0, 50, by = 2), t = seq(0, 1, length.out = 30) )) ) as.data.frame(g2)
Objects of class ldmppr_grids define one or more grid "levels" used by
estimate_process_parameters. Each level contains numeric vectors
x, y, and t defining the approximation grid. Levels are
typically ordered from coarse to fine.
## S3 method for class 'ldmppr_grids' print(x, ...) ## S3 method for class 'ldmppr_grids' summary(object, ...) ## S3 method for class 'summary.ldmppr_grids' print(x, ...) ## S3 method for class 'ldmppr_grids' as.data.frame(x, ...) ## S3 method for class 'ldmppr_grids' length(x) ## S3 method for class 'ldmppr_grids' x[i, ...] ## S3 method for class 'ldmppr_grids' as.list(x, ...)## S3 method for class 'ldmppr_grids' print(x, ...) ## S3 method for class 'ldmppr_grids' summary(object, ...) ## S3 method for class 'summary.ldmppr_grids' print(x, ...) ## S3 method for class 'ldmppr_grids' as.data.frame(x, ...) ## S3 method for class 'ldmppr_grids' length(x) ## S3 method for class 'ldmppr_grids' x[i, ...] ## S3 method for class 'ldmppr_grids' as.list(x, ...)
x |
an object of class |
... |
unused. |
object |
an object of class |
i |
indices of levels to keep. |
A ldmppr_grids is a list with (at minimum):
levels: list of levels; each level is a list with x, y, t
upper_bounds: numeric c(b_t, b_x, b_y)
labels: optional labels used only for printing
include_endpoints: logical
print()prints a brief description of bounds and grid levels.
summary()returns a summary.ldmppr_grids.
as.data.frame()returns one row per level with dimensions and ranges.
length()returns the number of levels.
[ ]subsets levels, preserving class.
as.list()returns the underlying list structure.
print(ldmppr_grids): Print a brief summary of a grid schedule.
summary(ldmppr_grids): Summarize a grid schedule.
print(summary.ldmppr_grids): Print a summary produced by summary.ldmppr_grids().
as.data.frame(ldmppr_grids): Convert a grid schedule to a data.frame.
length(ldmppr_grids): Number of levels in a grid schedule.
[: Subset grid levels.
as.list(ldmppr_grids): Extract the underlying list representation.
ldmppr_mark_model objects store a fitted mark model and preprocessing
information used to predict marks at new locations and times.
These objects are typically returned by train_mark_model and can be
saved/loaded with save_mark_model and load_mark_model.
ldmppr_mark_model( engine, fit_engine = NULL, xgb_raw = NULL, recipe = NULL, outcome = "size", feature_names = NULL, rasters = NULL, info = list() ) ## S3 method for class 'ldmppr_mark_model' print(x, ...) ## S3 method for class 'ldmppr_mark_model' summary(object, ...) ## S3 method for class 'summary.ldmppr_mark_model' print(x, ...) ## S3 method for class 'ldmppr_mark_model' predict( object, new_data = NULL, sim_realization = NULL, raster_list = NULL, scaled_rasters = FALSE, xy_bounds = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", seed = NULL, ... ) save_mark_model(object, path, ...) ## S3 method for class 'ldmppr_mark_model' save_mark_model(object, path, ...) load_mark_model(path)ldmppr_mark_model( engine, fit_engine = NULL, xgb_raw = NULL, recipe = NULL, outcome = "size", feature_names = NULL, rasters = NULL, info = list() ) ## S3 method for class 'ldmppr_mark_model' print(x, ...) ## S3 method for class 'ldmppr_mark_model' summary(object, ...) ## S3 method for class 'summary.ldmppr_mark_model' print(x, ...) ## S3 method for class 'ldmppr_mark_model' predict( object, new_data = NULL, sim_realization = NULL, raster_list = NULL, scaled_rasters = FALSE, xy_bounds = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", seed = NULL, ... ) save_mark_model(object, path, ...) ## S3 method for class 'ldmppr_mark_model' save_mark_model(object, path, ...) load_mark_model(path)
engine |
character string (currently |
fit_engine |
fitted engine object (e.g. |
xgb_raw |
raw xgboost payload (e.g. UBJ) used for rehydration. |
recipe |
a prepped recipes object used for preprocessing new data. |
outcome |
outcome column name (default |
feature_names |
(optional) vector of predictor names required at prediction time. |
rasters |
(optional) list of rasters used for prediction (e.g. for spatial covariates). |
info |
(optional) list of metadata. |
x |
an object of class |
... |
passed to methods. |
object |
a |
new_data |
a data frame of predictors (and possibly outcome columns).
Ignored when |
sim_realization |
optional simulation realization containing |
raster_list |
optional list of rasters used when |
scaled_rasters |
|
xy_bounds |
domain bounds |
include_comp_inds |
|
competition_radius |
positive numeric distance used when |
edge_correction |
edge correction for competition indices ( |
seed |
optional nonnegative integer seed. |
path |
path to an |
The model may be backed by different engines (currently "xgboost" and
"ranger"). For "xgboost", the object can store a serialized booster payload
to make saving/loading robust across R sessions.
print()prints a brief summary.
predict()returns numeric predictions for new data.
an object of class "ldmppr_mark_model".
print(ldmppr_mark_model): Print a brief summary of the mark model.
summary(ldmppr_mark_model): Summarize a mark model.
predict(ldmppr_mark_model): Predict marks for new data.
save_mark_model(ldmppr_mark_model): Save method for ldmppr_mark_model.
ldmppr_mark_model(): Create a mark model container.
print(summary.ldmppr_mark_model): Print a summary produced by summary.ldmppr_mark_model.
save_mark_model(): Save a mark model to disk.
load_mark_model(): Load a saved mark model from disk.
Objects of class ldmppr_model_check are returned by check_model_fit.
They contain global envelope test results and curve sets for multiple summary
functions/statistics.
## S3 method for class 'ldmppr_model_check' print(x, ...) ## S3 method for class 'ldmppr_model_check' summary(object, ...) ## S3 method for class 'summary.ldmppr_model_check' print(x, ...) ## S3 method for class 'ldmppr_model_check' plot(x, which = c("combined", "L", "F", "G", "J", "E", "V"), ...)## S3 method for class 'ldmppr_model_check' print(x, ...) ## S3 method for class 'ldmppr_model_check' summary(object, ...) ## S3 method for class 'summary.ldmppr_model_check' print(x, ...) ## S3 method for class 'ldmppr_model_check' plot(x, which = c("combined", "L", "F", "G", "J", "E", "V"), ...)
x |
an object of class |
... |
additional arguments passed to the underlying |
object |
an object of class |
which |
which envelope to plot. |
An ldmppr_model_check is a list with components such as:
combined_env: a global envelope test object (typically from **GET**)
envs: named list of envelope test objects (e.g., L, F, G, J, E, V)
curve_sets: named list of curve set objects
settings: list of settings used when generating envelopes (e.g., n_sim, thinning)
print()prints a brief summary of the diagnostic object.
summary()returns a summary.ldmppr_model_check object.
plot()plots the combined envelope or a selected statistic envelope.
print(ldmppr_model_check): Print a brief summary of the diagnostic results.
summary(ldmppr_model_check): Summarize p-values from the combined and individual envelopes.
plot(ldmppr_model_check): Plot the combined envelope or a selected statistic.
print(summary.ldmppr_model_check): Print a summary produced by summary.ldmppr_model_check.
ldmppr_sim objects are returned by simulate_mpp. They contain the simulated
realization, an associated marked point pattern object, and metadata used to
reproduce or inspect the simulation.
## S3 method for class 'ldmppr_sim' print(x, ...) ## S3 method for class 'ldmppr_sim' summary(object, ...) ## S3 method for class 'summary.ldmppr_sim' print(x, ...) ## S3 method for class 'ldmppr_sim' as.data.frame(x, ...) ## S3 method for class 'ldmppr_sim' nobs(object, ...) ## S3 method for class 'ldmppr_sim' plot(x, pattern_type = "simulated", ...) mpp.ldmppr_sim(x, ...)## S3 method for class 'ldmppr_sim' print(x, ...) ## S3 method for class 'ldmppr_sim' summary(object, ...) ## S3 method for class 'summary.ldmppr_sim' print(x, ...) ## S3 method for class 'ldmppr_sim' as.data.frame(x, ...) ## S3 method for class 'ldmppr_sim' nobs(object, ...) ## S3 method for class 'ldmppr_sim' plot(x, pattern_type = "simulated", ...) mpp.ldmppr_sim(x, ...)
x |
a |
... |
additional arguments (not used). |
object |
a |
pattern_type |
type of pattern to plot |
An ldmppr_sim is a list with at least:
process: process name (e.g. "self_correcting")
mpp: a marked point pattern object
realization: data.frame with columns time, x, y, marks
params, bounds, and other metadata
For methods:
print()prints a summary of the simulation.
summary()returns a summary.ldmppr_sim object.
plot()returns a ggplot visualization of the marked point pattern.
as.data.frame()returns the simulated realization as a data.frame.
nobs()returns the number of points in the realization.
mpp()returns the marked point pattern object.
print(ldmppr_sim): Print a brief summary of the simulation.
summary(ldmppr_sim): Summarize a simulated realization.
as.data.frame(ldmppr_sim): Coerce to a data.frame of the simulated realization.
nobs(ldmppr_sim): Number of simulated points.
plot(ldmppr_sim): Plot the simulated marked point pattern.
print(summary.ldmppr_sim): Print a summary produced by summary.ldmppr_sim.
mpp.ldmppr_sim(): Extract the underlying marked point pattern object.
A medium sized example dataset consisting of 111 observations in a (50m x 50m) square domain.
data("medium_example_data")data("medium_example_data")
## medium_example_data
A data frame with 111 rows and 3 columns:
x coordinate
y coordinate
Size
...
The dataset was generated using the Snodgrass dataset available at https://data.ess-dive.lbl.gov/view/doi:10.15485/2476543.
The full code to generate this dataset is available in the package's data_raw directory.
Real example dataset. Code to generate it can be found in data_raw/medium_example_data.R.
Plot a marked point process
plot_mpp(mpp_data, pattern_type = c("reference", "simulated"))plot_mpp(mpp_data, pattern_type = c("reference", "simulated"))
mpp_data |
|
pattern_type |
type of pattern to plot ( |
a ggplot object of the marked point process.
# Load example data data(small_example_data) mpp_data <- generate_mpp( locations = small_example_data %>% dplyr::select(x, y), marks = small_example_data$size, xy_bounds = c(0, 25, 0, 25) ) # Plot the marked point process plot_mpp(mpp_data, pattern_type = "reference")# Load example data data(small_example_data) mpp_data <- generate_mpp( locations = small_example_data %>% dplyr::select(x, y), marks = small_example_data$size, xy_bounds = c(0, 25, 0, 25) ) # Plot the marked point process plot_mpp(mpp_data, pattern_type = "reference")
Gentle decay (power-law) mapping function from sizes to arrival times
power_law_mapping(sizes, delta)power_law_mapping(sizes, delta)
sizes |
vector of sizes to be mapped to arrival times. |
delta |
numeric value (greater than 0) for the exponent in the mapping function. |
vector of arrival times.
# Generate a vector of sizes sizes <- runif(100, 0, 100) # Map the sizes to arrival times using a power-law mapping with delta = .5 power_law_mapping(sizes, .5)# Generate a vector of sizes sizes <- runif(100, 0, 100) # Map the sizes to arrival times using a power-law mapping with delta = .5 power_law_mapping(sizes, .5)
Prefer using the S3 method predict() on an ldmppr_mark_model:
predict(mark_model, sim_realization = ..., xy_bounds = ...).
This wrapper is retained for backward compatibility and is deprecated.
predict_marks( sim_realization, raster_list = NULL, scaled_rasters = FALSE, mark_model = NULL, xy_bounds = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", seed = NULL )predict_marks( sim_realization, raster_list = NULL, scaled_rasters = FALSE, mark_model = NULL, xy_bounds = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", seed = NULL )
sim_realization |
a data.frame containing a thinned or unthinned realization from
|
raster_list |
list of raster objects used for mark prediction. |
scaled_rasters |
|
mark_model |
a mark model object. May be an |
xy_bounds |
vector of domain bounds as |
include_comp_inds |
|
competition_radius |
positive numeric distance used when |
edge_correction |
type of edge correction to apply ( |
seed |
optional nonnegative integer seed for reproducibility. |
a vector of predicted mark values.
Scale a set of rasters
scale_rasters(raster_list, reference_resolution = NULL)scale_rasters(raster_list, reference_resolution = NULL)
raster_list |
a list of raster objects. |
reference_resolution |
the resolution to resample the rasters to. |
a list of scaled raster objects.
# Create two example rasters rast_a <- terra::rast( ncol = 10, nrow = 10, xmin = 0, xmax = 10, ymin = 0, ymax = 10, vals = runif(100) ) rast_b <- terra::rast( ncol = 10, nrow = 10, xmin = 0, xmax = 10, ymin = 0, ymax = 10, vals = runif(100) ) # Scale example rasters in a list rast_list <- list(rast_a, rast_b) scale_rasters(rast_list)# Create two example rasters rast_a <- terra::rast( ncol = 10, nrow = 10, xmin = 0, xmax = 10, ymin = 0, ymax = 10, vals = runif(100) ) rast_b <- terra::rast( ncol = 10, nrow = 10, xmin = 0, xmax = 10, ymin = 0, ymax = 10, vals = runif(100) ) # Scale example rasters in a list rast_list <- list(rast_a, rast_b) scale_rasters(rast_list)
Simulate a realization of a location dependent marked point process
simulate_mpp( process = c("self_correcting"), process_fit = NULL, t_min = 0, t_max = 1, anchor_point = NULL, raster_list = NULL, scaled_rasters = FALSE, mark_model = NULL, xy_bounds = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", thinning = TRUE, seed = NULL, mark_mode = NULL, size_range = NULL, delta = NULL )simulate_mpp( process = c("self_correcting"), process_fit = NULL, t_min = 0, t_max = 1, anchor_point = NULL, raster_list = NULL, scaled_rasters = FALSE, mark_model = NULL, xy_bounds = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", thinning = TRUE, seed = NULL, mark_mode = NULL, size_range = NULL, delta = NULL )
process |
type of process used (currently supports |
process_fit |
either (1) a |
t_min |
minimum value for time. |
t_max |
maximum value for time. |
anchor_point |
(optional) vector of (x,y) coordinates of the point to condition on.
If |
raster_list |
(optional) list of raster objects used for mark prediction.
Required when |
scaled_rasters |
|
mark_model |
a mark model object used when |
xy_bounds |
(optional) vector of bounds as |
include_comp_inds |
|
competition_radius |
positive numeric distance used when |
edge_correction |
type of edge correction to apply ( |
thinning |
|
seed |
integer seed for reproducibility. |
mark_mode |
(optional) mark generation mode: |
size_range |
numeric vector |
delta |
positive scalar used for |
an object of class "ldmppr_sim".
# Specify the generating parameters of the self-correcting process generating_parameters <- c(2, 8, .02, 2.5, 3, 1, 2.5, .2) # Specify an anchor point M_n <- c(10, 14) # Load the raster files raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE ) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) # Scale the rasters scaled_raster_list <- scale_rasters(rasters) # Load the example mark model file_path <- system.file("extdata", "example_mark_model.rds", package = "ldmppr") mark_model <- load_mark_model(file_path) # Simulate a realization example_mpp <- simulate_mpp( process = "self_correcting", process_fit = generating_parameters, t_min = 0, t_max = 1, anchor_point = M_n, raster_list = scaled_raster_list, scaled_rasters = TRUE, mark_model = mark_model, xy_bounds = c(0, 25, 0, 25), include_comp_inds = TRUE, competition_radius = 10, edge_correction = "none", thinning = TRUE, seed = 90210 ) # Plot the realization and provide a summary plot(example_mpp, pattern_type = "simulated") summary(example_mpp)# Specify the generating parameters of the self-correcting process generating_parameters <- c(2, 8, .02, 2.5, 3, 1, 2.5, .2) # Specify an anchor point M_n <- c(10, 14) # Load the raster files raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE ) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) # Scale the rasters scaled_raster_list <- scale_rasters(rasters) # Load the example mark model file_path <- system.file("extdata", "example_mark_model.rds", package = "ldmppr") mark_model <- load_mark_model(file_path) # Simulate a realization example_mpp <- simulate_mpp( process = "self_correcting", process_fit = generating_parameters, t_min = 0, t_max = 1, anchor_point = M_n, raster_list = scaled_raster_list, scaled_rasters = TRUE, mark_model = mark_model, xy_bounds = c(0, 25, 0, 25), include_comp_inds = TRUE, competition_radius = 10, edge_correction = "none", thinning = TRUE, seed = 90210 ) # Plot the realization and provide a summary plot(example_mpp, pattern_type = "simulated") summary(example_mpp)
Allows the user to simulate a realization from the self-correcting model given a set of parameters and a point to condition on.
simulate_sc( t_min = 0, t_max = 1, sc_params = NULL, anchor_point = NULL, xy_bounds = NULL )simulate_sc( t_min = 0, t_max = 1, sc_params = NULL, anchor_point = NULL, xy_bounds = NULL )
t_min |
minimum value for time. |
t_max |
maximum value for time. |
sc_params |
a vector of parameter values corresponding to
|
anchor_point |
a vector of (x,y) coordinates of point to condition on. |
xy_bounds |
a vector of domain bounds (2 for x, 2 for y). |
a list containing the thinned and unthinned simulation realizations.
# Specify the generating parameters of the self-correcting process generating_parameters <- c(2, 8, .02, 2.5, 3, 1, 2.5, .2) # Specify an anchor point M_n <- c(10, 14) # Simulate the self-correcting process generated_locs <- simulate_sc( t_min = 0, t_max = 1, sc_params = generating_parameters, anchor_point = M_n, xy_bounds = c(0, 25, 0, 25) )# Specify the generating parameters of the self-correcting process generating_parameters <- c(2, 8, .02, 2.5, 3, 1, 2.5, .2) # Specify an anchor point M_n <- c(10, 14) # Simulate the self-correcting process generated_locs <- simulate_sc( t_min = 0, t_max = 1, sc_params = generating_parameters, anchor_point = M_n, xy_bounds = c(0, 25, 0, 25) )
A small example dataset for testing and examples consisting of 121 observations in a (25m x 25m) square domain.
data("small_example_data")data("small_example_data")
## small_example_data
A data frame with 121 rows and 3 columns:
x coordinate
y coordinate
Size
...
The dataset was generated using the example raster data and an exponential decay size function.
The full code to generate this dataset is available in the package's data_raw directory.
Simulated dataset. Code to generate it can be found in data_raw/small_example_data.R.
calculates acceptance for thinning mechanism during simulation
thin_st_fast(data, params)thin_st_fast(data, params)
data |
NumericMatrix with columns (time, x, y). Assumed sorted by time ascending. |
params |
NumericVector length 3: (alpha3, beta3, gamma3 |
LogicalVector length n of whether to keep each point (true) or thin it (false).
Trains a predictive model for the mark distribution of a spatio-temporal process.
data may be either (1) a data.frame containing columns x, y, size and time,
(2) a data.frame containing x, y, size (time will be derived via delta),
or (3) a ldmppr_fit object returned by estimate_process_parameters.
Allows the user to incorporate location specific information and competition indices as covariates in the mark model.
train_mark_model( data, raster_list = NULL, scaled_rasters = FALSE, model_type = "xgboost", xy_bounds = NULL, delta = NULL, save_model = FALSE, save_path = NULL, parallel = FALSE, num_cores = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", selection_metric = "rmse", cv_folds = 5, tuning_grid_size = 200, seed = 0, verbose = TRUE )train_mark_model( data, raster_list = NULL, scaled_rasters = FALSE, model_type = "xgboost", xy_bounds = NULL, delta = NULL, save_model = FALSE, save_path = NULL, parallel = FALSE, num_cores = NULL, include_comp_inds = FALSE, competition_radius = 15, edge_correction = "none", selection_metric = "rmse", cv_folds = 5, tuning_grid_size = 200, seed = 0, verbose = TRUE )
data |
a data.frame or a |
raster_list |
list of raster objects used for mark-model training. |
scaled_rasters |
|
model_type |
the machine learning model type ( |
xy_bounds |
a vector of domain bounds (2 for x, 2 for y). If |
delta |
(optional) numeric scalar used only when |
save_model |
|
save_path |
path for saving the generated model. |
parallel |
|
num_cores |
number of workers to use when |
include_comp_inds |
|
competition_radius |
positive numeric distance used when |
edge_correction |
type of edge correction to apply ( |
selection_metric |
metric to use for identifying the optimal model ( |
cv_folds |
number of cross-validation folds to use in model training.
If |
tuning_grid_size |
size of the tuning grid for hyperparameter tuning. |
seed |
integer seed for reproducible resampling/tuning/model fitting. |
verbose |
|
an object of class "ldmppr_mark_model" containing the trained mark model.
# Load the small example data data(small_example_data) # Load example raster data raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE ) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) # Scale the rasters scaled_raster_list <- scale_rasters(rasters) # Train the model mark_model <- train_mark_model( data = small_example_data, raster_list = scaled_raster_list, scaled_rasters = TRUE, model_type = "xgboost", xy_bounds = c(0, 25, 0, 25), delta = 1, parallel = FALSE, include_comp_inds = FALSE, competition_radius = 10, edge_correction = "none", selection_metric = "rmse", cv_folds = 3, tuning_grid_size = 2, verbose = TRUE ) print(mark_model)# Load the small example data data(small_example_data) # Load example raster data raster_paths <- list.files(system.file("extdata", package = "ldmppr"), pattern = "\\.tif$", full.names = TRUE ) raster_paths <- raster_paths[!grepl("_med\\.tif$", raster_paths)] rasters <- lapply(raster_paths, terra::rast) # Scale the rasters scaled_raster_list <- scale_rasters(rasters) # Train the model mark_model <- train_mark_model( data = small_example_data, raster_list = scaled_raster_list, scaled_rasters = TRUE, model_type = "xgboost", xy_bounds = c(0, 25, 0, 25), delta = 1, parallel = FALSE, include_comp_inds = FALSE, competition_radius = 10, edge_correction = "none", selection_metric = "rmse", cv_folds = 3, tuning_grid_size = 2, verbose = TRUE ) print(mark_model)