### 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)) })
}
# \donttest{
# 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)
# }
Run the code above in your browser using DataLab