[prev in list] [next in list] [prev in thread] [next in thread]
List: r-devel
Subject: Re: [Rd] Understanding some code within nls()
From: peter dalgaard <pdalgd () gmail ! com>
Date: 2022-06-25 8:20:39
Message-ID: 6E828323-BAA5-4997-B9BC-95674C4A05A3 () gmail ! com
[Download RAW message or body]
Where do you see that?
I see two instances in nls.R of
setPars = function(newPars) {...
but they are both part of a list element assignment, not function definitions as \
such. I.e., they are used for exporting an internal function to the outside world. \
The function sets variables in the environment of its defining function (e.g. \
nlsModel()), hence the <<-
AFAICT, the code you write would die in an infite recursion immediately.
- Peter
> On 24 Jun 2022, at 18:11 , J C Nash <profjcnash@gmail.com> wrote:
>
> In working to try to improve the nls() function, a Google Summer of Code \
> contributor and I have found our understanding of the setPars() function in nls() \
> in base R to be inadequate.
>
> setPars <- function(newPars) {
> setPars(newPars)
> resid <<- .swts * (lhs - (rhs <<- getRHS())) # envir = thisEnv {2 x}
> dev <<- sum(resid^2) # envir = thisEnv
> if(length(gr <- attr(rhs, "gradient")) == 1L) gr <- c(gr)
> QR <<- qr(.swts * gr) # envir = thisEnv
> (QR$rank < min(dim(QR$qr))) # to catch the singular gradient matrix
> }
>
> There is a similar but not identical function in the minpack.lm.
>
> I'd be grateful if anyone who has ideas on how this function is working
> (in particular why the recursive call and then the "<<-" assignments are
> needed) would get in touch offline to profjcnash _at_ gmail.com. I suspect
> a list discussion is not useful without some preparatory work to narrow
> the queries.
>
> My intention is to write up a 1-2 page explanation as a prelude to modifying
> code to introduce Marquardt stabilizations and bounds-constrained parameters,
> which nls() currently lacks. Also I have examples where minpack.lm seems
> to be failing to get bounds constraints correct. The nlsr package (Duncan
> Murdoch and myself) does get these correct, but focusses on solving the
> nonlinear least squares problem, and lacks many useful features for modeling
> that are found in nls(). However, nls() often fails due to "singular gradient"
> or else needs to use altered calls to apply special methods.
>
> Assuming some success, I'll post links to the list.
>
> John Nash
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes@cbs.dk Priv: PDalgd@gmail.com
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic