Fitting individual models

knitr::opts_chunk$set(echo = TRUE)

Sometimes it can be useful to fit only specific models to a dataset rather than fit multiple models and run the decision algorithm. For this purpose, sicegar provides the function multipleFitFunction(). This function fits a chosen model to the input dataset. It calls the fitting algorithm multiple times with different, randomly generated start parameters, to guarantee robust and reliable fitting.

###*****************************
seedNo=14159
set.seed(seedNo)
###*****************************

###*****************************
require("sicegar")
require("dplyr")
require("ggplot2")
###*****************************

We will demonstrate the use of this function on double-sigmoidal data, generated by adding some noise to the double-sigmoidal curve used for fitting. The curve used for fitting is implemented as doublesigmoidalFitFormula(), and thus can be used to generate model data.

time <- seq(3, 24, 0.5)
noise_parameter <- 0.2
intensity_noise <- runif(n = length(time), min = 0, max = 1) * noise_parameter
intensity <- doublesigmoidalFitFormula(time,
                                       finalAsymptoteIntensityRatio = .3,
                                       maximum = 4,
                                       slope1Param = 1,
                                       midPoint1Param = 7,
                                       slope2Param = 1,
                                       midPointDistanceParam = 8)
intensity <- intensity + intensity_noise
dataInput <- data.frame(time, intensity)
head(dataInput) # the generated input data

Before we can perform the fit, we need to normalize the data appropriately. All sicegar fit functions work on normalized data, where time and intensity are normalized to the interval from 0 to 1. Sicegar provides a convenient normalization function normalizeData() that normalizes data appropriately while storing the required information to transform fitted parameters back into non-normalized coordinates:

normalizedInput <- normalizeData(dataInput = dataInput, 
                                 dataInputName = "doubleSigmoidalSample")
head(normalizedInput$timeIntensityData) # the normalized time and intensity data

The data scaling paratmers and the data input name are stored as well:

normalizedInput$dataScalingParameters # scaling parameters
normalizedInput$dataInputName # data input name

Note that normalizeData() normalizes time with respect to the maximum value the time parameter takes:

timeRange <- time
timeNormalized <- time/timeRange # normalized time values

Whereas intensity is normalized with respect to the intensity interval:

intensityMin <- min(intensity)
intensityMax <- max(intensity)
intensityRange <- intensityMax - intensityMin

intensityNormalized <- (intensity-intensityMin)/intensityRange # normalized intensity values

Fitting the models to the data

To fit a model to the data using the function multipleFitFunction(), we provide it as input the normalized data and the model type to be fitted, which can be "sigmoidal" or "doublesigmoidal". Here we are fitting both models to the same input data:

# Do the sigmoidal fit
sigmoidalModel <- multipleFitFunction(dataInput=normalizedInput,
                                      model="sigmoidal")


# Do the double-sigmoidal fit
doubleSigmoidalModel <- multipleFitFunction(dataInput=normalizedInput,
                                            model="doublesigmoidal")

The two generated model objects contain a large number of computed parameters, described in detail in the following.

t(sigmoidalModel)
t(doubleSigmoidalModel)

The calculated quantities can be grouped into several different groups of parameters:

1. Information about the fitting process

2. Estimates of the fitted parameters

These estimates have been converted from the normalized data to the original raw data, and are the main quantities of interest to the user. They depend on the type of the model, sigmoidal vs.\ double-sigmoidal.

Estimates for the sigmoidal model are:

Estimates for the double-sigmoidal model are:

3. Quantities measuring the overall quality of fit

4. Start point of the gradient descent algorithm

Each time a fit is attempted, the likelihood maximization algorithm starts from a random initiation point and finds the final parameter estimates by gradient descent. The start vector for the best fit is returned in the form of variables whose name starts with startVector., followed by the name of the estimated parameter. For example:

5. Parameters related to the normalization step

6. Error estimates for fitted parameters

For each estimated parameter listed under point 2, the algorithm provides additional statistical parameters, such as the estimate in the normalized scale, the standard error (also in normalized scale), the t value, and the P value. For example, for the maximum estimate, these are:



Try the sicegar package in your browser

Any scripts or data that you put into this service are public.

sicegar documentation built on Aug. 23, 2019, 5:05 p.m.