[R] nls.lm

ProfJCNash profjcnash at gmail.com
Thu Oct 20 15:26:23 CEST 2016


>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}}
> 
> ______________________________________________
> R-help at r-project.org 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.
>



More information about the R-help mailing list