sim_vcpsr  R Documentation 
sim_vcpsr
is a varyingcoefficient singleindex
signal regression approach that allows both the signal coefficients
and the unknown link function to vary with
an indexing variable t
, e.g. temperature. Two surfaces
are estimated (coefficent and link) that can be sliced at arbitary t
.
Anisotripic penalization with Psplines is used on both.
sim_vcpsr(
y,
X,
t_var,
x_index = c(1:ncol(X)),
nsegs = rep(10, 4),
bdegs = rep(3, 4),
lambdas = rep(1, 4),
pords = rep(2, 4),
max_iter = 100,
mins = c(min(x_index), min(t_var)),
maxs = c(max(x_index), max(t_var))
)
y 
a response vector of length 
X 
the signal regressors with dimension 
t_var 
the varying coeffient indexing variable of length 
x_index 
an index of length 
nsegs 
a vector of length 4 containing
the number of evenly spaced segments between min and max, for each
the coefficient surface (row and col) and
link surface (row and col), resp. (default 
bdegs 
a vector of length 4 containing
the degree of Bsplines, for each
the coefficient surface (row and col) and link surface (row and col), resp.
(default cubic 
lambdas 
a vector of length 4 containing
the positive tuning parameters, for each
the coefficient surface (row and col) and link surface (row and col), resp.
(default 
pords 
a vector of length 4 containing
the difference penalty order, for each
the coefficient surface (row and col) and link surface (row and col), resp.
(default 
max_iter 
a scalar for the maximum number of iterations (default 100) 
mins 
A vector length 2, containing min for signal index and 
maxs 
A vector length 2, containing max for signal index and 
y 
the response vector of length 
alpha 
the Pspline coefficient vector (unfolded) of length 
iter 
the number of iterations used for the singleindex fit. 
yint 
the estimated yintercept for the singleindex model. 
Bx 
the Bspline matrix built along the signal index, using 
By 
the Bspline matrix built along the 
Q 
the effective regressors from the 
t_var 
the VC indexing variable of length 
nsegs 
a vector of length 4 containing the number of evenly spaced segments between min and max, for each the coefficient surface (row and col) and link surface (row and col). 
bdegs 
a vector of length 4 containing the degree of Bsplines, for each the coefficient surface (row and col) and link surface (row and col). 
lambdas 
a vector of length 4 containing the positive tuning parameters, for each the coefficient surface (row and col) and link surface (row and col). 
pords 
a vector of length 4 containing the difference penalty order, for each the coefficient surface (row and col) and link surface (row and col). 
mins 
a vector length 2, containing min for signal index and 
maxs 
a vector length 2, containing max for signal index and 
eta 
the estimated linear predictor for the singleindex fit. 
Pars 
a matrix of 2 rows associated with the signal coefficient surface
design parameters, each row: 
pPars 
a matrix of 2 rows associated with the link function
design parameters, each row: 
cv 
the leaveoneout crossvalidation statistic or the standard error of prediction for the singleindex fit. 
delta_alpha 
change measure in signalcoefficent parameters at convergence. 
fit2D 

Paul Eilers and Brian Marx
Marx, B. D. (2015). Varyingcoefficient singleindex signal regression. Chemometrics and Intelligent Laboratory Systems, 143, 111–121.
Eilers, P.H.C. and Marx, B.D. (2021). Practical Smoothing, The Joys of Psplines. Cambridge University Press.
# Load libraries
library(fields) # Needed for plotting
# Get the data
Dat < Mixture
# Dimensions: observations, temperature index, signal
m < 34
p1 < 401
p2 < 12
# Stacking mixture data, each mixture has 12 signals stacked
# The first differenced spectra are also computed.
mixture_data < matrix(0, nrow = p2 * m, ncol = p1)
for (ii in 1:m)
{
mixture_data[((ii  1) * p2 + 1):(ii * p2), 1:p1] <
t(as.matrix(Dat$xspectra[ii, , ]))
d_mixture_data < t(diff(t(mixture_data)))
}
# Response (typo fixed) and index for signal
y_mixture < Dat$fractions
y_mixture[17, 3] < 0.1501
index_mixture < Dat$wl
# Select response and replicated for the 12 temps
# Column 1: water; 2: ethanediol; 3: amino1propanol
y < as.vector(y_mixture[, 2])
y < rep(y, each = p2)
bdegs = c(3, 3, 3, 3)
pords < c(2, 2, 2, 2)
nsegs < c(12, 5, 5, 5) # Set to c(27, 7, 7 ,7) for given lambdas
mins < c(700, 30)
maxs < c(1100, 70)
lambdas < c(1e11, 100, 0.5, 1) # based on svcm search
x_index < seq(from = 701, to = 1100, by = 1) # for dX
t_var_sub < c(30, 35, 37.5, 40, 45, 47.5, 50, 55, 60, 62.5, 65, 70)
t_var < rep(t_var_sub, m)
max_iter < 2 # Set higher in practice, e.g. 100
int < TRUE
# Defining x as first differenced spectra, number of channels.
x < d_mixture_data
# Singleindex VC model using optimal tuning
fit < sim_vcpsr(y, x, t_var, x_index, nsegs, bdegs, lambdas, pords,
max_iter = max_iter, mins = mins, maxs = maxs)
plot(fit, xlab = "Wavelength (nm)", ylab = "Temp C")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.