(2/3) Sigmoidal model

Umut Caglar

2017-03-18

# The Sigmoidal Fit Function This is a document invetigates details of sigmoidal model

Data generation

To simulate the results, we will go backwards and firstly generate some data to analize. To add some randomness to the input data I will use some noise. The input of all package must be in the form of a data frame with at least 2 columns time and intensity.

sicegar::sigmoidalFitFormula generate a set of intensity values based on maximum, slope and midPoint values supplied. So here we are generating a set of points that are on a sigmoidal with a /slope parameter/ of 1, maximum of 4 and midpoint of 8.

The sigmoidal fit formula uses the function
      y = (0 + (maximum - 0) / (1 + exp((-slope)*(x - midPoint))))
and if we calculate the derivative of it at the midpoint we find the slope as
      max_slope = 1/4 * slope * maximum
i.e what we provide to sicegar::sigmoidalFitFormula as slope is not the maximum slope but a parameter related with maximum slope.

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, slope=1, midPoint=8)
intensity=intensity+intensity_noise

dataInput=data.frame(intensity=intensity,time=time)

Data normalization

This is the first step. Data should be normalized before any fit. I.e time and intensity should be in between 0-1 interval.

There is a nuance

timeRatio=max(timeData); timeData=timeData/timeRatio
intensityMin = min(dataInput$intensity)
intensityMax = max(dataInput$intensity)
intensityRatio = intensityMax - intensityMin

intensityData=dataInput$intensity-intensityMin
intensityData=intensityData/intensityRatio

The normalization code is

normalizedInput = sicegar::normalizeData(dataInput = dataInput, 
                                         dataInputName = "Sample001")

Components of the normalization output

head(normalizedInput$timeIntensityData) # the normalized time and intensity data
##        time   intensity
## 1 0.1250000 0.000000000
## 2 0.1458333 0.002079141
## 3 0.1666667 0.002811145
## 4 0.1875000 0.004563081
## 5 0.2083333 0.026984704
## 6 0.2291667 0.052748267
print(normalizedInput$dataScalingParameters) # the normalization parameters that is needed to go back to original scale
##      timeRatio   intensityMin   intensityMax intensityRatio 
##     24.0000000      0.1065867      4.0969597      3.9903731
print(normalizedInput$dataInputName) # a useful feature to track the sample in all the process
## [1] "Sample001"

The figures of raw and normalized datasets

Sigmoidal fit of the data

Now it is time to calculate the parameters by using sicegar::sigmoidalFitFunction()

parameterVector<-sicegar::sigmoidalFitFunction(normalizedInput,tryCounter=2)

# Where tryCounter is a tool usually provided by sicegar::fitFunction when the sicegar::sigmoidalFitFunction is called from sicegar::fitFunction. 

# If tryCounter==1 it took the  start position given by sicegar::fitFunction
# If tryCounter!=1 it generates a random start position from given interval

the function outputs a vector that gives information about multiple parameters

print(t(parameterVector))
##                                      [,1]          
## maximum_N_Estimate                   "0.9892762"   
## maximum_Std_Error                    "0.00172638"  
## maximum_t_value                      "573.035"     
## maximum_Pr_t                         "6.473165e-80"
## slope_N_Estimate                     "24.91311"    
## slope_Std_Error                      "0.3550745"   
## slope_t_value                        "70.16306"    
## slope_Pr_t                           "1.684373e-43"
## midPoint_N_Estimate                  "0.3352606"   
## midPoint_Std_Error                   "0.0006568671"
## midPoint_t_value                     "510.3933"    
## midPoint_Pr_t                        "6.635815e-78"
## residual_Sum_of_Squares              "0.003021868" 
## log_likelihood                       "144.5919"    
## AIC_value                            "-281.1837"   
## BIC_value                            "-274.1389"   
## isThisaFit                           "TRUE"        
## startVector.maximum                  "0.702167"    
## startVector.slope                    "94.52226"    
## startVector.midPoint                 "0.3882737"   
## dataScalingParameters.timeRatio      "24"          
## dataScalingParameters.intensityMin   "0.1065867"   
## dataScalingParameters.intensityMax   "4.09696"     
## dataScalingParameters.intensityRatio "3.990373"    
## model                                "sigmoidal"   
## maximum_Estimate                     "4.054168"    
## slope_Estimate                       "1.038046"    
## midPoint_Estimate                    "8.046254"

Here is the brief explanations of the parameters that are given by sicegar::sigmoidalFitFunction (In different order then than the output vector of the sigmoidalFitFunction)

These are the parameters of the normalization step

They are the meta summary of the result parameters

Likelihood maximization algorithm starts from a random initiation (if tryCounter!=1) point and goes down the fitness space by a gradient decent algorithm. these parameters represent the start point of the gradient decent algorithm.

For each parameter that needs to fitted by LM algorithm; the algorithm gives a bunch of statistical parameters; including the estimated value of the parameter

They are the parameters associated with parameter “maximum”

They are the parameters associated with parameter “slope”

They are the parameters associated with parameter “midpoint”

They are the parameters associated with the quality of the fit.

They are the fitted values after converting everything from normalized to un-normalized scale.

Check the results to see if the results are meaningfull

By using the maximum_Estimate, slope_Estimate, midPoint_Estimate parameters of the sigmoidalfit and the time sequence that we already created we can calculate the intensity values by the help of sicegar::sigmoidalFitFormula(). We can draw the best sigmoidal fit on top of our initial data.

intensityTheoretical=sicegar::sigmoidalFitFormula(time,
                                                  maximum=parameterVector$maximum_Estimate,
                                                  slope=parameterVector$slope_Estimate,
                                                  midPoint=parameterVector$midPoint_Estimate)
comparisonData=cbind(dataInput,intensityTheoretical)

ggplot2::ggplot(comparisonData)+
  ggplot2::geom_point(aes(x=time, y=intensity))+
  ggplot2::geom_line(aes(x=time,y=intensityTheoretical))+
  ggplot2::expand_limits(x = 0, y = 0)