Skip to content
Prev 4149 / 63424 Next

Using the nls package

On Mon, Jul 31, 2000 at 07:20:32AM +0100, Prof Brian D Ripley wrote:
The only safe way I can think of would be to go for machine precision
as the default and then have some user-settable threshold for:

	( current residual / previous residual )
Undoubtably there is a lot more reading that I can do to improve
my understanding. I'm just making a suggestion based on the observation
that the algorithm actually found the right answer very quickly.
As it turns out, I am working with FFT data, I am looking for a transfer
function that will fit some admittance measurements.
The UTS library does have a copy but it isn't due back till September.

I searched a few of the local bookshops (over the internet) and
Diana Bates (with her children's stories) came up infinitely more often
than Douglas Bates and his regression. I will have to search the
University Co-op bookshop with my hands because the recent introduction of
GST has blown up their webpage.

Douglas, if you are reading this, what say you help me understand the
code in nls.R and nls.c and I'll promise to buy your book (though it could
take me a while to mail-order it in) ?
Consider also the case for fitting higher dimensional REAL data.
Admittedly, this is a contrived example but you may have an experiment
with one input variable and three output variables. You know from theory
that the output variables are all related to each other by some function
but you need to find particular parameters in that function:
Error in qr.qty(QR, resid) : qr and y must have the same number of rows

If the nls system supported these `wide' problems properly then complex
number support could just be recast as a special case of the same.
into a normal regression but with more sample points (and each sample
point repeated N times) and with a bogus input variable that gives the
column number. Thus, the same fundamental algorithm must work for both
cases if the structure of the data is suitably munged around.

I've been looking through the code in nls.c and nls.R quite closely and
I can see a lot of stuff which seems to be catering to cases of various
dimensional objects. I cannot fully comprehend what it does and I cannot
get a high dimensional case (such as the above) to work properly.

The crux of it seems to be that qr() needs a matrix to work on
so it uses as.matrix() to coerce its input. If you feed it a vector
you get a column matrix (sounds good), if you feed it a matrix you
have no problem, if you feed it a high dimensional tensor you get
a column vector (which surprised me), and qr() goes with that:
[1] 10  1
[1] 3 5
[1] 24  1

The result is that the nls model comes to grief when it feeds
the three dimensional tensor into qr() then what it gets back
(i.e. a long, thin column matrix) does not match up with anything.
But sqrt() DOES support complex numbers... so the assumption is that
most users will not expect complex numbers to crop up in their calculations
unless they were deliberately put there, but once deliberatly put there,
they work properly.

I would be happy to see two examples added to the documentation for sqrt,
those being sqrt(-1) and sqrt(-1+0i).

	- Tel



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Message-ID: <20000801160606.A2033@ftoomsh.progsoc.uts.edu.au>
In-Reply-To: <Pine.GSO.4.05.10007310708440.10573-100000@auk.stats>; from ripley@stats.ox.ac.uk on Mon, Jul 31, 2000 at 07:20:32AM +0100