nls.lm

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

nls.lm

Mike meyer
How do you reply to a specific post on this board instead of the thread?
I am too incompetent to find this out myself.

Thanks,

Michael
unaffiliated

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: nls.lm

David Winsemius

> On Oct 19, 2016, at 12:16 PM, Mike meyer <[hidden email]> wrote:
>
> How do you reply to a specific post on this board instead of the thread?
> I am too incompetent to find this out myself.

Most of us use a mail-client that supports 'reply-to-all'. And the Posting Guide asks you to include sufficient context which you have been consistently failing to do.

--
David.

>
> Thanks,
>
> Michael
> unaffiliated
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: nls.lm

S Ellison-2
In reply to this post by Mike meyer
> How do you reply to a specific post on this board instead of the thread?

You can reply to the individual, as I just did.

But I strongly suggest that you don't. You would be much better advised to discontinue debate and follow the essential advice given by nls.lm, which - no matter whether couched in terms of count of residuals - is simply to make sure that you have more independent data than variables when seeking a unique numerical solution by non-linear least squares. If you don't you'll get nonsense.


S Ellison





*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: nls.lm

J C Nash
>From a statistician's point of view, "nonsense" may be OK, but there are other applications of R where
(partial or non-unique) solutions may be needed.

Yesterday I raised the question of how nonlinear least squares could be adapted to underdetermined problems.
Many folk are unaware of such possibilities, even in the linear case. In the nonlinear case, the m>n condition is
far from adequate to provide appropriate warnings to users. What should we do to detect non-unique solutions?

My interest is in building better nonlinear least squares and optimization software, and I find software users
(including R users) have some belief that those of us building the tools they use are magic wizards or fairy
godmothers who have provided everything they need in bullet-proof packages. This is so far from reality. All of
the tools I have worked with have weaknesses. To close the loopholes we need those "small reproducible examples",
including cases like these, so that better diagnostics can be devised.

We also need discussion on what to present as diagnostics and how to do so for maximum benefit and least
"get in the way". A two-way communication with users can aid immensely.

Sorry for the rant, but I'm in the midst of trying to prepare a unification of nls/nlmrt/minpack.lm and some
of the effort is pretty messy, especially in the area of derivatives and diagnostics.

Below is a little script that tries Berend's problem. The nonlinear least squares "runs" but the output fails
except for str(). The script will stop on failure at some points, so you need to paste some statements. I welcome
similar scripts/examples to build the necessary tests for improved packages.

JN

Here's the script.

# try to solve undetermined system by nonlinear least squares
X1 <- c(1,1)
Y1 <- c(1,1)
Z1 <- c(1,1)
RHS1 <- c(3,4)
X2 <- c(1,2)
RHS2 <- c(3,6)
mydata <- data.frame(X1, X2, Y1, Z1, RHS1, RHS2)
require(nlmrt)
st1 <- c(px=1,py=1,pz=1)
st0 <- c(px=0,py=0,pz=0)
sol10 <- nlxb(RHS1 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st0)
summary(sol10)
print(sol10)
str(sol10)
sol11 <- nlxb(RHS1 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st1)
summary(sol11)
print(sol11)
str(sol11)
## try RHS2
sol20 <- nlxb(RHS2 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st0)
summary(sol20)
print(sol20)
str(sol20)
sol21 <- nlxb(RHS2 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st1)
summary(sol21)
print(sol21)
str(sol21)
# change first column -- then we get solutions
sol220 <- nlxb(RHS2 ~ px*X2 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st0)
summary(sol220)
print(sol220)
str(sol220)
sol221 <- nlxb(RHS2 ~ px*X2 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st1)
summary(sol221)
print(sol221)
str(sol221)



On 16-10-20 07:05 AM, S Ellison wrote:

>> How do you reply to a specific post on this board instead of the thread?
>
> You can reply to the individual, as I just did.
>
> But I strongly suggest that you don't. You would be much better advised to discontinue debate and follow the essential advice given by nls.lm, which - no matter whether couched in terms of count of residuals - is simply to make sure that you have more independent data than variables when seeking a unique numerical solution by non-linear least squares. If you don't you'll get nonsense.
>
>
> S Ellison
>
>
>
>
>
> *******************************************************************
> This email and any attachments are confidential. Any use...{{dropped:8}}
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: nls.lm

Mike meyer
Let's take a different view of the problem.
Given f=(f_1,...,f_m):R^n -> R^m we want to minimize ||f(x)||.

What distinguishes this from a general minimization problem is that you know the structure of the
objective function F(x)=||f(x)||² and have the individual constituents f_j.
Make use of that information as appropriate.

This is more general than trying to solve the system f(x)=0 or fitting a model to data.
In this more general setting notions such as underdetermined/overdetermined system do not apply.

The restricted view of model fitting serves only to confuse the issue.
For that reason it is (in my view) a bad idea to force the user to set up his problem in
R-model notation.

Michael
unaffiliated


> Gesendet: Donnerstag, 20. Oktober 2016 um 15:26 Uhr
> Von: ProfJCNash <[hidden email]>
> An: "S Ellison" <[hidden email]>, "Mike meyer" <[hidden email]>
> Cc: "[hidden email]" <[hidden email]>, "Berend Hasselman" <[hidden email]>
> Betreff: Re: [R] nls.lm
>
> From a statistician's point of view, "nonsense" may be OK, but there are other applications of R where
> (partial or non-unique) solutions may be needed.
>
> Yesterday I raised the question of how nonlinear least squares could be adapted to underdetermined problems.
> Many folk are unaware of such possibilities, even in the linear case. In the nonlinear case, the m>n condition is
> far from adequate to provide appropriate warnings to users. What should we do to detect non-unique solutions?
>
> My interest is in building better nonlinear least squares and optimization software, and I find software users
> (including R users) have some belief that those of us building the tools they use are magic wizards or fairy
> godmothers who have provided everything they need in bullet-proof packages. This is so far from reality. All of
> the tools I have worked with have weaknesses. To close the loopholes we need those "small reproducible examples",
> including cases like these, so that better diagnostics can be devised.
>
> We also need discussion on what to present as diagnostics and how to do so for maximum benefit and least
> "get in the way". A two-way communication with users can aid immensely.
>
> Sorry for the rant, but I'm in the midst of trying to prepare a unification of nls/nlmrt/minpack.lm and some
> of the effort is pretty messy, especially in the area of derivatives and diagnostics.
>
> Below is a little script that tries Berend's problem. The nonlinear least squares "runs" but the output fails
> except for str(). The script will stop on failure at some points, so you need to paste some statements. I welcome
> similar scripts/examples to build the necessary tests for improved packages.
>
> JN
>
> Here's the script.
>
> # try to solve undetermined system by nonlinear least squares
> X1 <- c(1,1)
> Y1 <- c(1,1)
> Z1 <- c(1,1)
> RHS1 <- c(3,4)
> X2 <- c(1,2)
> RHS2 <- c(3,6)
> mydata <- data.frame(X1, X2, Y1, Z1, RHS1, RHS2)
> require(nlmrt)
> st1 <- c(px=1,py=1,pz=1)
> st0 <- c(px=0,py=0,pz=0)
> sol10 <- nlxb(RHS1 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st0)
> summary(sol10)
> print(sol10)
> str(sol10)
> sol11 <- nlxb(RHS1 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st1)
> summary(sol11)
> print(sol11)
> str(sol11)
> ## try RHS2
> sol20 <- nlxb(RHS2 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st0)
> summary(sol20)
> print(sol20)
> str(sol20)
> sol21 <- nlxb(RHS2 ~ px*X1 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st1)
> summary(sol21)
> print(sol21)
> str(sol21)
> # change first column -- then we get solutions
> sol220 <- nlxb(RHS2 ~ px*X2 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st0)
> summary(sol220)
> print(sol220)
> str(sol220)
> sol221 <- nlxb(RHS2 ~ px*X2 + py*Y1 + pz*Z1, data=mydata, trace=1, start=st1)
> summary(sol221)
> print(sol221)
> str(sol221)
>
>
>
> On 16-10-20 07:05 AM, S Ellison wrote:
> >> How do you reply to a specific post on this board instead of the thread?
> >
> > You can reply to the individual, as I just did.
> >
> > But I strongly suggest that you don't. You would be much better advised to discontinue debate and follow the essential advice given by nls.lm, which - no matter whether couched in terms of count of residuals - is simply to make sure that you have more independent data than variables when seeking a unique numerical solution by non-linear least squares. If you don't you'll get nonsense.
> >
> >
> > S Ellison
> >
> >
> >
> >
> >
> > *******************************************************************
> > This email and any attachments are confidential. Any use...{{dropped:8}}
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > 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.
> >
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: nls.lm

Berend Hasselman

> On 21 Oct 2016, at 06:00, Mike meyer <[hidden email]> wrote:
>
> Let's take a different view of the problem.
> Given f=(f_1,...,f_m):R^n -> R^m we want to minimize ||f(x)||.
>
> What distinguishes this from a general minimization problem is that you know the structure of the
> objective function F(x)=||f(x)||² and have the individual constituents f_j.
> Make use of that information as appropriate.
>
> This is more general than trying to solve the system f(x)=0 or fitting a model to data.
> In this more general setting notions such as underdetermined/overdetermined system do not apply.
>
> The restricted view of model fitting serves only to confuse the issue.
> For that reason it is (in my view) a bad idea to force the user to set up his problem in
> R-model notation.
>

I assume that you have been referring to the R package minpack.lm.

I've had a look at the underlying Fortran code (from Minpack and developed by More et.al.  made in a distant past) as used by the package.
That underlying code returns an error when the condition:  number of functions (m)  >=  the number of independent variables (n)
is not satisfied i.e. when m < n.

Making that more general would entail a lot of thinking and reworking of the code. As far as I can see it is not possible to just remove the condition m>=n from the underlying Fortran. More (possibly many) changes would be required. Blaming R and/or the package author/maintainer is unfair.

If you require a more general version of the algorithm or if you want something else you will have to roll your own package/code.
If you don't feel that minpack.lm is appropriate for your application and you want changes you'll have to discuss matters with Moré (http://www.mcs.anl.gov/~more/) if I got the correct link.

Berend

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: nls.lm

J C Nash
Berend's point is well-taken. It's a lot of work to re-jig a code, especially one more than
30 years old.

On the other hand, nlmrt is all-R, and it does more or less work on underdetermined systems as I
illustrated in a small script. The changes needed to treat the problem as Mike suggests are
pretty easy, but they imply that some aspects of the modeling computations have to be omitted.
Mike: If you give that a try, I'd be interested in outcomes, and am willing to answer questions
on how the code works.

Indeed, I want to include the sort of "diagnostics" that allow underdetermined systems
in my packages, so that some results are replaced with NA or NULL and helpful warnings rather
than "Failed m<n" are reported.

Best, JN

On 16-10-21 03:39 AM, Berend Hasselman wrote:

>
>> On 21 Oct 2016, at 06:00, Mike meyer <[hidden email]> wrote:
>>
>> Let's take a different view of the problem.
>> Given f=(f_1,...,f_m):R^n -> R^m we want to minimize ||f(x)||.
>>
>> What distinguishes this from a general minimization problem is that you know the structure of the
>> objective function F(x)=||f(x)||² and have the individual constituents f_j.
>> Make use of that information as appropriate.
>>
>> This is more general than trying to solve the system f(x)=0 or fitting a model to data.
>> In this more general setting notions such as underdetermined/overdetermined system do not apply.
>>
>> The restricted view of model fitting serves only to confuse the issue.
>> For that reason it is (in my view) a bad idea to force the user to set up his problem in
>> R-model notation.
>>
>
> I assume that you have been referring to the R package minpack.lm.
>
> I've had a look at the underlying Fortran code (from Minpack and developed by More et.al.  made in a distant past) as used by the package.
> That underlying code returns an error when the condition:  number of functions (m)  >=  the number of independent variables (n)
> is not satisfied i.e. when m < n.
>
> Making that more general would entail a lot of thinking and reworking of the code. As far as I can see it is not possible to just remove the condition m>=n from the underlying Fortran. More (possibly many) changes would be required. Blaming R and/or the package author/maintainer is unfair.
>
> If you require a more general version of the algorithm or if you want something else you will have to roll your own package/code.
> If you don't feel that minpack.lm is appropriate for your application and you want changes you'll have to discuss matters with Moré (http://www.mcs.anl.gov/~more/) if I got the correct link.
>
> Berend
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: nls.lm

Mike meyer
In reply to this post by Berend Hasselman
Please accept my apologies as I was in fact wrong.

It was not my intention to attack minpack.lm or criticize the maintainer.
I like minpack.lm and am fully aware of the effort involved in rewriting the
code. Next time I'll use more careful wording.

Thanks also to Professor Nash for his efforts. I look forward to the results.


Best regards,

Michael
unaffiliatd




> Gesendet: Freitag, 21. Oktober 2016 um 09:39 Uhr
> Von: "Berend Hasselman" <[hidden email]>
> An: "Mike meyer" <[hidden email]>
> Cc: ProfJCNash <[hidden email]>, "[hidden email]" <[hidden email]>
> Betreff: Re: [R] nls.lm
>
>
> > On 21 Oct 2016, at 06:00, Mike meyer <[hidden email]> wrote:
> >
> > Let's take a different view of the problem.
> > Given f=(f_1,...,f_m):R^n -> R^m we want to minimize ||f(x)||.
> >
> > What distinguishes this from a general minimization problem is that you know the structure of the
> > objective function F(x)=||f(x)||² and have the individual constituents f_j.
> > Make use of that information as appropriate.
> >
> > This is more general than trying to solve the system f(x)=0 or fitting a model to data.
> > In this more general setting notions such as underdetermined/overdetermined system do not apply.
> >
> > The restricted view of model fitting serves only to confuse the issue.
> > For that reason it is (in my view) a bad idea to force the user to set up his problem in
> > R-model notation.
> >
>
> I assume that you have been referring to the R package minpack.lm.
>
> I've had a look at the underlying Fortran code (from Minpack and developed by More et.al.  made in a distant past) as used by the package.
> That underlying code returns an error when the condition:  number of functions (m)  >=  the number of independent variables (n)
> is not satisfied i.e. when m < n.
>
> Making that more general would entail a lot of thinking and reworking of the code. As far as I can see it is not possible to just remove the condition m>=n from the underlying Fortran. More (possibly many) changes would be required. Blaming R and/or the package author/maintainer is unfair.
>
> If you require a more general version of the algorithm or if you want something else you will have to roll your own package/code.
> If you don't feel that minpack.lm is appropriate for your application and you want changes you'll have to discuss matters with Moré (http://www.mcs.anl.gov/~more/) if I got the correct link.
>
> Berend
>
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.