Perintah nls dan SSasympOrig untuk estimasi model non‐linear
14.2. Perintah nls dan SSasympOrig untuk estimasi model non‐linear
Ada beberapa perintah di paket R yang disediakan untuk menjalankan model regresi non‐linear, antara lain nls dan SSasympOrig. Contoh diatas merupakan salah satu aplikasi dari perintah nls pada suatu data real. Pada bagian ini akan diberikan rangkuman tentang perintah nls dan SSasympOrig, khususnya yang berkaitan dengan argumen ‐argumen yang dapat ditampilkan. Secara umum penggunaan perintah nls dan keterangan argumen yang disediakan adalah sebagai berikut.
nls(formula, data, start, control, algorithm, trace, subset, weights, na.action, model, lower, upper, ...)
Argumen Keterangan
formula a nonlinear model formula including variables and parameters. Will be coerced to a formula if necessary.
data an optional data frame in which to evaluate the variables in formula and weights . Can also be a list or an environment, but not a matrix. start a named list or named numeric vector of starting estimates. When start is missing, a very cheap guess for start is tried (if algorithm
!= "plinear" ).
control an optional list of control settings. See nls.control for the names of the settable control values and their effect.
algorithm character string specifying the algorithm to use. The default algorithm is a Gauss‐Newton algorithm. Other possible values are "plinear" for the Golub‐Pereyra algorithm for partially linear least‐squares models and "port" for the ‘nl2sol’ algorithm from the Port package.
trace logical value indicating if a trace of the iteration progress should be printed. Default is FALSE . If TRUE the residual (weighted) sum‐of‐ squares and the parameter values are printed at the conclusion of each iteration. When the "plinear" algorithm is used, the conditional estimates of the linear parameters are printed after the nonlinear parameters. When the "port" algorithm is used the objective function value printed is half the residual (weighted) sum‐of‐ squares.
subset an optional vector specifying a subset of observations to be used in the fitting process.
weights an optional numeric vector of (fixed) weights. When present, the objective function is weighted least squares.
na.action a function which indicates what should happen when the data contain NA s. The default is set by the na.action setting of options , and is na.fail if that is unset. The ‘factory‐fresh’ default is na.omit . Value na.exclude can be useful.
model logical. If true, the model frame is returned as part of the object. Default is FALSE .
lower, upper vectors of lower and upper bounds, replicated to be as long as start . If unspecified, all parameters are assumed to be unconstrained. Bounds can only be used with the "port" algorithm. They are ignored, with a warning, if given for other algorithms.
... Additional optional arguments. None are used at present.
SSasympOrig merupakan suatu perintah untuk aplikasi regresi non‐linear dengan fungsi yang spesifik, yaitu
Asym
1 − exp( − exp( lrc ) ∗ input )
dengan input adalah suatu vektor kovariat, dan Asym dan lrc merupakan parameter‐ parameter model. Secara umum penggunaan perintah SSasympOrig dan keterangan argumen yang disediakan adalah sebagai berikut.
SSasympOrig(input, Asym, lrc)
Argumen Keterangan
input a numeric vector of values at which to evaluate the model. Asym a numeric parameter representing the horizontal asymptote. lrc a numeric parameter representing the natural logarithm of the rate
constant.
Misalkan perintah SSasympOrig akan diaplikasikan pada data BOD yang sudah tersedia di R. Data ini terdiri dari dua variabel, yaitu Time dan demand. Berikut ini adalah script untuk aplikasi perintah SSasympOrig dan beberapa output berkaitan dengan taksiran model regresi non‐linear dan plot prediksi yang dihasilkan.
> BOD
Time demand
> fm <‐ nls(demand ~ SSasympOrig(Time, A, lrc), data = BOD) > # fm <‐ nls(demand ~ A*(1 ‐ exp(‐exp(lrc)*Time)), data=BOD,
start = list(A = 1, lrc=0.1), trace=TRUE)
> summary(fm)
Formula: demand ~ A * (1 ‐ exp(‐exp(lrc) * Time))
Parameters:
Estimate Std. Error t value Pr(>|t|) A 19.1426 2.4959 7.670 0.00155 ** lrc ‐0.6328 0.3824 ‐1.655 0.17328 ‐‐‐
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.549 on 4 degrees of freedom