R/fit.curve.R

Defines functions fit.curve

Documented in fit.curve

#' Fit Curve
#'
#' @param x
#' @param mode
#' @param config
#'
#' @return
#' @export
#'
#' @examples
fit.curve <- function(x, mode = 'fit.smooth', config) {
    # Ver 3.1
    curve <- NULL
    if (mode == 'fit.norm') {
        para <-
            c(config$mu1, config$sigma1, config$k1, config$a, config$b)
        curve <- fit.norm(x, para = para)
    } else if (mode == 'fit.smooth') {
        curve <- fit.smooth(x)
    } else if (mode == 'fit.2norm') {
        para <- c(
            config$mu1, config$sigma1, config$k1,
            config$mu2, config$sigma2, config$k2,
            config$a, config$b
        )
        curve <- fit.2norm(x, para = para)
    } else {
        cat('curve fit model does not exist\n')
        return(NULL)
    }
    # return NULL if no peaks or no velleys
    if (is.null(curve)) {
        warning('Curve not fit\n')
        return(NULL)
    } else {
        return(curve)
    }
}
yanxianUCSB/yxhelper documentation built on April 20, 2020, 4:09 p.m.