fit_elastic_regression {elasdics}R Documentation

Compute a elastic mean for a collection of curves

Description

Computes a Fréchet mean for the curves stored in data_curves with respect to the elastic distance. Constructor function for class elastic_reg_model.

Usage

fit_elastic_regression(
  formula,
  data_curves,
  x_data,
  knots = seq(0, 1, 0.2),
  type = "smooth",
  closed = FALSE,
  max_iter = 10,
  eps = 0.001,
  pre_align = FALSE
)

Arguments

formula

an object of class "formula" of the form data_curves ~ ...".

data_curves

list of data.frames with observed points in each row. Each variable is one coordinate direction. If there is a variable t, it is treated as the time parametrization, not as an additional coordinate.

x_data

a data.frame with covariates.

knots

set of knots for the parameter curves of the regression model

type

if "smooth" linear srv-splines are used which results in a differentiable mean curve if "polygon" the mean will be piecewise linear.

closed

TRUE if the curves should be treated as closed.

max_iter

maximal number of iterations

eps

the algorithm stops if L2 norm of coefficients changes less

pre_align

TRUE if curves should be pre aligned to the mean

Value

an object of class elastic_reg_model, which is a list with entries

type

"smooth" if linear srv-splines or "polygon" if constant srv-splines were used

coefs

spline coeffiecients

knots

spline knots

data_curves

list of data.frames with observed points in each row. First variable t gives the initial parametrization, second variable t_optim the optimal parametrization when the curve is aligned to the model prediction.

closed

TRUE if the regression model fitted closed curves.

Examples

curve <- function(x_1, x_2, t){
  rbind(2*t*cos(6*t) - x_1*t , x_2*t*sin(6*t))
}
set.seed(18)
x_data <- data.frame(x_1 = runif(10,-1,1), x_2 = runif(10,-1,1))
data_curves <- apply(x_data, 1, function(x){
  m <- sample(10:15, 1)
  delta <- abs(rnorm(m, mean = 1, sd = 0.05))
  t <- cumsum(delta)/sum(delta)
  data.frame(t(curve((x[1] + 1), (x[2] + 2), t))
   + 0.07*t*matrix(cumsum(rnorm(2*length(delta))), ncol = 2))
})
reg_model <- fit_elastic_regression(data_curves ~ x_1 + x_2,
                                    data_curves = data_curves, x_data = x_data)
plot(reg_model)

[Package elasdics version 1.1.3 Index]