simple.nlsfit: NLS fit with without bootstrap

View source: R/bootstrap.nlsfit.R

simple.nlsfitR Documentation

NLS fit with without bootstrap

Description

NLS fit with without bootstrap

Usage

simple.nlsfit(fn, par.guess, y, x, errormodel, priors = list(param = c(), p =
  c(), psamples = c()), ..., lower = rep(x = -Inf, times =
  length(par.guess)), upper = rep(x = +Inf, times = length(par.guess)), dy,
  dx, CovMatrix, boot.R = 0, gr, dfn, mask, use.minpack.lm = TRUE,
  error = sd, maxiter = 500, success.infos = 1:3,
  relative.weights = FALSE, na.rm = FALSE)

Arguments

fn

fn(par, x, ...). The (non-linear) function to be fitted to the data. Its first argument must be the fit parameters named par. The second must be x, the explaining variable. Additional parameters might be passed to the function. Currently we pass boot.r which is 0 for the original data and the ID (1, ...) of the bootstrap sample otherwise. As more parameters might be added in the future it is recommended that the fit function accepts ... as the last parameter to be forward compatible.

par.guess

initial guess values for the fit parameters.

y

the data as a one-dimensional numerical vector to be described by the fit function.

x

values of the explaining variable in form of a one-dimensional numerical vector.

errormodel

Either "yerrors" or "xyerrors", depending on the x-values having errors or not.

priors

List possessing the elements param, p and psamples. The vector param includes the indices of all fit parameters that are to be constrained and the vector p the corresponding paramater values (e.g. known from a previous fit). The list element psamples is a matrix of dimensions (boot.R, length(param)) and contains the corresponding bootstrap samples. If this list is not specified priors are omitted within the fit.

...

Additional parameters passed to fn, gr and dfn.

lower

Numeric vector of length length(par.guess) of lower bounds on the fit parameters. If missing, -Inf will be set for all.

upper

Numeric vector of length length(par.guess) of upper bounds on the fit parameters. If missing, +Inf will be set for all.

dy, dx

Numeric vector. Errors of the dependent and independent variable, respectively. These do not need to be specified as they can be computed from the bootstrap samples. In the case of parametric bootstrap it might would lead to a loss of information if they were computed from the pseudo-bootstrap samples. They must not be specified if a covariance matrix is given.

CovMatrix

complete variance-covariance matrix of dimensions c(length(y), length(y)) or c(length(y)+length(x), length(y)+length(x)) depending on the errormodel. Pass NULL if the matrix has to be calculated from the bsamples. In that case, if the number of boostrap samples is small compared to the number of variables, singular value decomposition with small eigenvalue replacement will be used (see invertCovMatrix) to attempt a clean inversion. In case a variance-covariance matrix is passed, the inversion will simply be attempted using solve on the Cholesky decomposition. Finally, if CovMatrix is missing, an uncorrelated fit will be performed.

boot.R

If larger than 0, boot.R paramtetric bootstrap samples are generated on the fit results after fit and error calculation are finished. The original data is never boostraped in this function.

gr

gr(par, x, ...). gr=d(fn) / d(par) is a function to return the gradient of fn. It must return an array with length(x) rows and length(par) columns.

dfn

dfn(par, x, ...). dfn=d(fn) / dx is the canonical derivative of fn by x and only relevant if x-errors are provided.

mask

logical or integer index vector. The mask is applied to select the observations from the data that are to be used in the fit. It is applied to x, y, dx, dy, bsamples and CovMatrix as applicable.

use.minpack.lm

use the minpack.lm library if available. This is usually faster than the default optim but somtimes also less stable.

error

Function that takes a sample vector and returns the error estimate. This is a parameter in order to support different resampling methods like jackknife.

maxiter

integer. Maximum number of iterations that can be used in the optimization process.

success.infos

integer vector. When using minpack.lm there is the info in the return value. Values of 1, 2 or 3 are certain success. A value of 4 could either be a success or a saddle point. If you want to interpret this as a success as well just pass 1:4 instead of the default 1:3.

relative.weights

are the errors on y (and x) to be interpreted as relative weights instead of absolute ones? If TRUE, the covariance martix of the fit parameter results is multiplied by chi^2/dof. This is the default in many fit programs, e.g. gnuplot.

na.rm

logical. If set to true, NAs in y and dy will be ignored. If x-errors are taken into account, NAs in x and dx will be ignored, too.

Value

Returns an object of class bootstrapfit, see bootstrap.nlsfit.

See Also

Other NLS fit functions: bootstrap.nlsfit(), parametric.bootstrap.cov(), parametric.bootstrap(), parametric.nlsfit.cov(), parametric.nlsfit(), plot.bootstrapfit(), predict.bootstrapfit(), print.bootstrapfit(), summary.bootstrapfit()

Examples

## Declare some data.
value <- c(0.1, 0.2, 0.3)
dvalue <- c(0.01, 0.01, 0.015)
x <- c(1, 2, 3)
dx <- c(0.1, 0.1, 0.1)

fn <- function (par, x, ...) par[1] + par[2] * x

fit.result <- simple.nlsfit(fn, c(1, 1), value, x, "xyerrors", dy=dvalue, dx=dx)
summary(fit.result)

hadron documentation built on Sept. 9, 2022, 5:06 p.m.