This function performs the nonlinear fit of GGamma CDF of a variable x

fitLogNormDist(
  x,
  probability.x,
  parameter.values,
  summarized.data = FALSE,
  sample.size = 20,
  npoints = NULL,
  maxiter = 1024,
  ftol = 1e-12,
  ptol = 1e-12,
  maxfev = 1e+05,
  verbose = TRUE
)

Arguments

x

numerical vector

probability.x

probability vector of x. If not provided, the values are estimated using the empirical cumulative distribution function ('ecdf') from 'stats' R package.

parameter.values

initial parameter values for the nonlinear fit. If the locator parameter is included (mu != 0), this must be given as parameter.values = list(alpha = 'value', scale = 'value', mu = 'value') or if mu = 0, as: parameter.values = list(alpha = 'value', scale = 'value'). If not provided, then an initial guess is provided.

summarized.data

Logic value. If TRUE (default: FALSE), summarized data based on 'npoints' are used to perform the nonlinear fit.

sample.size

size of the sample.

npoints

number of points used in the fit.

maxiter

positive integer. Termination occurs when the number of iterations reaches maxiter. Default value: 1024.

ftol

non-negative numeric. Termination occurs when both the actual and predicted relative reductions in the sum of squares are at most ftol. Therefore, ftol measures the relative error desired in the sum of squares. Default value: 1e-12

ptol

non-negative numeric. Termination occurs when the relative error between two consecutive iterates is at most ptol. Therefore, ptol measures the relative error desired in the approximate solution. Default value: 1e-12.

maxfev

integer; termination occurs when the number of calls to fn has reached maxfev. Note that nls.lm sets the value of maxfev to 100*(length(par) + 1) if maxfev = integer(), where par is the list or vector of parameters to be optimized.

verbose

if TRUE, prints the function log to stdout

Value

Model table with coefficients and goodness-of-fit results: Adj.R.Square, deviance, AIC, R.Cross.val, and rho, as well as, the coefficient covariance matrix.

Details

The algorithm tries to fit the two-parameter LogNorm CDF using a modification of Levenberg-Marquardt algorithm implemented in function 'nls.lm' from 'minpack.lm' package that is used to perform the nonlinear fit. Cross-validations for the nonlinear regressions (R.Cross.val) were performed in each methylome as described in reference (1). In addition, Stein's formula for adjusted R squared (rho) was used as an estimator of the average cross-validation predictive power (1).

If the number of values to fit is >10^6, the fitting to a LogNorm CDF would be a time consuming task. To reduce the computational time, the option 'summarized.data' can be set 'TRUE'. If summarized.data = TRUE, the original variable values are summarized into 'npoint' bins and their midpoints are used as the new predictors. In this case, only the goodness-of-fit indicators AIC and R.Cross.val are estimated based on all the original variable x values.

References

  1. Stevens JP. Applied Multivariate Statistics for the Social Sciences. Fifth Edit. Routledge Academic; 2009.

Author

Robersy Sanchez - 04/09/2019

Examples

set.seed(126)
x <- rlnorm(1000, meanlog = 1.03, sdlog = 2.1)
fitLogNormDist(x)
#> *** Trying nonlinear fit to a Log-Normal Dist.distribution model ...
#> *** Performing nonlinear regression model  crossvalidation...
#>         Estimate   Std. Error  t value Pr(>|t|))      Adj.R.Square
#> meanlog 1.013025 0.0007225363 1402.041         0 0.999999988821257
#> sdlog   1.997010 0.0012082324 1652.836         0                  
#>                       rho       R.Cross.val                  DEV
#> meanlog 0.999999988798855 0.999886282714612 9.30628464170656e-07
#> sdlog                                                           
#>                       AIC               BIC     COV.mean       COV.sd  df
#> meanlog -7979.03725044855 -7959.40622933263 5.220586e-07 1.296256e-08 998
#> sdlog                                       1.296256e-08 1.459826e-06 998