resss: Compute sum of squares from residuals via the residual...

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

For a nonlinear model originally expressed as an expression of the form lhs ~ formula_for_rhs assume we have a resfn and jacfn that compute the residuals and the Jacobian at a set of parameters. This routine computes the sum of squares of the residuals.

Usage

1
   resss(prm, resfn, ...)

Arguments

prm

A parameter vector. For our example, we could use start=c(b1=1, b2=2.345, b3=0.123) However, the names are NOT used, only positions in the vector.

resfn

A function to compute the residuals of our model at a parameter vector.

...

Any data needed for computation of the residual vector from the expression rhsexpression - lhsvar. Note that this is the negative of the usual residual, but the sum of squares is the same.

Details

resss calls resfn to compute residuals and then uses crossprod to compute the sum of squares.

At 2012-4-26 there is no checking for errors. The evaluations of residuals and the cross product could be wrapped in try() if the evaluation could be inadmissible.

Value

The scalar numeric value of the sum of squares at the paramters.

Author(s)

John C Nash <nashjc@uottawa.ca>

References

Nash, J. C. (1979, 1990) _Compact Numerical Methods for Computers. Linear Algebra and Function Minimisation._ Adam Hilger./Institute of Physics Publications

others!!

See Also

Function nls(), packages optim and optimx.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
shobbs.res  <-  function(x){ # scaled Hobbs weeds problem -- residual
# This variant uses looping
    if(length(x) != 3) stop("hobbs.res -- parameter vector n!=3")
    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  <-  1:12
    res  <-  100.0*x[1]/(1+x[2]*10.*exp(-0.1*x[3]*tt)) - y
}
 
st  <-  c(b1=1, b2=1, b3=1)

firstss<-resss(st, shobbs.res)
# The sum of squares of the scaled Hobbs function at parameters
st
firstss
# now illustrate how to get solution via optimization

tf <- function(prm){
  val <- resss(prm, shobbs.res)
}
testop <- optim(st, tf, control=list(trace=1))
testop


Search within the nlsr package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.