model2rjfun function

model2rjfun

model2rjfun

These functions create functions to evaluate residuals or sums of squares at particular parameter locations.

model2rjfun(modelformula, pvec, data = NULL, jacobian = TRUE, testresult = TRUE, ...) SSmod2rjfun(modelformula, pvec, data = NULL, jacobian = TRUE, testresult = TRUE, ...) model2ssgrfun(modelformula, pvec, data = NULL, gradient = TRUE, testresult = TRUE, ...) modelexpr(fun)

Arguments

  • modelformula: A formula describing a nonlinear regression model.

  • pvec: A vector of parameters.

  • data: A dataframe, list or environment holding data used in the calculation.

  • jacobian: Whether to compute the Jacobian matrix.

  • testresult: Whether to test the function by evaluating it at pvec.

  • gradient: Whether to compute the gradient vector.

  • fun: A function produced by one of model2rjfun or model2ssgrfun.

  • ...: Dot arguments, that is, arguments that may be supplied by name = value

    to supply information needed to compute specific quantities in the model.

Details

If pvec does not have names, the parameters will have names generated in the form p_<n> , e.g. p_1, p_2. Names that appear in pvec will be taken to be parameters of the model.

The data argument may be a dataframe, list or environment, or NULL. If it is not an environment, one will be constructed using the components of data with parent environment set to be the environment of modelformula.

SSmod2rjfun returns a function with header function(prm), which evaluates the residuals (and if jacobian is TRUE the Jacobian matrix) of the selfStart model (the rhs is used) at prm. The residuals are defined to be the right hand side of modelformula

minus the left hand side. Note that the selfStart model used in the model formula must be available (i.e., loaded). If this function is called from nlxb() then the control element japprox must be set to value SSJac.

Returns

model2rjfun returns a function with header function(prm), which evaluates the residuals (and if jacobian is TRUE the Jacobian matrix) of the model at prm. The residuals are defined to be the right hand side of modelformula minus the left hand side.

model2ssgrfun returns a function with header function(prm), which evaluates the sum of squared residuals (and if gradient is TRUE the gradient vector) of the model at prm.

modelexpr returns the expression used to calculate the vector of residuals (and possibly the Jacobian) used in the previous functions.

Examples

# We do not appear to have an example for modelexpr. See nlsr-devdoc.Rmd for one. y <- c(5.308, 7.24, 9.638, 12.866, 17.069, 23.192, 31.443, 38.558, 50.156, 62.948, 75.995, 91.972) tt <- seq_along(y) # for testing mydata <- data.frame(y = y, tt = tt) f <- y ~ b1/(1 + b2 * exp(-1 * b3 * tt)) p <- c(b1 = 1, b2 = 1, b3 = 1) rjfn <- model2rjfun(f, p, data = mydata) rjfn(p) rjfnnoj <- model2rjfun(f, p, data = mydata, jacobian=FALSE) rjfnnoj(p) myexp <- modelexpr(rjfn) cat("myexp:"); print(myexp) ssgrfn <- model2ssgrfun(f, p, data = mydata) ssgrfn(p) ssgrfnnoj <- model2ssgrfun(f, p, data = mydata, gradient=FALSE) ssgrfnnoj(p)

See Also

nls

Author(s)

John Nash and Duncan Murdoch

  • Maintainer: John C Nash
  • License: GPL-2
  • Last published: 2023-09-05

Useful links