Figure Generation

Umut Caglar

2017-03-18

The Figure generation tools

This is a document invetigates how to generate figures. Figure gneration might be really useful to visualize the input data and quantification of it

Data generation

To generate the figures, 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.

We will generate data for both sigmoidal and double sigmoidal

Generate data for sigmoidal

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

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

Generate data for double - sigmoidal

noise_parameter=0.2
intensity_noise=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

dataInputDoubleSigmoidal=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.

The normalization code is

normalizedSigmoidalInput = sicegar::normalizeData(dataInput = dataInputSigmoidal, 
                                         dataInputName = "sigmoidalSample")

normalizedDoubleSigmoidalInput = sicegar::normalizeData(dataInput = dataInputDoubleSigmoidal, 
                                         dataInputName = "doubleSigmoidalSample")

Fits for sigmoidal and double sigmoidal

We will now recalculate the parameters for sigmoidal and double sigmoidal datasets

# Do the sigmoidal fit
sigmoidalModel=fitFunction(dataInput=normalizedSigmoidalInput,
                           model="sigmoidal",
                           n_runs_min=20,
                           n_runs_max=500,
                           showDetails=FALSE)

# Do the double sigmoidal fit
doubleSigmoidalModel=fitFunction(dataInput=normalizedDoubleSigmoidalInput,
                                 model="doublesigmoidal",
                                 n_runs_min=20,
                                 n_runs_max=500,
                                 showDetails=FALSE)

doubleSigmoidalModel = numericalReCalculation(doubleSigmoidalModel,
                                              stepSize=0.00001)
# The double sigmoidal model needs one more step for obtaining correct values named as "numericalReCalculation"

Figure generation

The figure generation function have multiple options.

One can only draw the input data

# Sigmoidal Raw Data
fig01a=printInfectionCurves(dataInput=normalizedSigmoidalInput)
print(fig01a)

# Double Sigmoidal Raw Data
fig01b=printInfectionCurves(dataInput=normalizedDoubleSigmoidalInput)
print(fig01b)

or we can generate raw data with fits

# Sigmoidal Fit
fig02a=printInfectionCurves(dataInput=normalizedSigmoidalInput,
                           sigmoidalFitVector=sigmoidalModel)
print(fig02a)

# Double Sigmoidal Fit
fig02b=printInfectionCurves(dataInput=normalizedDoubleSigmoidalInput,
                           doubleSigmoidalFitVector=doubleSigmoidalModel)
print(fig02b)

We can see the quantified parameters on the figues too; by the help of showParameterRelatedLines=TRUE option

# Sigmoidal Fit with parameter related lines
fig03a=printInfectionCurves(dataInput=normalizedSigmoidalInput,
                           sigmoidalFitVector=sigmoidalModel,
                           showParameterRelatedLines=TRUE)
print(fig03a)

# Double Sigmoidal Fit with parameter related lines
fig03b=printInfectionCurves(dataInput=normalizedDoubleSigmoidalInput,
                           doubleSigmoidalFitVector=doubleSigmoidalModel,
                           showParameterRelatedLines=TRUE)
print(fig03b)