fitNormDistr {sojourner} | R Documentation

## fitNormDistr

### Description

fit normal distributions to diffusion coefficient caclulated by Dcoef method and saves seed state as a attribute of the result

### Usage

    fitNormDistr(dcoef,components=NULL,log.transform=FALSE,binwidth=NULL,
    combine.plot=FALSE,output=FALSE, proportion=NULL, means=NULL,
    sd=NULL, constrain=FALSE)

### Arguments

`sd` | numeric vector with estimates of standard deviation(sigma) values for each component.
`constrain` | logical indicate if mean and std deviation are set to the given value. This will not work for the unimodal distribution.
`dcoef` | diffusion coefficient calculated from Dcoef().
`components` | parameter specifying the number of components to fit. If NULL (default), a components analysis is done to determine the most likely components and this number is then used for subsequent analysis.
`log.transform` | logical indicate if log10 transformation is needed, default F.
`binwidth` | binwidth for the combined plot. If NULL (default), will automatic assign binwidth.
`combine.plot` | Logical indicate if all the plot should be combined into one, with same scale (/same axises breaks), same color theme, and same bin size for comparison.
`output` | logical indicate if output file should be generated.
`proportion` | numeric vector with estimates of each component's proportion of the whole data.
`means` | numeric vector with estimates of mean(mu) values for each component.

### Details

Components analysis uses the likelihood ratio test (LRT) to assess the number of mixture components. Bad Random seed generation may cause normalmixEM to crash. Using another seed will solve the issue.

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

### Value

proportions

  The proportions of mixing components.

mean

  The Means of the components.

sd

  The Standard Deviations (SD) of components if not log transformed; if log transformed, it is then interpreted as Coefficient of Variation (CV).

loglik

  The log likelihood, useful for compare different fitting result, the bigger the better fit.

### 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)
    MSD=msd(trackll=trackll)
    dcoef=Dcoef(MSD,dt=6,plot=TRUE,output=FALSE)

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

    # fit dcoef (function automatically saves seed state as an attribute of
    # the result)
    a=fitNormDistr(dcoef,components=NULL,log.transform=FALSE,
                   combine.plot=FALSE, output=FALSE)

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

    b=fitNormDistr(dcoef,components=NULL,log.transform=FALSE,
    combine.plot=FALSE,output=FALSE)

    # if 'a' and 'b' are the same
    mapply(identical,a[[1]],b[[1]])

    #try with log transformation
    set.seed(234)
    c=fitNormDistr(dcoef,components=2,log.transform=TRUE,combine.plot=FALSE,
                   output=FALSE)

    # trying with some parameters provided(this will be applied to all dcoef
    # results).
    # with constrain = FALSE, this will be used as the starting values for the
    # EM-algorithm
    # normally we should deal with only one dataset when working with
    # constrains, since it will apply to all of them.
    folder3=system.file("extdata","HSF", package="sojourner")
    trackll=compareFolder(c(folder3),input=3)
    MSD=msd(trackll=trackll)
    dcoef=Dcoef(MSD,dt=6,plot=TRUE,output=FALSE)

    # try with constrain=TRUE, the values will be forced to equal the provided
    # ones.
    set.seed(345)
    e=fitNormDistr(dcoef,means=c(0.3,0.5), constrain=TRUE)

[Package sojourner version 1.6.0 Index]