Re: [R] problem in fitting model in NLS function

2012-11-15 Thread U30A J C Nash

Bad scaling will waste a lot of everyone's time.

I put the data in a data frame mdat, then

library(nlmrt)
mdat<-read.csv("muzzamil.csv", header=T)
fmn <- nlxb(y~a * (x^b), data=mdat, start=c(a=1,b=1), trace=T)
fm <- nls(y~a * (x^b), data=mdat, start=c(a=1,b=1), trace=T)
fmn2 <- nlxb(y~a2 * ((x-1979)^b2), data=mdat, start=c(a2=1,b2=1), trace=T)
fm2 <- nls(y~a2 * ((x-1979)^b2), data=mdat, start=c(a2=1,b2=1), trace=T)

found a possible solution quickly with the last 2 forms. Without 
adjusting the x data, you get a very ill-conditioned problem.


JN



Message: 21
Date: Wed, 14 Nov 2012 03:04:56 -0800 (PST)
From: muzammil786 
To: r-help@r-project.org
Subject: Re: [R] problem in fitting model in NLS function
Message-ID: <1352891096449-4649473.p...@n4.nabble.com>
Content-Type: text/plain; charset=us-ascii

Dear David,

I am having a similar problem on this data (given below). I have tried
several starting values for a and b, but it is consistently giving me:

*fm <- nls(y~f(x,a,b), data.frame(x,y), start=c(a=1,b=1))
Error in numericDeriv(form[[3L]], names(ind), env) :
  Missing value or an infinity produced when evaluating the model*

The function f(x,a,b) is defined here:
*f <- function(x,a,b) {a * I(x^b)} *

The data is given here:

*  x   y
1  1980   1
2  1981   1
3  1982   1
4  1983   3
5  1984   3
6  1985   5
7  1986   8
8  1987   8
9  1988   9
10 1989  12
11 1990  15
12 1991  24
13 1992  33
14 1993  44
15 1994  62
16 1995  68
17 1996  81
18 1997  87
19 1998 102
20 1999 114
21 2000 123
22 2001 135
23 2002 144
24 2003 158
25 2004 172
26 2005 188
27 2006 197
28 2007 224
29 2008 234
30 2009 254
31 2010 278
32 2011 312
33 2012 317*

I shall be grateful if you could guide me what's wrong here.

Cheers.
Muzammil



--
View this message in context: 
http://r.789695.n4.nabble.com/problem-in-fitting-model-in-NLS-function-tp4345082p4649473.html
Sent from the R help mailing list archive at Nabble.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.


[R] vectorized uni-root?

2012-11-10 Thread U30A J C Nash

The package rootoned on http://r-forge.r-project.org/R/?group_id=395
has an all-R version of zeroin (the algorithm of uniroot). This should 
also be in Rmpfr by Martin M., as it was set up for that use. I suspect 
it can be vectorized fairly easily. However, it may be simpler to write, 
or else abstract from that code, a vectorized false position or secant 
code (same formula, FP must have end points with opposite sign function 
values, so is `safer'). This avoids the bisection step and simplifies 
things, but may be a bit less efficient sometimes.


JN



Date: Fri, 9 Nov 2012 14:58:55 +
From: Ravi Varadhan 
To: "'ivo.we...@gmail.com'" 
Cc: "r-help@r-project.org" 
Subject: Re: [R] vectorized uni-root?
Message-ID:
<2f9ea67ef9ae1c48a147cb41be2e15c32e8...@dom-eb-mail1.win.ad.jhu.edu>
Content-Type: text/plain

Hi Ivo,

The only problem is that uniroot() actually uses Brent's algorithm, and 
is based on the C code from netlib (there is also Fortran code available 
- zeroin.f).  Brent's algorithm is more sophisticated than a simple 
bisection approach that you have vectorized.  It combines bisection and 
secant methods along with some quadratic interpolation.  The idea behind 
this hybrid approach (which by the way is a fundamental theme in all of 
numerical analysis) is to get faster convergence while not sacrificing 
the global convergence of bisection.


So, the existing uniroot() will not be deprecated unless you can 
vectorize Brent's hybrid root-finding approach!


Best,
Ravi

__
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] Error message in nmkb()

2012-11-06 Thread U30A J C Nash
I would guess -- we don't have a reproducible code -- that you have an 
undefined function value. Since nmkb is entirely in R to my knowledge, 
you could simply take the source code and modify it to display the 
elements in the test that cause the trouble. Then load the source rather 
than using library(dfoptim).


Alternatively, add to your objective function some code to display the 
parameters before evaluation and the resulting value that is returned. 
Messy but pretty effective to reveal if and where the function is giving 
trouble.


JN


On 12-11-06 06:00 AM, r-help-requ...@r-project.org wrote:

Date: Mon, 5 Nov 2012 01:56:30 -0800 (PST)
From: MMar86
To:r-help@r-project.org
Subject: [R] Error message in nmkb()
Message-ID:<1352109390759-4648459.p...@n4.nabble.com>
Content-Type: text/plain; charset=UTF-8

Hallo together,
I am trying to use the nmkb() optimizer and I have problems using the
function, as it causes the following error message
Fehler (error)* in while (nf < maxfeval & restarts < restarts.max & dist >
ftol &  :
   Fehlender Wert (missing value)* , wo (where)* TRUE/FALSE n?tig ist (is
required)*
*translation

Do I need  to adjust the control ?
my.optpar3<-nmkb(par=par.start,fn=my.loglike.normal,lower=constLo,upper=999,
control=list(restarts.max=9))

If you need more info, please let me know.
I would appreciate some help, thank you very much.

Best,
Marcial


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