Thomas Bock
2003-Oct-24 11:22 UTC
[R] first value from nlm (non-finite value supplied by nlm)
Dear expeRts, first of all I'd like to thank you for the quick help on my last which() problem. Here is another one I could not tackle: I have data on an absorption measurement which I want to fit with an voigt profile: fn.1 <- function(p){ for (i1 in ilong){ ff <- f[i1] ex[i1] <- exp(S*n*L*voigt(u,v,ff,p[1],p[2],p[3])[[1]]) } sum((t-ex)^2) } out <- nlm(fn.1, p = c(fo, GG, GL), hessian = TRUE, steptol = 1e-5, iterlim = 1000) foN <- out$estimate[1] GGN <- out$estimate[2] GLN <- out$estimate[3] This works fine but the my start value of S is to poor, so I like to fit S in a second run, with the initial values from the first run (two runs because I know that S as an parameter is an problem): fn.2 <- function(p){ for (i1 in ilong){ ex[i1] <- exp(p[1]*n*L*voigt(u,v,f[i1],p[2],p[3],GLN)[[1]]) } sum((t-ex)^2) } out <-nlm(fn.2, p = c(S,foN,GGN), hessian = TRUE, steptol = 1e-5, iterlim = 1000,print.level=2) SN <- out$estimate[1] The problem is now that the first value from nlm() is positive (1E-6 !?) and this leeds to an Inf: iteration = 0 Step: [1] 0 0 0 Parameter: [1] -3.800000e-19 2.196660e+03 5.211179e-03 Function Value [1] 0.5890603 Gradient: [1] Inf 11.23381 -23.61961 - Error in nlm(fn.2, p = c(S, foN, GGN), hessian = TRUE, steptol = 1e-5, : non-finite value supplied by nlm In addition: Warning message: NA/Inf replaced by maximum positive value The number of parameters plays no role; same behaviour with p = c(S,GGN) Can someone give a broad hint Thomas
Spencer Graves
2003-Oct-24 15:32 UTC
[R] first value from nlm (non-finite value supplied by nlm)
Have you tried fn.2(out$estimate), without the call to "nlm"? There may be a problem with the definition of "fn.2", but I don't have time to check that for you, other than to note the "t" is the matrix transpose function. In many but not all contexts, R is able to distinguish t as a function from t as a non-function. However, I consider that skating on thin ice. hope this helps. spencer graves Thomas Bock wrote:> Dear expeRts, > > first of all I'd like to thank you for the > quick help on my last which() problem. > > Here is another one I could not tackle: > I have data on an absorption measurement which I want to fit > with an voigt profile: > > fn.1 <- function(p){ > for (i1 in ilong){ > ff <- f[i1] > ex[i1] <- exp(S*n*L*voigt(u,v,ff,p[1],p[2],p[3])[[1]]) > } > sum((t-ex)^2) > } > out <- nlm(fn.1, p = c(fo, GG, GL), hessian = TRUE, steptol = 1e-5, > iterlim = 1000) > foN <- out$estimate[1] > GGN <- out$estimate[2] > GLN <- out$estimate[3] > > This works fine but the my start value of S is to poor, > so I like to fit S in a second run, with the initial values from the > first run > (two runs because I know that S as an parameter is an problem): > > fn.2 <- function(p){ > for (i1 in ilong){ > ex[i1] <- exp(p[1]*n*L*voigt(u,v,f[i1],p[2],p[3],GLN)[[1]]) > } > sum((t-ex)^2) > } > out <-nlm(fn.2, p = c(S,foN,GGN), hessian = TRUE, > steptol = 1e-5, iterlim = 1000,print.level=2) > SN <- out$estimate[1] > > The problem is now that the first value from nlm() is positive (1E-6 !?) > and this leeds to an Inf: > > iteration = 0 > Step: > [1] 0 0 0 > Parameter: > [1] -3.800000e-19 2.196660e+03 5.211179e-03 > Function Value > [1] 0.5890603 > Gradient: > [1] Inf 11.23381 -23.61961 - > > Error in nlm(fn.2, p = c(S, foN, GGN), hessian = TRUE, steptol = 1e-5, : > non-finite value supplied by nlm > In addition: Warning message: > NA/Inf replaced by maximum positive value > > The number of parameters plays no role; same behaviour with p = c(S,GGN) > > Can someone give a broad hint > Thomas > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Maybe Matching Threads
- nlm and optional arguments
- Sometimes having problems finding a minimum using optim(), optimize(), and nlm() (while searching for noncentral F parameters)
- Understanding nonlinear optimization and Rosenbrock's banana valley function?
- Viewing source code for .Internal functions
- Convergence code in nlm function