fitCDF {sojourner} | R Documentation

## fitCDF

### Description

Caclulate apparent diffusion coefficient (Dcoef) for trajecotries by fitting displacementCDF.

### Usage

    fitCDF(cdf, components=c("one","two","three"),
            start=list(
                oneCompFit=list(D=c(0,2)),
                twoCompFit=list(D1=c(0,2),D2=c(0,2),alpha=c(0,1)),
                threeCompFit=list(D1=c(0,2),D2=c(0,2),D3=c(0,2),
                                alpha=c(0,1),beta=c(0,1))),
            t.interval=0.01,
            maxiter.search=1000,
            maxiter.optim=1000,
            output=FALSE)

### Arguments

`start` | the start value for fitting.
`t.interval` | time interval for image aquisition. Default 0.01 sec.
`maxiter.optim` | maximum iteration in local optimization process. Default ot 1000.
`cdf` | cdf calculated from displacementCDF().
`components` | parameter specifying the number of components to fit. Currently support one to three components fit.
`maxiter.search` | maximum iteration in random search start value process. Default to 1000.
`output` | Logical indicaring if output file should be generated.

### Details

Calculating Dcoef by fitting displacementCDF.

Reducing the range can greatly increase the precision of the searching; alternatively, if the range are unavailable, increase the maxiter.search so more points will be searched through with the cost of computation time. maxiter.optim barely need to change, if it does not converge with default setting maxiter=1000, most likely the problem is in the initial values.

Note: Ensure that a random number generator seed has been manually set! The seed is stored as an attribute of the returned object of fitCDF() and using the same seed makes results repeatable (see examples).

### Value

- on screen output and file Result and parameters of goodness of the fit.

- Plot, fiting plot.

### Examples

    # compare folders
    folder1=system.file("extdata","SWR1",package="sojourner")
    folder2=system.file("extdata","HTZ1",package="sojourner")
    trackll=compareFolder(folders=c(folder1,folder2), input=3)
    cdf=displacementCDF(trackll,dt=1,plot=FALSE,output=FALSE)

    # set unique seed (use any number)
    set.seed(123)

    # fit CDF (function automatically saves seed state as an attribute of the
    # result)
    a=fitCDF(cdf,components="two",output=FALSE)

    # to repeat results of a, load seed attribute of 'a' into current RNG state
    .Random.seed=attr(a,"seed")
    # or, reset the seed with same unique number
    # set.seed(123)

    b=fitCDF(cdf,components="two",output=FALSE)

    # if 'a' and 'b' are the same
    x=summary(a[[1]])
    y=summary(b[[1]])
    # formula records environment, exclude from the comparison
    mapply(identical,x[names(x)!="formula"],y[names(y)!="formula"])

    # To specify ranges of parameter value of interest
    set.seed(234)
    fit=fitCDF(cdf,components="two",
        start=list(
                    twoCompFit=list(D1=c(0,2),D2=c(0,2),alpha=c(0,1)))
                    )

[Package sojourner version 1.1.1 Index]