[R] nls: example code throws error

2013-04-26 Thread Steven LeBlanc
Greets,

I'm trying to learn to use nls and was running the example code for an 
exponential model:

 x - -(1:100)/10
 y - 100 + 10 * exp(x / 2) + rnorm(x)/10
 nlmod - nls(y ~  Const + A * exp(B * x))
Error in B * x : non-numeric argument to binary operator
In addition: Warning message:
In nls(y ~ Const + A * exp(B * x)) :
  No starting values specified for some parameters.
Initializing ‘Const’ to '1.'.
Consider specifying 'start' or using a selfStart model

Presumably, the code should work if it is part of an example on the help page. 
In perusing various help forums for similar problems, it also appears that 
others believe this syntax should work in the model formula.

Any ideas?

Perhaps also, a pointer to a comprehensive and correct document that details 
model formulae syntax if someone has one?

Thanks  Best Regards,
Steven



[[alternative HTML version deleted]]

__
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] nls: example code throws error

2013-04-26 Thread Gabor Grothendieck
On Thu, Apr 25, 2013 at 7:16 PM, Steven LeBlanc ores...@gmail.com wrote:
 Greets,

 I'm trying to learn to use nls and was running the example code for an 
 exponential model:

 x - -(1:100)/10
 y - 100 + 10 * exp(x / 2) + rnorm(x)/10
 nlmod - nls(y ~  Const + A * exp(B * x))
 Error in B * x : non-numeric argument to binary operator
 In addition: Warning message:
 In nls(y ~ Const + A * exp(B * x)) :
   No starting values specified for some parameters.
 Initializing ‘Const’ to '1.'.
 Consider specifying 'start' or using a selfStart model

 Presumably, the code should work if it is part of an example on the help 
 page. In perusing various help forums for similar problems, it also appears 
 that others believe this syntax should work in the model formula.

 Any ideas?


Try running in a clean session.  Having B - X in your workspace
would cause such an error.

--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
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] nls: example code throws error

2013-04-26 Thread Duncan Mackay

Hi

Try

x - -(1:100)/10
set.seed(1)
y - 100 + 10 * exp(x / 2) + rnorm(x)/10

short cut to starting values
lm(log(y) ~-log(x+10))
Call:
lm(formula = log(y) ~ -log(x + 10))

Coefficients:
(Intercept)
  4.624

nlmod - nls(y ~  A + B * exp(C * x), start=list(A=90, B=5,C=0.1))

Formula: y ~ A + B * exp(C * x)

Parameters:
Estimate Std. Error t value Pr(|t|)
A 100.009079   0.017797  5619.4   2e-16
B   9.93   0.042718   234.1   2e-16
C   0.499529   0.004495   111.1   2e-16

Residual standard error: 0.09073 on 97 degrees of freedom

Number of iterations to convergence: 5
Achieved convergence tolerance: 0.0002475

I will leave you to plot the results as a check

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

At 09:16 26/04/2013, you wrote:

Content-Type: text/plain
Content-Disposition: inline
Content-length: 899

Greets,

I'm trying to learn to use nls and was running the example code for 
an exponential model:


 x - -(1:100)/10
 y - 100 + 10 * exp(x / 2) + rnorm(x)/10
 nlmod - nls(y ~  Const + A * exp(B * x))
Error in B * x : non-numeric argument to binary operator
In addition: Warning message:
In nls(y ~ Const + A * exp(B * x)) :
  No starting values specified for some parameters.
Initializing 'Const' to '1.'.
Consider specifying 'start' or using a selfStart model

Presumably, the code should work if it is part of an example on the 
help page. In perusing various help forums for similar problems, it 
also appears that others believe this syntax should work in the model formula.


Any ideas?

Perhaps also, a pointer to a comprehensive and correct document that 
details model formulae syntax if someone has one?


Thanks  Best Regards,
Steven



[[alternative HTML version deleted]]


__
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.


Re: [R] nls: example code throws error

2013-04-26 Thread Keith Jewell

On 26/04/2013 00:16, Steven LeBlanc wrote:
 Greets,

 I'm trying to learn to use nls and was running the example code for 
an exponential model:


  snip

 Perhaps also, a pointer to a comprehensive and correct document that 
details model formulae syntax if someone has one?


 Thanks  Best Regards,
 Steven

Others have pointed out that the error is probably from an unclean 
environment.


For model formula syntax, see ?nls
Under Arguments formula, follow the link to ?formula

__
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] nls: example code throws error

2013-04-26 Thread Ben Bolker
Keith Jewell k.jewell at campden.co.uk writes:

 Others have pointed out that the error is probably from an unclean 
 environment.
 

  Completely OT, but an unclean environment sounds sort of scary to me.
Like it contains zombies or something.
I don't know a better, short way to express the idea though.

__
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] nls: example code throws error

2013-04-26 Thread Duncan Murdoch

On 13-04-26 10:14 AM, Ben Bolker wrote:

Keith Jewell k.jewell at campden.co.uk writes:


Others have pointed out that the error is probably from an unclean
environment.



   Completely OT, but an unclean environment sounds sort of scary to me.
Like it contains zombies or something.


Isn't that accurate?  Undead objects causing your code to be full of bugs?

Duncan Murdoch


I don't know a better, short way to express the idea though.

__
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.