[R] Unable to retrieve residual sum of squares from nls output

Jun Shen jun.shen.ut at gmail.com
Fri Aug 13 23:33:31 CEST 2010


Hi, Dennis,

Does this give what you want?

>sum(resid(FIT)^2)

Jun

Senior Pharmacokineticist
Seventh Wave Labs
On Fri, Aug 13, 2010 at 4:21 PM, Dennis Fisher <fisher at plessthan.com> wrote:
> Colleagues,
>
> I am using "nls" successfully (2.11.1, OS X) but I am having difficulties retrieving part of the output - residual sum of squares.  I have assigned the output to FIT:
>> > FIT
>> Nonlinear regression model
>>   model:  NEWY ~ PMESOR + PAMPLITUDE * cos(2 * pi * (NEWX - POFFSET)/PERIOD)
>>    data:  parent.frame()
>>     PMESOR PAMPLITUDE    POFFSET
>>    1153.02   -1183.09      24.58
>>  residual sum-of-squares: 1815056
>>
>> Number of iterations to convergence: 8
>> Achieved convergence tolerance: 1.643e-08
>
> As you can see, the object contains "residual sum-of-squares: 1815056".  However, I can't figure out how to grab that value.   The tried using "str":
>> > str(FIT)
>> List of 6
>>  $ m          :List of 16
>>   ..$ resid     :function ()
>>   ..$ fitted    :function ()
>>   ..$ formula   :function ()
>>   ..$ deviance  :function ()
>>   ..$ lhs       :function ()
>>   ..$ gradient  :function ()
>>   ..$ conv      :function ()
>>   ..$ incr      :function ()
>>   ..$ setVarying:function (vary = rep(TRUE, length(useParams)))
>>   ..$ setPars   :function (newPars)
>>   ..$ getPars   :function ()
>>   ..$ getAllPars:function ()
>>   ..$ getEnv    :function ()
>>   ..$ trace     :function ()
>>   ..$ Rmat      :function ()
>>   ..$ predict   :function (newdata = list(), qr = FALSE)
>>   ..- attr(*, "class")= chr "nlsModel"
>>  $ convInfo   :List of 5
>>   ..$ isConv     : logi TRUE
>>   ..$ finIter    : int 8
>>   ..$ finTol     : num 1.64e-08
>>   ..$ stopCode   : int 0
>>   ..$ stopMessage: chr "converged"
>>  $ data       : language parent.frame()
>>  $ call       : language nls(formula = NEWY ~ PMESOR + PAMPLITUDE * cos(2 * pi * (NEWX -      POFFSET)/PERIOD), start = list(PMESOR = MESOR, PAMPLITUDE = AMPLITUDE,  ...
>>  $ dataClasses: Named chr "numeric"
>>   ..- attr(*, "names")= chr "NEWX"
>>  $ control    :List of 2
>>   ..$ maxiter : num 1000
>>   ..$ warnOnly: logi TRUE
>>  - attr(*, "class")= chr "nls"
>
> However, none of these elements appears to contain the residual sum of squares.
> Help!  Thanks.
>
> Dennis
>
>
>
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list