View source: R/fps_weighting.R
| fps_weighting | R Documentation |
Computes covariate-balancing weights for a functional treatment using the empirical-likelihood balancing framework of Ciardulli, S. and Fontana, N. (2026). Treatment is represented via FPCA (Karhunen–Loeve expansion); The treatment is first represented via Functional Principal Component Analysis (FPCA) through its Karhunen–Loeve expansion truncated at rank L; the resulting FPC scores and observed confounders are balanced by solving the dual of the empirical-likelihood problem via the BFGS quasi-Newton algorithm. Functional covariates enter the balancing step through their own FPC scores.
fps_weighting(
treatment,
treat_grid = NULL,
treat_domain = NULL,
domain_name = "s",
nbasis = NULL,
pve = 0.95,
covariates,
cov_grids = NULL,
cov_domains = NULL,
cov_nbasis = NULL,
cov_pve = 0.95,
normalize = TRUE,
tol = 1e-08,
maxit = 1000
)
treatment |
n x T numeric matrix of observed treatment trajectories, or
an |
treat_grid |
Numeric vector of length T giving the observation grid
of the treatment. Required when |
treat_domain |
Numeric vector |
domain_name |
Character string naming the domain variable (default
|
nbasis |
Integer. Number of B-spline basis functions used for the
treatment FPCA. If |
pve |
Numeric in (0, 1]. Proportion of variance explained threshold for the treatment FPCA (default 0.95). |
covariates |
Either (a) an n x p numeric matrix of scalar covariates,
or (b) a named list with elements |
cov_grids |
A list of numeric vectors (one per functional covariate)
giving the observation grids. Required if |
cov_domains |
A list of numeric vectors |
cov_nbasis |
A list of integers (or |
cov_pve |
Numeric in (0, 1]. PVE threshold for functional covariate FPCA (default 0.95). |
normalize |
Logical. If |
tol |
Relative convergence tolerance for the BFGS optimiser (default 1e-8). |
maxit |
Maximum number of BFGS iterations (default 1000). |
An object of class "fps_weighting", which is a named list
with the following components:
Numeric vector of length n. Positive weights summing to 1.
List returned by the internal FPCA routine,
containing FPC scores (scr), eigenfunctions (efn), mean
function (mean), eigenvalues (eval), variance proportions
(varprop), cumulative PVE (perc), raw pca.fd
object (pca_fd), number of components retained (L), and
the t_grid and domain used.
List of FPCA results for functional covariates, or
NULL if none were supplied.
The n x p scalar covariate matrix used.
Full augmented confounder matrix fed to the optimiser (scalar covariates column-bound with FPC scores of functional covariates).
Convergence code from optim
(0 = success).
The domain name passed via domain_name.
The matched call.
fps_effect_estimation, simulate_fps_data
dat <- simulate_fps_data(n = 2000, setting = "LL", seed = 1)
# Scalar covariates only (treat_domain inferred from treat_grid)
w <- fps_weighting(
treatment = dat$X,
treat_grid = dat$t_grid,
covariates = dat$C
)
print(w)
plot(w, type = "balance")
# Include one functional covariate
w2 <- fps_weighting(
treatment = dat$X,
treat_grid = dat$t_grid,
treat_domain = c(0, 1),
covariates = list(scalar = dat$C, functional = list(dat$D)),
cov_grids = list(dat$t_grid)
)
plot(w2, type = "balance")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.