Description Usage Arguments Details Value Author(s) Examples
View source: R/register_fpca.R
Function combines constrained optimization and GFPCA to estimate warping functions for
exponential family curves. See argument family
for which families are
supported. Warping functions are calculated by the function registr
.
The GFPCA step can be performed either using the variational EM-based GFPCA
approaches of Wrobel et al. (2019) (fpca_type = "variationalEM"
, default)
or the mixed model-based two-step approach of Gertheiss et al. (2017)
(fpca_type = "two-step"
).
Warping functions by default are forced to start and end on the diagonal to be
domain-preserving. This behavior can be changed by setting
incompleteness
to some other value than NULL and a reasonable lambda_inc
value.
For further details see the accompanying vignette.
The number of functional principal components (FPCs) can either be specified
directly (argument npc
) or chosen based on the explained share of
variance in each iteration (argument npc_criterion
).
By specifying cores > 1
the registration call can be parallelized.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | register_fpca(
Y,
Kt = 8,
Kh = 4,
family = "gaussian",
incompleteness = NULL,
lambda_inc = NULL,
Y_template = NULL,
max_iterations = 10,
npc = NULL,
npc_criterion = NULL,
fpca_type = "variationalEM",
fpca_maxiter = 50,
fpca_seed = 1988,
fpca_error_thresh = 1e-04,
fpca_index_significantDigits = 4L,
cores = 1L,
verbose = 1,
...
)
|
Y |
Dataframe. Should have values id, value, index. |
Kt |
Number of B-spline basis functions used to estimate mean functions
and functional principal components. Default is 8. If
|
Kh |
Number of B-spline basis functions used to estimate warping functions h. Default is 4. |
family |
One of |
incompleteness |
Optional specification of incompleteness structure.
One of |
lambda_inc |
Penalization parameter to control the amount of
overall dilation of the domain.
The higher this lambda, the more the registered domains are forced to have the
same length as the observed domains.
Only used if |
Y_template |
Optional dataframe with the same structure as |
max_iterations |
Number of iterations for overall algorithm. Defaults to 10. |
npc, npc_criterion |
The number of functional principal components (FPCs)
has to be specified either directly as |
fpca_type |
One of |
fpca_maxiter |
Only used if |
fpca_seed |
Only used if |
fpca_error_thresh |
Only used if |
fpca_index_significantDigits |
Only used if |
cores |
Number of cores to be used. If |
verbose |
Can be set to integers between 0 and 4 to control the level of detail of the printed diagnostic messages. Higher numbers lead to more detailed messages. Defaults to 1. |
... |
Additional arguments passed to registr and to the gfpca functions
(if |
Requires input data Y
to be a dataframe in long format with variables
id
, index
, and value
to indicate subject IDs,
observation times on the domain, and observations, respectively.
One joint iteration consists of a GFPCA step and a registration step.
As preprocessing, one initial registration step is performed.
The template function for this registration step is defined by argument
Y_template
.
After convergence or max_iterations
is reached, one final GFPCA step
is performed.
An object of class registration
containing:
Y |
The observed data plus variables |
fpca_obj |
List of items from FPCA step. |
family |
Used exponential family. |
index_warped |
List of the (warped) index values for each iteration.
Has |
hinv_innerKnots |
List of inner knots for setting up the spline bases
for the inverse warping functions. Only contains |
hinv_beta |
Matrix of B-spline basis coefficients used to construct the
subject-specific inverse warping functions. From the last performed
registration step. For details see |
convergence |
List with information on the convergence of the joint
approach. Containing the following elements: |
Julia Wrobel julia.wrobel@cuanschutz.edu Jeff Goldsmith ajg2202@cumc.columbia.edu, Alexander Bauer alexander.bauer@stat.uni-muenchen.de
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | ### complete binomial curves
Y = simulate_unregistered_curves(I = 20, D = 200)
# estimation based on Wrobel et al. (2019)
reg = register_fpca(Y, npc = 2, family = "binomial",
fpca_type = "variationalEM", max_iterations = 5)
if (requireNamespace("ggplot2", quietly = TRUE)) {
library(ggplot2)
ggplot(reg$Y, aes(x = tstar, y = t_hat, group = id)) +
geom_line(alpha = 0.2) + ggtitle("Estimated warping functions")
plot(reg$fpca_obj, response_function = function(x) { 1 / (1 + exp(-x)) })
}
# estimation based on Gertheiss et al. (2017)
reg2 = register_fpca(Y, npc = 2, family = "binomial",
fpca_type = "two-step", max_iterations = 5,
fpca_index_significantDigits = 4)
# example using accelerometer data from nhanes 2003-2004 study
data(nhanes)
nhanes_short = nhanes[nhanes$id %in% unique(nhanes$id)[1:5],]
reg_nhanes = register_fpca(nhanes_short, npc = 2, family = "binomial", max_iterations = 5)
### incomplete Gaussian curves
data(growth_incomplete)
# Force the warping functions to start and end on the diagonal
reg2a = register_fpca(growth_incomplete, npc = 2, family = "gaussian",
incompleteness = NULL, max_iterations = 5)
if (requireNamespace("ggplot2", quietly = TRUE)) {
ggplot(reg2a$Y, aes(x = tstar, y = t_hat, group = id)) +
geom_line(alpha = 0.2) +
ggtitle("Estimated warping functions")
ggplot(reg2a$Y, aes(x = t_hat, y = value, group = id)) +
geom_line(alpha = 0.2) +
ggtitle("Registered curves")
}
# Allow the warping functions to not start / end on the diagonal.
# The higher lambda_inc, the more the starting points and endpoints are forced
# towards the diagonal.
reg2b = register_fpca(growth_incomplete, npc = 2, family = "gaussian",
incompleteness = "full", lambda_inc = 0.1,
max_iterations = 5)
if (requireNamespace("ggplot2", quietly = TRUE)) {
ggplot(reg2b$Y, aes(x = tstar, y = t_hat, group = id)) +
geom_line(alpha = 0.2) +
ggtitle("Estimated warping functions")
ggplot(reg2b$Y, aes(x = t_hat, y = value, group = id)) +
geom_line(alpha = 0.2) +
ggtitle("Registered curves")
}
### complete Gamma curves
Y = simulate_unregistered_curves(I = 20, D = 100)
Y$value = exp(Y$latent_mean)
registr_gamma = register_fpca(Y, npc = 2, family = "gamma", fpca_type = "two-step",
gradient = FALSE, max_iterations = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.