Description Objects from the Class Slots Extends Methods Note Author(s) References See Also Examples
It is a class of nonlinear regression model function, can embed expression formula and function. It is a more general object such that the heterogeneous variance model and robust loss function in nlr
is saved as nl.form
object.
Objects can be created by calls of the form:
new("nl.form",formula,fnc,formtype,p, inv=NULL,name=name,par,arguments=list(...),dependent, independent,origin,selfStart)
,
or constructor:
nl.form(form,p=NULL,inv=NULL,name,par=NULL,dependent=NULL,independent=NULL,origin=NULL,selfStart=NULL,...)
formula
:Object of class "call or NULL"
it can be 1- a two sided formula with response (or a function of response) in left of ~ and nonlinear function model is a function of predictors and parameters, or 2- a one sided formula with ~nonlinear model in right, is again a function of predictors and unknown parameters. If Null then the nonlinear model is a R function stored in fnc
slot as bellow. Each of right side or left side formula can return "gradient" and "hessian" as attributed value.
fnc
:Object of class "function or NULL"
is nonlinear model stored as R function.
dependent
:Object of class "characterorNULL"
of predictor variable, null value means the formula
slot is one sided.
independent
:Object of class "characterorNULL"
caharacter vector name of predictor variables, which can be more than one predictor.
formtype
:Object of class "character"
character type of nl.form
. Do not insert this slot, it will be set automatically by creater, it use internaly for evaluation.
p
:Object of class "numericorNULL"
number of parameters.
inv
:Object of class "callorNULL"
if nonlinear model is function of one predictor the inverse function define in this slot. Still not functioning, designed for feature extention, so it can be ignored at the moment, but it is better to define.
name
:Object of class "character"
a character name for the nonlinear function model.
par
:Object of class "list"
of parameters, assigned value to parameters will be used in worst case that initial values can not be computed.
arguments
:Object of class "list"
list of extra arguments use in formula
or fnc
slot.
origin
:Object of class "callorNULL"
is original one sided or two sided expression of nonlinear model withought gradient and hessian.
selfStart
:Object of class "functionorNULL"
selfstart function defined for initial values guiss. Is same as nls or nlme::nlme functions.
Class "nl.formorNULL"
, directly.
signature(x = "nl.form")
: return slots.
signature(expr = "nl.form")
: Return a character vector containing all the names which occur in "formula"
or or "fnc"
.
signature(expr = "nl.form")
: evaluate nl.form
object in the environment include parameters and predictor variables.
signature(expr = "nl.form")
: same functionality as eval but extended for compatibility. eval.nl.form
has same functionality created for compatibility purpose.
signature(object = "nl.form")
: get initial value from selfstart or par slot.
signature(model = "nl.form")
: self computing initial value, if not given "getInitial"
method return initial values from environment or "par" slot.
signature(expr = "eval.nl.form")
: eval.nl.form
has same functionality as eval
, created for compatibility purpose.
this object typicaly implemented to store a nonlinear regression model function informations. But extensively used in nlr
package to save heteroscedastic variances and robust loss functions.
Hossein Riazoshams, 2013. Email: riazihosein@gmail.com URL http://www.riazoshams.com/nlr/
Riazoshams H, Midi H, and Ghilagaber G, 2018,. Robust Nonlinear Regression, with Application using R, Joh Wiley and Sons.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # define hampel robust loss as a function
hampel <- nl.form(
form = function(t,
a = 1.345,
k0 = 3.73677,
k1 = 4,
maxrho5 = 1.345,
...) {
U <- abs(t)
Ugrta <- (U > abs(a))
.rho <- .grad <- .hess <- .weight <- NULL
.rho[Ugrta] <- 2. * abs(a) * U[Ugrta] - a * a
.rho[!Ugrta] <- t[!Ugrta] ^ 2
.grad[Ugrta] <- 2. * abs(a) * sign(t[Ugrta])
.grad[!Ugrta] <- 2. * t[!Ugrta]
.hess[Ugrta] <- 0.
.hess[!Ugrta] <- 2.
.weight[Ugrta] <- 2. * abs(a) / U[Ugrta]
.weight[!Ugrta] <- 2.
attr(.rho, "gradient") <- .grad
attr(.rho, "hessian") <- .hess
attr(.rho, "weight") <- .weight
return(.rho)
},
name = "huber",
independent = "t",
a = 1.345,
k0 = 3.73677,
k1 = 4,
maxrho5 = 1.345
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.