This is a document invetigates details of double sigmoidal model
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::doublesigmoidalFitFormula
generate a set of intensity values based on finalAsymptoteIntensity, maximum, slope1, midPoint1,slope2, midPointDistance values supplied. So here we are generating a set of points that are on two sigmoidals glued side by side from the maximum of the combined function.
note that slope1, slope2 and finalAsymptoteIntensity are not exactly the exacly slope1 slope2 and final asymtote intensity of the final function. they are parameters related with them.
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=doublesigmoidalFitFormula(time,
finalAsymptoteIntensity=.3,
maximum=4,
slope1=1,
midPoint1=7,
slope2=1,
midPointDistance=8)
intensity=intensity+intensity_noise
dataInput=data.frame(intensity=intensity,time=time)
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.009751953
## 3 0.1666667 0.022564417
## 4 0.1875000 0.042943317
## 5 0.2083333 0.093315512
## 6 0.2291667 0.157635754
print(normalizedInput$dataScalingParameters) # the normalization parameters that is needed to go back to original scale
## timeRatio intensityMin intensityMax intensityRatio
## 24.0000000 0.1544192 4.0611482 3.9067290
print(normalizedInput$dataInputName) # a useful feature to track the sample in all the process
## [1] "Sample001"
Now it is time to calculate the parameters by using sicegar::doublesigmoidalFitFunction()
parameterVector<-sicegar::doublesigmoidalFitFunction(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]
## finalAsymptoteIntensity_N_Estimate "0.2830857"
## finalAsymptoteIntensity_Std_Error "0.003176356"
## finalAsymptoteIntensity_t_value "89.12278"
## finalAsymptoteIntensity_Pr_t "8.723137e-45"
## maximum_N_Estimate "0.99507"
## maximum_Std_Error "0.00379288"
## maximum_t_value "262.3521"
## maximum_Pr_t "4.204386e-62"
## slope1_N_Estimate "25.9788"
## slope1_Std_Error "0.4928017"
## slope1_t_value "52.71653"
## slope1_Pr_t "2.04674e-36"
## midPoint1_N_Estimate "0.2936612"
## midPoint1_Std_Error "0.0009137447"
## midPoint1_t_value "321.3821"
## midPoint1_Pr_t "2.31223e-65"
## slope2_N_Estimate "24.8414"
## slope2_Std_Error "0.6875028"
## slope2_t_value "36.1328"
## slope2_Pr_t "1.842897e-30"
## midPointDistance_N_Estimate "0.3335492"
## midPointDistance_Std_Error "0.00186414"
## midPointDistance_t_value "178.9293"
## midPointDistance_Pr_t "5.8665e-56"
## residual_Sum_of_Squares "0.003357907"
## log_likelihood "142.3248"
## AIC_value "-270.6497"
## BIC_value "-258.3213"
## isThisaFit "TRUE"
## startVector.finalAsymptoteIntensity "0.3351392"
## startVector.maximum "0.9301484"
## startVector.slope1 "98.1881"
## startVector.midPoint1 "0.562631"
## startVector.slope2 "118.1069"
## startVector.midPointDistance "0.2448843"
## dataScalingParameters.timeRatio "24"
## dataScalingParameters.intensityMin "0.1544192"
## dataScalingParameters.intensityMax "4.061148"
## dataScalingParameters.intensityRatio "3.906729"
## model "doublesigmoidal"
## numericalParameters "FALSE"
## finalAsymptoteIntensity_Estimate "0.2830857"
## maximum_Estimate "4.041888"
## slope1_Estimate "1.08245"
## midPoint1_Estimate "7.047869"
## slope2_Estimate "1.035058"
## midPointDistance_Estimate "8.005181"
Here is the brief explanations of the parameters that are given by sicegar::doublesigmoidalFitFunction
(In different order then than the output vector of the doublesigmoidalFitFunction)
These are the parameters of the normalization step
dataScalingParameters.timeRatio
: Maximum of raw time datadataScalingParameters.intensityMin
: Minimum of raw intensity datadataScalingParameters.intensityMax
: Maximum of raw intensity datadataScalingParameters.intensityRatio
: Maximum - Minimum of intensity dataThey are the meta summary of the result parameters
isThisaFit
model
numericalParameters
: “FALSE” in this caseLikelihood 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.
startVector.maximum
: maximum value of initiation pointstartVector.slope1
: slope1 value of initiation pointstartVector.midPoint1
: midPoint1 value of initiation pointstartVector.slope2
: slope2 value of initiation pointstartVector.midPointDistance
: midPointDistance value of initiation pointstartVector.finalAsymptoteIntensity
: finalAsymptoteIntensity value of initiation point.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”
maximum_N_Estimate
: Here N stand for the intersection in the normalized scalemaximum_Std_Error
maximum_t_value
maximum_Pr_t
They are the parameters associated with parameter “slope1”
slope1_N_Estimate
: Here N stand for the intersection in the normalized scaleslope1_Std_Error
slope1_t_value
slope1_Pr_t
They are the parameters associated with parameter “midPoint1”
midPoint1_N_Estimate
: Here N stand for the intersection in the normalized scalemidPoint1_Std_Error
midPoint1_t_value
midPoint1_Pr_t
They are the parameters associated with parameter “slope2”
slope2_N_Estimate
: Here N stand for the intersection in the normalized scaleslope2_Std_Error
slope2_t_value
slope2_Pr_t
They are the parameters associated with parameter “midPointDistance”
midPointDistance_N_Estimate
: Here N stand for the intersection in the normalized scalemidPointDistance_Std_Error
midPointDistance_t_value
midPointDistance_Pr_t
They are the parameters associated with parameter “finalAsymptoteIntensity”
finalAsymptoteIntensity_N_Estimate
: Here N stand for the intersection in the normalized scalefinalAsymptoteIntensity_Std_Error
finalAsymptoteIntensity_t_value
finalAsymptoteIntensity_Pr_t
They are the parameters associated with the quality of the fit.
residual_Sum_of_Squares
: Small value indicate better fitlog_likelihood
: Higher value indicate a better fitAIC_value
: Smaller value indicate a better fitBIC_value
: Smaller value indicate a better fitThey are the fitted values after converting everything from normalized to un-normalized scale. (Without numeric correction)
maximum_Estimate
: Maximum intensity estimate for the raw dataslope1_Estimate
: Slope1 parameter estimate for the raw datamidPoint1_Estimate
: Mid-point 1 estimate (time the intensity reaches 1/2 of maximum) for the raw data. Needs numerical correctionslope2_Estimate
: Slope2 parameter estimate for the raw datamidPointDistance_Estimate
: Distance between mid- point 1 and mid-point 2. Where mid-point 2 is the time that intensity decreases to the value in between final asymptote intensity and maximum value. Needs numerical correctionfinalAsymptoteIntensity_Estimate
: This is the ratio between asymptote intensity and maximum value of the function.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::doublesigmoidalFitFormula(
time,
finalAsymptoteIntensity=parameterVector$finalAsymptoteIntensity_Estimate,
maximum=parameterVector$maximum_Estimate,
slope1=parameterVector$slope1_Estimate,
midPoint1=parameterVector$midPoint1_Estimate,
slope2=parameterVector$slope2_Estimate,
midPointDistance=parameterVector$midPointDistance_Estimate)
comparisonData=cbind(dataInput,intensityTheoretical)
require(ggplot2)
ggplot2::ggplot(comparisonData)+
ggplot2::geom_point(aes(x=time, y=intensity))+
ggplot2::geom_line(aes(x=time,y=intensityTheoretical), colour="orange")+
ggplot2::expand_limits(x = 0, y = 0)