Skip to contents

The function fits a sigmoidal curve to given data by using likelihood maximization (LM) algorithm and provides the parameters (maximum, slopeParam, midPoint, and h0) describing the 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

sigmoidalFitFunction(
  dataInput,
  tryCounter,
  startList = list(maximum = 1, slopeParam = 1, midPoint = 0.33),
  lowerBounds = c(maximum = 0.3, slopeParam = 0.01, midPoint = -0.52),
  upperBounds = c(maximum = 1.5, slopeParam = 180, midPoint = 1.15),
  min_Factor = 1/2^20,
  n_iterations = 1000
)

Arguments

dataInput

A dataframe or a list containing the dataframe. The dataframe 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 being imported into this function.

tryCounter

A counter that shows the number of times the data was fit via maximum likelihood function.

startList

A vector containing the initial set of parameters that the algorithm tries for the first fit attempt for the relevant parameters. The vector is composed of four elements; 'maximum', 'slopeParam', 'midPoint', and 'h0'. Detailed explanations of those parameters can be found in vignettes. Defaults are maximum = 1, slopeParam = 1, midPoint = 0.33, and h0 = 0. The numbers are in normalized time intensity scale.

lowerBounds

The lower bounds for the randomly generated start parameters. The vector is composed of four elements; 'maximum', 'slopeParam', 'midPoint', and 'h0'. Detailed explanations of those parameters can be found in vignettes. Defaults are maximum = 0.3, slopeParam = 0.01, midPoint = -0.52, and h0 = -0.1. The numbers are in normalized time intensity scale.

upperBounds

The upper bounds for the randomly generated start parameters. The vector is composed of four elements; 'maximum', 'slopeParam','midPoint', and 'h0'. Detailed explanations of those parameters can be found in vignettes. Defaults are maximum = 1.5, slopeParam = 180, midPoint = 1.15, 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

Defines maximum number of iterations used by the fitting algorithm. Default is 1000

Value

Returns fitted parameters for the sigmoidal model.

Examples

# runif() is used here for consistency with previous versions of the sicegar package. However,
# rnorm() will generate symmetric errors, producing less biased numerical parameter estimates.
# We recommend errors generated with rnorm() for any simulation studies on sicegar.
time <- seq(3, 24, 0.5)

#simulate intensity data and add noise
noise_parameter <- 0.1
intensity_noise <- stats::runif(n = length(time), min = 0, max = 1) * noise_parameter
intensity <- sigmoidalFitFormula(time, maximum = 4, slopeParam = 1, midPoint = 8)
intensity <- intensity + intensity_noise

dataInput <- data.frame(intensity = intensity, time = time)
normalizedInput <- normalizeData(dataInput)
parameterVector <- sigmoidalFitFunction(normalizedInput, tryCounter = 2)

#Check the results
if(parameterVector$isThisaFit){
intensityTheoretical <- sigmoidalFitFormula(time,
                                           maximum = parameterVector$maximum_Estimate,
                                           slopeParam = parameterVector$slopeParam_Estimate,
                                           midPoint = parameterVector$midPoint_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)
}
#>   maximum_N_Estimate maximum_Std_Error maximum_t_value maximum_Pr_t
#> 1                 NA                NA              NA           NA
#>   slopeParam_N_Estimate slopeParam_Std_Error slopeParam_t_value slopeParam_Pr_t
#> 1                    NA                   NA                 NA              NA
#>   midPoint_N_Estimate midPoint_Std_Error midPoint_t_value midPoint_Pr_t
#> 1                  NA                 NA               NA            NA
#>   residual_Sum_of_Squares log_likelihood AIC_value BIC_value isThisaFit
#> 1                     Inf             NA        NA        NA      FALSE
#>   startVector.maximum startVector.slopeParam startVector.midPoint
#> 1           0.7847606               127.0291           -0.3039134
#>   dataScalingParameters.timeRange dataScalingParameters.intensityMin
#> 1                              24                         0.04516577
#>   dataScalingParameters.intensityMax dataScalingParameters.intensityRange
#> 1                            4.09465                             4.049484
#>       model maximum_Estimate slopeParam_Estimate midPoint_Estimate
#> 1 sigmoidal               NA                  NA                NA