[R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Janice Kielbassa
Hello!

I want to do a non-linear regression with 2 explanatory variables 
(something like : length ~ a * time * exp( b* temperature)), having a 
data set (length, time, temperature). Which function could I use (I 
tried nls but I think it doesn't work)
Thanks a lot!

Janice

__
R-help@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.


Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00
X-USF-Spam-Flag: NO

On Wed, 2008-01-16 at 11:02 +0100, Janice Kielbassa wrote:
 Hello!
 
 I want to do a non-linear regression with 2 explanatory variables 
 (something like : length ~ a * time * exp( b* temperature)), having a 
 data set (length, time, temperature). Which function could I use (I 
 tried nls but I think it doesn't work)

Janice, I'll start by saying I can't help you as I have never used nls()
myself and I am not familiar with this type of analysis.

Why do you think that nls() doesn't work? It is a widely used part of
R and thus probably very well tested.

My understanding of these things is that nls is a sophisticated tool
that requires some effort on the part of the user, such as selecting
appropriate starting values.

You are unlikely to get any further assistance from the list unless you
read the posting guide and post an example of what you did (preferably
with the actual data or dummy data with the same properties if not) and
the exact error message or output from R that lead you to believe that
nls() did not work.

HTH

G

 Thanks a lot!
 
 Janice
 
 __
 R-help@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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@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.


Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Roland Rau
Gavin Simpson wrote:
 hits=-2.6 tests=BAYES_00
 X-USF-Spam-Flag: NO
 
 On Wed, 2008-01-16 at 11:02 +0100, Janice Kielbassa wrote:
 Hello!

 I want to do a non-linear regression with 2 explanatory variables 
 (something like : length ~ a * time * exp( b* temperature)), having a 
 data set (length, time, temperature). Which function could I use (I 
 tried nls but I think it doesn't work)
 
 Janice, I'll start by saying I can't help you as I have never used nls()
 myself and I am not familiar with this type of analysis.
 

maybe it helps if you have a look at Chapter 10 Nonlinear Models by 
Douglas M. Bates and John M. Chambers in: John M. Chambers, Trevor J. 
Hastie (Eds.): Statistical Models in S. Chapman  Hall/CRC , 1992

Best,
Roland

__
R-help@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.


Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Rolf Turner

I have never had much success in using nls().  If you scan the archives
you will find one or two postings from me on this topic.  I have  
received
no useful responses to these postings.

I have found that anything that I tried (and failed) to do using nls()
could be done quite easily using optim().

cheers,

Rolf Turner


On 17/01/2008, at 3:56 AM, Gavin Simpson wrote:

 hits=-2.6 tests=BAYES_00
 X-USF-Spam-Flag: NO

 On Wed, 2008-01-16 at 11:02 +0100, Janice Kielbassa wrote:
 Hello!

 I want to do a non-linear regression with 2 explanatory variables
 (something like : length ~ a * time * exp( b* temperature)), having a
 data set (length, time, temperature). Which function could I use (I
 tried nls but I think it doesn't work)

 Janice, I'll start by saying I can't help you as I have never used  
 nls()
 myself and I am not familiar with this type of analysis.

 Why do you think that nls() doesn't work? It is a widely used  
 part of
 R and thus probably very well tested.

 My understanding of these things is that nls is a sophisticated tool
 that requires some effort on the part of the user, such as selecting
 appropriate starting values.


##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@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.


Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Katharine Mullen
Dear Rolf,

One thing that sometimes makes nls easier to apply is using the 'formula'
argument like you would use the 'fn' argument of optim.  That is, if you
have a residual function that has arguments x, y, a, b and you need to
optimize a and b, you would make a call like

nls(~resid(x,y,a=astart, b=bstart), control = nls.control(warnOnly =
   TRUE, printEval = TRUE), start = list(a=astart, b=bstart))

This did not work easily before R-2.6.0, but does now.  The Puromycin
analysis from the help files is an example of this useage and below is
another.

Or do you already use nls this way and still have problems?

# get data as a sum of exponentials
dataSumOfExp - function(rates = seq(.05, .005, length=3),
 times = 1:100,
 amps = rep(1, length(rates))) {
  tfun - function(t,r) exp(-r*t)
  ## get C with tfun
  C - mapply(tfun, r=rates, MoreArgs=list(t=times))
  ## add the columns of C with relative amplitudes 1, and add noise
  C %*% amps + rnorm( nrow(C) )  * max(C) * .1
}

# residual function
resFun - function(rates, amps, measured, times = 1:100) {
  tfun - function(t,r) exp(-r*t)
  CEst - mapply(tfun, r=rates, MoreArgs=list(t=times))
  measured - CEst %*% amps
}

# get data
measured - dataSumOfExp()

# optimize rates of exponentials and their relative amplitudes
res - nls(~resFun(rates = rates, measured = measured, amps = amps),
   control = nls.control(warnOnly = TRUE, printEval = TRUE),
   start = list(rates = c(.04, .1, .001),
 amps = rep(1,3)), trace = TRUE)

summary(res)

On Thu, 17 Jan 2008, Rolf Turner wrote:


 I have never had much success in using nls().  If you scan the archives
 you will find one or two postings from me on this topic.  I have
 received
 no useful responses to these postings.

 I have found that anything that I tried (and failed) to do using nls()
 could be done quite easily using optim().

   cheers,

   Rolf Turner


 On 17/01/2008, at 3:56 AM, Gavin Simpson wrote:

  hits=-2.6 tests=BAYES_00
  X-USF-Spam-Flag: NO
 
  On Wed, 2008-01-16 at 11:02 +0100, Janice Kielbassa wrote:
  Hello!
 
  I want to do a non-linear regression with 2 explanatory variables
  (something like : length ~ a * time * exp( b* temperature)), having a
  data set (length, time, temperature). Which function could I use (I
  tried nls but I think it doesn't work)
 
  Janice, I'll start by saying I can't help you as I have never used
  nls()
  myself and I am not familiar with this type of analysis.
 
  Why do you think that nls() doesn't work? It is a widely used
  part of
  R and thus probably very well tested.
 
  My understanding of these things is that nls is a sophisticated tool
  that requires some effort on the part of the user, such as selecting
  appropriate starting values.


 ##
 Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

 __
 R-help@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.


__
R-help@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.