Double sigmoidal fit function with h0.
Source:R/doublesigmoidalFitFunctions_h0.R
doublesigmoidalFitFunction_h0.Rd
The function fits a double sigmoidal curve to given data by using likelihood maximization (LM) algorithm and provides the parameters (maximum, final asymptote intensity, slope1Param, midpoint1Param, slope2Param, and midpoint distance) describing the double-sigmoidal fit as output. It also contains information about the goodness of fits such as AIC, BIC, residual sum of squares, and log likelihood.
Usage
doublesigmoidalFitFunction_h0(
dataInput,
tryCounter,
startList = list(finalAsymptoteIntensityRatio = 0, maximum = 1, slope1Param = 1,
midPoint1Param = 0.33, slope2Param = 1, midPointDistanceParam = 0.29, h0 = 0.1),
lowerBounds = c(finalAsymptoteIntensityRatio = 0, maximum = 0.3, slope1Param = 0.01,
midPoint1Param = -0.52, slope2Param = 0.01, midPointDistanceParam = 0.04, h0 = 0),
upperBounds = c(finalAsymptoteIntensityRatio = 1, maximum = 1.5, slope1Param = 180,
midPoint1Param = 1.15, slope2Param = 180, midPointDistanceParam = 0.63, h0 = 0.3),
min_Factor = 1/2^20,
n_iterations = 1000
)
Arguments
- dataInput
A data frame or a list containing the dataframe. The data frame should be composed of at least two columns. One represents time, and the other represents intensity. The data should be normalized with the normalize data function sicegar::normalizeData() before imported into this function.
- tryCounter
A counter that shows the number of times the data was fit via maximum likelihood function.
- startList
The initial set of parameters vector that algorithm tries for the first fit attempt for the relevant parameters. The vector composes of seven elements; 'finalAsymptoteIntensityRatio', 'maximum', 'slope1Param', 'midPoint1Param' , 'slope2Param', 'midPointDistanceParam', and 'h0'. Detailed explanations of those parameters can be found in vignettes. Defaults are finalAsymptoteIntensityRatio = 0, maximum = 1, slope1Param = 1, midPoint1Param = 0.33, slope2Param = 1, midPointDistanceParam=0.29, and h0 = 0. The numbers are in normalized time intensity scale.
- lowerBounds
The lower bounds for the randomly generated start parameters. The vector composes of seven elements; 'finalAsymptoteIntensityRatio', 'maximum', 'slope1Param', 'midPoint1Param' , 'slope2Param', 'midPointDistanceParam', and 'h0'. Detailed explanations of those parameters can be found in vignettes. Defaults are finalAsymptoteIntensityRatio = 0, maximum = 0.3, slope1Param = .01, midPoint1Param = -0.52, slope2Param = .01, midPointDistanceParam = 0.04, and h0 = -0.1. The numbers are in normalized time intensity scale.
- upperBounds
The upper bounds for the randomly generated start parameters. The vector composes of seven elements; 'finalAsymptoteIntensityRatio', 'maximum', 'slope1Param', 'midPoint1Param' , 'slope2Param', 'midPointDistanceParam', and 'h0'. Detailed explanations of those parameters can be found in vignettes. Defaults are finalAsymptoteIntensityRatio = 1, maximum = 1.5, slope1Param = 180, midPoint1Param = 1.15, slope2Param = 180, midPointDistanceParam = 0.63, and h0 = 0.3. The numbers are in normalized time intensity scale.
- min_Factor
Defines the minimum step size used by the fitting algorithm. Default is 1/2^20.
- n_iterations
Define maximum number of iterations used by the fitting algorithm. Default is 1000
Examples
time=seq(3, 24, 0.1)
#simulate intensity data and add noise
noise_parameter <- 0.2
intensity_noise <- stats::runif(n = length(time), min = 0, max = 1) * noise_parameter
intensity <- doublesigmoidalFitFormula_h0(time,
finalAsymptoteIntensityRatio = .3,
maximum = 4,
slope1Param = 1,
midPoint1Param = 7,
slope2Param = 1,
midPointDistanceParam = 8,
h0 = 1)
intensity <- intensity + intensity_noise
dataInput <- data.frame(intensity = intensity, time = time)
normalizedInput <- normalizeData(dataInput)
parameterVector <- doublesigmoidalFitFunction_h0(normalizedInput, tryCounter = 1)
#Check the results
# doublesigmoidalFitFunction_h0() is run on the startList param values (because 'tryCounter = 1')
# use multipleFitFunction() for multiple random starts in order to optimize
if(parameterVector$isThisaFit){
intensityTheoretical <-
doublesigmoidalFitFormula_h0(
time,
finalAsymptoteIntensityRatio = parameterVector$finalAsymptoteIntensityRatio_Estimate,
maximum = parameterVector$maximum_Estimate,
slope1Param = parameterVector$slope1Param_Estimate,
midPoint1Param = parameterVector$midPoint1Param_Estimate,
slope2Param = parameterVector$slope2Param_Estimate,
midPointDistanceParam = parameterVector$midPointDistanceParam_Estimate,
h0 = parameterVector$h0_Estimate)
comparisonData <- cbind(dataInput, intensityTheoretical)
require(ggplot2)
ggplot(comparisonData) +
geom_point(aes(x = time, y = intensity)) +
geom_line(aes(x = time, y = intensityTheoretical)) +
expand_limits(x = 0, y = 0)}
if(!parameterVector$isThisaFit) {print(parameterVector)}
#> finalAsymptoteIntensityRatio_N_Estimate
#> 1 NA
#> finalAsymptoteIntensityRatio_Std_Error finalAsymptoteIntensityRatio_t_value
#> 1 NA NA
#> finalAsymptoteIntensityRatio_Pr_t maximum_N_Estimate maximum_Std_Error
#> 1 NA NA NA
#> maximum_t_value maximum_Pr_t slope1Param_N_Estimate slope1Param_Std_Error
#> 1 NA NA NA NA
#> slope1Param_t_value slope1Param_Pr_t midPoint1Param_N_Estimate
#> 1 NA NA NA
#> midPoint1Param_Std_Error midPoint1Param_t_value midPoint1Param_Pr_t
#> 1 NA NA NA
#> slope2Param_N_Estimate slope2Param_Std_Error slope2Param_t_value
#> 1 NA NA NA
#> slope2Param_Pr_t midPointDistanceParam_N_Estimate
#> 1 NA NA
#> midPointDistanceParam_Std_Error midPointDistanceParam_t_value
#> 1 NA NA
#> midPointDistanceParam_Pr_t h0_N_Estimate h0_Std_Error h0_t_value h0_Pr_t
#> 1 NA NA NA NA NA
#> residual_Sum_of_Squares log_likelihood AIC_value BIC_value isThisaFit
#> 1 Inf NA NA NA FALSE
#> startVector.finalAsymptoteIntensityRatio startVector.maximum
#> 1 0 1
#> startVector.slope1Param startVector.midPoint1Param startVector.slope2Param
#> 1 1 0.33 1
#> startVector.midPointDistanceParam startVector.h0
#> 1 0.29 0.1
#> dataScalingParameters.timeRange dataScalingParameters.intensityMin
#> 1 24 1.10194
#> dataScalingParameters.intensityMax dataScalingParameters.intensityRange
#> 1 4.185273 3.083333
#> model finalAsymptoteIntensityRatio_Estimate maximum_Estimate
#> 1 doublesigmoidal NA NA
#> slope1Param_Estimate midPoint1Param_Estimate slope2Param_Estimate
#> 1 NA NA NA
#> midPointDistanceParam_Estimate h0_Estimate
#> 1 NA NA