FRindex {Qindex} | R Documentation |
Functional Regression Indices & Weights
Description
Functions explained in this documentation are,
FRindex()
-
to compute the functional regression indices and weights based on the functional predictors.
predict.FRindex()
-
to compute the predicted values based on functional regression indices and weights model.
FR_gam()
-
a helper function to fit a functional regression model using generalized additive models with integrated smoothness estimation (gam).
Usage
FRindex(formula, data, sign_prob = 0.5, ...)
FR_gam(
formula,
data,
xarg = as.double(colnames(X)),
family,
knot_pct = 0.4,
knot.value = ceiling(length(xarg) * knot_pct),
...
)
## S3 method for class 'FRindex'
predict(
object,
newdata = object@data,
newX = newdata[[object@formula[[3L]]]],
new_xarg = as.double(colnames(newX)),
...
)
Arguments
formula |
a two-sided formula.
|
data |
data.frame, with
the response |
sign_prob |
double scalar between 0 and 1,
probability corresponding to the selected nearest-even quantile in |
... |
for function |
xarg |
strictly increasing double vector,
the common grid on which the functional predictor values |
family |
family object, the distribution
and link function to be used in gam.
Default family for Surv response is |
knot_pct |
positive double scalar,
percentage of the number of columns of |
knot.value |
positive integer scalar, number of knots
(i.e., parameter |
object |
an FRindex object for the predict method,
the returned object from function |
newdata |
data.frame, with at least
the tabulated functional predictor values |
newX |
double matrix,
functional predictor values |
new_xarg |
strictly increasing double vector,
the common grid on which the functional predictor values |
Details
Functional regression indices & weights model
Function FRindex()
defines and calculates
the functional regression indices and weights in the following steps.
Fit a functional regression model to the response
y
using the functional predictorX
, with tabulated tabulated on a same gridxarg
for all subjects, using helper functionFR_gam()
Select one point in the tabulating grid
xarg
. For one-dimensional domain, we select the nearest-even quantile of the tabulating gridxarg
, corresponding to the user-specified probabilitysign_prob
. Defaultsign_prob = .5
indicates the median ofxarg
.Obtain the fitted coefficient function
\hat\beta(x)
, tabulated on the gridxarg
, using internal helper functiongam2beta()
Calculate the integral of the product of the fitted coefficient function
\hat\beta(x)
(from Step 3) and the functional predictor valuesX
, using the trapzoid ruleObtain the sign of the correlation between
the subject-specific functional predictor values, at the selected quantile of
xarg
(from Step 2), andthe subject-specific integrals from Step 4
Functional regression weights (slot @weight
)
are the tabulated weight function on the grid xarg
.
These weights are defined as the product of
sign
(from Step 5) and \hat\beta(x)
(from Step 3).
Functional regression indices (slot @index
)
are defined as the product of
sign
(from Step 5) and intg
(from Step 4).
Multiplication by sign
is required to ensure
that the resulting functional regression indices
are positively associated with the functional predictor values
at the selected quantile of xarg
(from Step 2).
Predict method for functional regression indices & weights
Function predict.FRindex()
computes functional regression indices and weights
based on the tabulated functional predictors X^{new}
in a new sets of subjects.
It's important that the new tabulation grid new_xarg
must have the same range
as the model tabulation grid object@xarg
.
Then,
Obtain the fitted coefficient function
\hat\beta(x^{new})
of the existing generalized additive modelobject@gam
, but tabulated on the new gridnew_xarg
, using internal helper functiongam2beta()
Calculate the integral of the product of the fitted coefficient function
\hat\beta(x^{new})
(from Step 1) and the new functional predictor valuesX^{new}
, using the trapzoid rule
Predicted functional regression weights
are the tabulated weight function on the new grid new_xarg
.
These weights are defined as the product of
object@sign
and \hat\beta(x^{new})
(from Step 1).
Predicted functional regression indices
are defined as the product of
object@sign
and intg
(from Step 2).
Multiplication by object@sign
is required to ensure
that the resulting functional regression indices
are positively associated with the functional predictor values
at the selected quantile of object@xarg
.
Value
Functional regression indices & weights model
Function FRindex()
returns an S4 FRindex object.
The slots of S4 class FRindex are described in section Slots.
Predict method for functional regression indices & weights
Function predict.FRindex()
returns a
double vector,
which is the predicted functional regression indices.
The returned object contains an attributes
Slots
formula,data,xarg
see explanations in section Arguments
gam
sign
double scalar of either 1 or -1, see Step 5 in section Details on function
FRindex()
index,weight
double vectors, functional regression indices and functional regression weights, respectively. See section Details on function
FRindex()
Using ...
in FRindex()
Function FRindex()
passes the parameters
xarg
, family
, knot_pct
and knot.value
into helper function FR_gam()
through three dots ...
.
The most important parameter among them is xarg
.
The default argument of the parameter xarg
comes
from the column names of the matrix of
tabulated functional predictor values X
.
This is particularly convenient when
the functional predictor is the quantile function,
and data
is the returned object of function clusterQp()
.
Both FRindex()
and helper function FR_gam()
accept user-provided xarg
.
In such case, the provided values will be checked such that
-
length of
xarg
is the same as the number of columns of matrixX
-
xarg
must be strictly sorted (see is.unsorted)
Otherwise, an error message will be returned.
Details of Helper Function
Helper function FR_gam()
uses gam to estimate the functional coefficient by fitting functional regression model.
Returns of Helper Functions
Helper function FR_gam()
returns a gam object, with additional attributes
attr(,'X')
attr(,'xarg')
References
Cui, E., Crainiceanu, C. M., & Leroux, A. (2021). Additive Functional Cox Model. Journal of Computational and Graphical Statistics. doi:10.1080/10618600.2020.1853550
Gellar, J. E., Colantuoni, E., Needham, D. M., & Crainiceanu, C. M. (2015). Cox regression models with functional covariates for survival data. Statistical Modelling. doi:10.1177/1471082X14565526
Examples
library(survival)
pt = unique(Ki67$PATIENT_ID)
length(pt) # 622
# set.seed if necessary
train_pt = sample(pt, size = 500L)
Ki67q = clusterQp(Marker ~ ., data = Ki67, exclude = c('tissueID','inner_x','inner_y'))
train_q = subset(Ki67q, PATIENT_ID %in% train_pt)
test_q = subset(Ki67q, !(PATIENT_ID %in% train_pt))
train_q$Marker = log1p(train_q$Marker)
test_q$Marker = log1p(test_q$Marker)
FRi = FRindex(Surv(RECFREESURV_MO, RECURRENCE) ~ Marker, data = train_q)
FRi@index # functional regression index
FRi@weight # functional regression weights
head(show(FRi)) # append `FRi` to the data
(FRi_test = predict(FRi, newdata = test_q))
FRi_train = predict(FRi)
# stopifnot(identical(FRi@index, c(FRi_train)),
# identical(FRi@weight, attr(FRi_train, 'weight')))
# set.seed if necessary
Ki67bbc_v2 = BBC_dichotom(Surv(RECFREESURV_MO, RECURRENCE) ~ NodeSt + Tstage,
data = data.frame(train_q, FRi_std = std_IQR(FRi_train)),
dichotom = ~ FRi_std)
summary(Ki67bbc_v2)
Ki67q = clusterQp(Marker ~ ., data = Ki67, exclude = c('tissueID','inner_x','inner_y'))
Ki67q$Marker = log1p(Ki67q$Marker)
library(survival)
FR_gam(Surv(RECFREESURV_MO, RECURRENCE) ~ Marker, data = Ki67q)