R/RcppExports.R

Defines functions project_to_curve

Documented in project_to_curve

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Project a set of points to the closest point on a curve
#'
#' Finds the projection index for a matrix of points \code{x}, when
#' projected onto a curve \code{s}. The curve need not be of the same
#' length as the number of points.
#'
#' @param x a matrix of data points.
#' @param s a parametrized curve, represented by a polygon.
#' @param stretch A stretch factor for the endpoints of the curve,
#'   allowing the curve to grow to avoid bunching at the end.
#'   Must be a numeric value between 0 and 2.
#'
#' @return A structure is returned which represents a fitted curve.  It has components
#'   \item{s}{The fitted points on the curve corresponding to each point \code{x}}
#'   \item{ord}{the order of the fitted points}
#'   \item{lambda}{The projection index for each point}
#'   \item{dist}{The total squared distance from the curve}
#'   \item{dist_ind}{The squared distances from the curve to each of the respective points}
#'
#' @seealso \code{\link{principal_curve}}
#'
#' @keywords regression smooth nonparametric
#'
#' @export
#'
#' @examples
#' t <- runif(100, -1, 1)
#' x <- cbind(t, t ^ 2) + rnorm(200, sd = 0.05)
#' s <- matrix(c(-1, 0, 1, 1, 0, 1), ncol = 2)
#'
#' proj <- project_to_curve(x, s)
#'
#' plot(x)
#' lines(s)
#' segments(x[, 1], x[, 2], proj$s[, 1], proj$s[, 2])
project_to_curve <- function(x, s, stretch = 2) {
    .Call('_princurve_project_to_curve', PACKAGE = 'princurve', x, s, stretch)
}
dynverse/princurve documentation built on Jan. 20, 2021, 11:10 a.m.