% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit_curve.R
\name{fit_curve}
\alias{fit_curve}
\title{Fit curve over cycles}
\usage{
fit_curve(ts, cycles, fit = c("gu", "klosterman"))
}
\arguments{
\item{ts}{Time series in \code{s2ts} format (generated using \code{\link[=fill_s2ts]{fill_s2ts()}}).}

\item{cycles}{Cycles allocation (data table generated by \code{\link[=cut_cycles]{cut_cycles()}},
eventually filtered using \code{\link[=assign_season]{assign_season()}}).}

\item{fit}{Fitting function among \code{"klosterman"}, \code{"beck"},
\code{"elmore"}, \code{"gu"} and \code{"no"} (see \code{phenopix::greenProcess()}).
Value \code{"no"} can be used to convert a \code{s2ts} time series in the format
returned by this function without making any interpolation.
A vector of length > 1 can be specified, in which case the second element
is used if the first method fails.}
}
\value{
A named list of \code{n} elements (being \code{n} the number of IDs included
in \code{ts}). Each element is a named list of \code{m} elements (being \code{m} the
number of detected cycles).
Each element is a list including the following elements:
\itemize{
\item \code{fit}: the fitted curve as returned by \code{phenopix} fitting functions;
\item \code{ts}: a data table of fitted values, containing the columns
\code{date} (date of the record) and
\code{value} (fitted value);
\item \code{maxval}: the date of the maximum value in the cycles
(obtained from input \code{cycles} and here reported).
}
}
\description{
Fit a curve using a parametric function from
\code{phenopix::greenProcess()}.
}
\examples{
# Load input data
data("ts_filled")
data("dt_cycles")

\donttest{
# Standard interpolation
cf <- fit_curve(ts_filled, dt_cycles)
plot(ts_filled, fitted = cf)
}

# Interpolation using a different method
cf_2 <- fit_curve(ts_filled, dt_cycles, fit = "no")
}
\author{
Luigi Ranghetti, PhD (2020) \email{luigi@ranghetti.info}
}
