| Title: | Hierarchical Gaussian Processes for 'adlaplace' |
|---|---|
| Description: | Hierarchical and random-slope integrated Wiener process model terms for use with the adlaplace Laplace approximation framework. Provides hiwp, rsiwp, rsiid, rsfpoly, and rsrpoly constructors plus conditional simulation utilities for IWP-style smooths. |
| Authors: | Patrick Brown [aut, cre, cph] |
| Maintainer: | Patrick Brown <[email protected]> |
| License: | MPL-2.0 |
| Version: | 0.5.2 |
| Built: | 2026-07-17 23:35:58 UTC |
| Source: | https://github.com/eborgnine/adlaplace |
Draw conditional simulations of the Gaussian process model components, then summarize the resulting linear predictors and group-level effect curves.
cond_sim_iwp( fit, model_data, newx = NULL, n = 500, weights = NULL, probs = c(0.025, 0.5, 0.975), probs_envelope = c(0.1, 0.9) )cond_sim_iwp( fit, model_data, newx = NULL, n = 500, weights = NULL, probs = c(0.025, 0.5, 0.975), probs_envelope = c(0.1, 0.9) )
fit |
Output of |
model_data |
Output of |
newx |
Optional list of prediction data frames, one per variable.
When |
n |
Number of conditional draws to simulate. |
weights |
Optional weights used to average group-level effects. |
probs |
Numeric vector of probabilities used when computing quantiles. |
probs_envelope |
Numeric vector of probabilities for envelopes. |
A list with components sim, quantiles, and envelope.
cond_sim_iwp_at, cond_sim_iwp_inputs
Draw conditional simulations of IWP/HIWP/RSIWP model components from explicit
inputs. Prefer cond_sim_iwp when you have a Laplace fit
and model_data objects; use this function for custom pipelines.
cond_sim_iwp_at( terms, random_info, beta, gamma_mode, half_H_inv, newx = NULL, n = 500, weights = NULL, probs = c(0.025, 0.5, 0.975), probs_envelope = c(0.1, 0.9) )cond_sim_iwp_at( terms, random_info, beta, gamma_mode, half_H_inv, newx = NULL, n = 500, weights = NULL, probs = c(0.025, 0.5, 0.975), probs_envelope = c(0.1, 0.9) )
terms |
Named list of model term objects from |
random_info |
Data frame from |
beta |
Named numeric vector of fixed-effect MLEs, or a data frame with
columns |
gamma_mode |
Named numeric vector of random-effect modes at the Laplace
inner optimum, or a data frame with columns |
half_H_inv |
Matrix |
newx |
Optional list of prediction data frames, one per variable.
When |
n |
Number of conditional draws. |
weights |
Optional group weights (named vector or list by variable). |
probs |
Quantile levels for summaries. |
probs_envelope |
Envelope probability levels (requires GET). |
List with simulated curves, quantiles, and envelopes.
Extracts flat arguments for cond_sim_iwp_at from the output of
log_lik_laplace and model_data.
cond_sim_iwp_inputs(laplace, model_data)cond_sim_iwp_inputs(laplace, model_data)
laplace |
Output of |
model_data |
Output of |
A list with terms, random_info, beta,
gamma_mode, and half_H_inv.
Creates and manages hierarchical integrated Wiener process (HIWP) model terms.
hiwp( x, p = 2, ref_value = 0, knots, by, init = NULL, lower = NULL, upper = NULL, parscale = NULL, boundary_is_random = TRUE, include_poly = TRUE, include_global = TRUE ) ## S4 method for signature 'hiwp' design(term, data) ## S4 method for signature 'hiwp' precision(term, data) ## S4 method for signature 'hiwp' theta_info(term) ## S4 method for signature 'hiwp' beta_info(term, data) ## S4 method for signature 'hiwp' random_info(term, data)hiwp( x, p = 2, ref_value = 0, knots, by, init = NULL, lower = NULL, upper = NULL, parscale = NULL, boundary_is_random = TRUE, include_poly = TRUE, include_global = TRUE ) ## S4 method for signature 'hiwp' design(term, data) ## S4 method for signature 'hiwp' precision(term, data) ## S4 method for signature 'hiwp' theta_info(term) ## S4 method for signature 'hiwp' beta_info(term, data) ## S4 method for signature 'hiwp' random_info(term, data)
x |
Variable name |
p |
Order of the integrated Wiener process (default: 2) |
ref_value |
Reference value for the basis |
knots |
Vector of knot locations |
by |
Grouping variable for hierarchical structure |
init |
Initial values for theta parameters |
lower |
Lower bounds for theta parameters |
upper |
Upper bounds for theta parameters |
parscale |
Parameter scales for optimization |
boundary_is_random |
Whether boundary should be treated as random |
include_poly |
Whether to include polynomial terms |
include_global |
Whether to include global component |
term |
An |
data |
A data frame containing the variables used in the term. |
Hierarchical Integrated Wiener Process Model Term
A list containing hiwp term object and optionally related terms
A design matrix for the HIWP term.
A precision matrix for the HIWP term.
A data frame containing theta parameter information for the HIWP term.
NULL (HIWP terms don't have beta parameters).
A data frame containing random effects information for the HIWP term.
The following methods are available for hiwp objects:
design(term, data)Creates design matrix for HIWP term
precision(term, data)Creates precision matrix for HIWP term
theta_info(term)Extracts theta parameter information
beta_info(term, data)Extracts beta parameter information
random_info(term, data)Extracts random effects information
# Example usage: # knots <- seq(0, 1, length.out = 5) # hiwp_term <- hiwp(x = "age", knots = knots, by = "group")# Example usage: # knots <- seq(0, 1, length.out = 5) # hiwp_term <- hiwp(x = "age", knots = knots, by = "group")
Creates and manages hierarchical random polynomial model terms.
Creates a hierarchical random polynomial model term.
hrpoly( x, p = 1, ref_value = 0, by, init = NULL, lower = NULL, upper = NULL, parscale = NULL ) ## S4 method for signature 'hrpoly' design(term, data) ## S4 method for signature 'hrpoly' precision(term, data) ## S4 method for signature 'hrpoly' theta_info(term) ## S4 method for signature 'hrpoly' beta_info(term, data) ## S4 method for signature 'hrpoly' random_info(term, data)hrpoly( x, p = 1, ref_value = 0, by, init = NULL, lower = NULL, upper = NULL, parscale = NULL ) ## S4 method for signature 'hrpoly' design(term, data) ## S4 method for signature 'hrpoly' precision(term, data) ## S4 method for signature 'hrpoly' theta_info(term) ## S4 method for signature 'hrpoly' beta_info(term, data) ## S4 method for signature 'hrpoly' random_info(term, data)
x |
Variable name. |
p |
Polynomial degree (default: 1). |
ref_value |
Reference value for the polynomial. |
by |
Grouping variable for hierarchical structure. |
init |
Initial value for theta parameter. |
lower |
Lower bound for theta parameter. |
upper |
Upper bound for theta parameter. |
parscale |
Parameter scale for optimization. |
term |
An |
data |
A data frame containing the variables used in the term. |
An hrpoly term object.
A design matrix for the hrpoly term.
A precision matrix for the hrpoly term.
A data frame containing theta parameter information for the hrpoly term.
NULL (hrpoly terms don't have beta parameters).
A data frame containing random effects information for the hrpoly term.
The following methods are available for hrpoly objects:
design(term, data)Creates design matrix for hrpoly term
precision(term, data)Creates precision matrix for hrpoly term
theta_info(term)Extracts theta parameter information
beta_info(term, data)Extracts beta parameter information
random_info(term, data)Extracts random effects information
# Create an hrpoly term for variable 'age' with grouping by 'site' term <- hrpoly(x = "age", p = 2, ref_value = 0, by = "site") str(term) # Create sample data set.seed(42) dat <- data.frame( age = rep(seq(0, 80, by = 10), each = 3), site = rep(c("A", "B", "C"), times = 9) ) by_group(term@by@term, dat) # Compute the design matrix design_mat <- design(term, dat) print(design_mat)# Create an hrpoly term for variable 'age' with grouping by 'site' term <- hrpoly(x = "age", p = 2, ref_value = 0, by = "site") str(term) # Create sample data set.seed(42) dat <- data.frame( age = rep(seq(0, 80, by = 10), each = 3), site = rep(c("A", "B", "C"), times = 9) ) by_group(term@by@term, dat) # Compute the design matrix design_mat <- design(term, dat) print(design_mat)
Creates a fixed polynomial model term for random slope models.
rsfpoly( x, mult, p = 2, ref_value = 0, ref_mult = 0, init = NULL, lower = NULL, upper = NULL, parscale = NULL ) ## S4 method for signature 'rsfpoly' design(term, data) ## S4 method for signature 'rsfpoly' precision(term, data) ## S4 method for signature 'rsfpoly' theta_info(term) ## S4 method for signature 'rsfpoly' beta_info(term, data) ## S4 method for signature 'rsfpoly' random_info(term, data)rsfpoly( x, mult, p = 2, ref_value = 0, ref_mult = 0, init = NULL, lower = NULL, upper = NULL, parscale = NULL ) ## S4 method for signature 'rsfpoly' design(term, data) ## S4 method for signature 'rsfpoly' precision(term, data) ## S4 method for signature 'rsfpoly' theta_info(term) ## S4 method for signature 'rsfpoly' beta_info(term, data) ## S4 method for signature 'rsfpoly' random_info(term, data)
x |
Variable name. |
mult |
Variable to multiply the polynomial by. |
p |
Polynomial degree (default: 2). |
ref_value |
Reference value for the polynomial. |
ref_mult |
Reference value for the covariate. |
init |
Initial values for beta parameters. |
lower |
Lower bounds for beta parameters. |
upper |
Upper bounds for beta parameters. |
parscale |
Parameter scales for optimization. |
term |
A rsfpoly term object |
data |
A data frame containing the term variables |
A rsfpoly term object.
A design matrix for the random slope fixed polynomial term, or NULL if p.order is 0
NULL (fixed effects don't have precision matrices)
NULL (fixed effects don't have theta parameters)
A data frame containing beta parameter information for the random slope fixed polynomial term
NULL (fixed effects don't have random effects information)
design(rsfpoly): Creates design matrix for rsfpoly term
precision(rsfpoly): Creates precision matrix for rsfpoly term
theta_info(rsfpoly): Extracts theta parameter information for rsfpoly term
beta_info(rsfpoly): Extracts beta parameter information for rsfpoly term
random_info(rsfpoly): Extracts random effects information for rsfpoly term
The following methods are available for rsfpoly objects:
design(term, data)Creates design matrix for rsfpoly term
precision(term, data)Creates precision matrix for rsfpoly term
theta_info(term)Extracts theta parameter information
beta_info(term, data)Extracts beta parameter information
random_info(term, data)Extracts random effects information
Creates an iid random slope model term
rsiid( x, mult, ref_mult = 0, init = NULL, lower = NULL, upper = NULL, parscale = NULL ) ## S4 method for signature 'rsiid' design(term, data) ## S4 method for signature 'rsiid' precision(term, data) ## S4 method for signature 'rsiid' theta_info(term) ## S4 method for signature 'rsiid' beta_info(term, data) ## S4 method for signature 'rsiid' random_info(term, data)rsiid( x, mult, ref_mult = 0, init = NULL, lower = NULL, upper = NULL, parscale = NULL ) ## S4 method for signature 'rsiid' design(term, data) ## S4 method for signature 'rsiid' precision(term, data) ## S4 method for signature 'rsiid' theta_info(term) ## S4 method for signature 'rsiid' beta_info(term, data) ## S4 method for signature 'rsiid' random_info(term, data)
x |
Variable name. |
mult |
Variable to multiply the polynomial by. |
ref_mult |
Reference value for the covariate. |
init |
Initial values for beta parameters. |
lower |
Lower bounds for beta parameters. |
upper |
Upper bounds for beta parameters. |
parscale |
Parameter scales for optimization. |
term |
A rsiid term object |
data |
A data frame containing the term variables |
A rsiid term object.
A design matrix for the random slope polynomial term, or NULL if p.order is 0
A precision matrix for the random slope polynomial term
A data frame containing theta parameter information for the random slope term
NULL (random slope polynomial terms don't have beta parameters)
A data frame containing random effects information for the random slope polynomial term
design(rsiid): Creates design matrix for rsiid term
precision(rsiid): Creates precision matrix for rsiid term
theta_info(rsiid): Extracts theta parameter information for rsiid term
beta_info(rsiid): Extracts beta parameter information for rsiid term
random_info(rsiid): Extracts random effects information for rsiid term
The following methods are available for rsiid objects:
design(term, data)Creates design matrix for rsiid term
precision(term, data)Creates precision matrix for rsiid term
theta_info(term)Extracts theta parameter information
beta_info(term, data)Extracts beta parameter information
random_info(term, data)Extracts random effects information
Creates a random slope integrated Wiener process (RSIWP) model term.
rsiwp( x, mult, p = 2, ref_value = 0, ref_mult = 0, knots, init = NULL, lower = NULL, upper = NULL, parscale = NULL, boundary_is_random = TRUE, include_poly = TRUE, include_linear = TRUE )rsiwp( x, mult, p = 2, ref_value = 0, ref_mult = 0, knots, init = NULL, lower = NULL, upper = NULL, parscale = NULL, boundary_is_random = TRUE, include_poly = TRUE, include_linear = TRUE )
x |
Variable name. |
mult |
Variable to multiply the IWP by. |
p |
Order of the integrated Wiener process (default: 2). |
ref_value |
Reference value for the basis. |
ref_mult |
Reference value for the covariate. |
knots |
Vector of knot locations. |
init |
Initial values for theta parameters. |
lower |
Lower bounds for theta parameters. |
upper |
Upper bounds for theta parameters. |
parscale |
Parameter scales for optimization. |
boundary_is_random |
Whether boundary should be treated as random. |
include_poly |
Whether to include polynomial terms. |
include_linear |
Whether to include a linear (fixed) term in |
A list containing the rsiwp term object and optionally polynomial terms.
Creates and manages random slope integrated Wiener process (RSIWP) model terms.
## S4 method for signature 'rsiwp' design(term, data) ## S4 method for signature 'rsiwp' precision(term, data) ## S4 method for signature 'rsiwp' theta_info(term) ## S4 method for signature 'rsiwp' beta_info(term, data) ## S4 method for signature 'rsiwp' random_info(term, data)## S4 method for signature 'rsiwp' design(term, data) ## S4 method for signature 'rsiwp' precision(term, data) ## S4 method for signature 'rsiwp' theta_info(term) ## S4 method for signature 'rsiwp' beta_info(term, data) ## S4 method for signature 'rsiwp' random_info(term, data)
term |
An rsiwp term object |
data |
A data frame containing the term variable |
design(rsiwp): Creates design matrix for RSIWP term
precision(rsiwp): Creates precision matrix for RSIWP term
theta_info(rsiwp): Extracts theta parameter information for RSIWP term
beta_info(rsiwp): Extracts beta parameter information for RSIWP term
random_info(rsiwp): Extracts random effects information for RSIWP term
The following methods are available for rsiwp objects:
design(term, data)Creates design matrix for RSIWP term
precision(term, data)Creates precision matrix for RSIWP term
theta_info(term)Extracts theta parameter information
beta_info(term, data)Extracts beta parameter information
random_info(term, data)Extracts random effects information
Creates a random polynomial model term for use in a random slope model.
rsrpoly(x, mult, p = 2, ref_value = 0, ref_mult = 0, sd = Inf) ## S4 method for signature 'rsrpoly' design(term, data) ## S4 method for signature 'rsrpoly' precision(term, data) ## S4 method for signature 'rsrpoly' theta_info(term) ## S4 method for signature 'rsrpoly' beta_info(term, data) ## S4 method for signature 'rsrpoly' random_info(term, data)rsrpoly(x, mult, p = 2, ref_value = 0, ref_mult = 0, sd = Inf) ## S4 method for signature 'rsrpoly' design(term, data) ## S4 method for signature 'rsrpoly' precision(term, data) ## S4 method for signature 'rsrpoly' theta_info(term) ## S4 method for signature 'rsrpoly' beta_info(term, data) ## S4 method for signature 'rsrpoly' random_info(term, data)
x |
Variable name. |
mult |
Variable to multiply the polynomial by. |
p |
Polynomial degree (default: 2). |
ref_value |
Reference value for the polynomial. |
ref_mult |
Reference value for the covariate. |
sd |
Standard deviation for random effects. |
term |
A rsrpoly term object |
data |
A data frame containing the term variables |
A rsrpoly term object.
A design matrix for the random slope polynomial term, or NULL if p.order is 0
A precision matrix for the random slope polynomial term
NULL (random slope polynomial terms don't have theta parameters)
NULL (random slope polynomial terms don't have beta parameters)
A data frame containing random effects information for the random slope polynomial term
design(rsrpoly): Creates design matrix for rsrpoly term
precision(rsrpoly): Creates precision matrix for rsrpoly term
theta_info(rsrpoly): Extracts theta parameter information for rsrpoly term
beta_info(rsrpoly): Extracts beta parameter information for rsrpoly term
random_info(rsrpoly): Extracts random effects information for rsrpoly term
The following methods are available for rsrpoly objects:
design(term, data)Creates design matrix for rsrpoly term
precision(term, data)Creates precision matrix for rsrpoly term
theta_info(term)Extracts theta parameter information
beta_info(term, data)Extracts beta parameter information
random_info(term, data)Extracts random effects information