[R] function in nls argument

From: Fernando Moyano <nanomoyano_at_yahoo.com>
Date: Wed, 07 May 2008 08:40:36 -0700 (PDT)

Greetings R users, maybe there is someone who can help me with this problem:

I define a function "optim.fun" and want as output the sum of squared errors between predicted and measured values, as follows:

optim.fun <- function (ST04, SM08b, ch2no, a, b, d, E)

        predR <-

abserr <- abs(ch2no-predR) qnum <- quantile(abserr, probs=0.95, na.rm=T) is.na(abserr) <- (abserr > qnum) errsq <- sum(abserr^2, na.rm=T) errsq }

Then I want to optimize parameters a,b,d and E as to minimize the function output with the following:

optim.model<-nls(nulldat ~ optim.fun(ST04, SM08b, ch2no, a, b, d, E), data=tower,
start=list(a=-0.003,b=0.13,d=0.50, E=400), na.action = na.exclude )

were nulldat=0
At this point I get the following error message:

Error in qr.default(.swts * attr(rhs, "gradient")) :   NA/NaN/Inf in foreign function call (arg 1) Warning messages:
1: In if (na.rm) x <- x[!is.na(x)] else if
(any(is.na(x))) stop("missing values and NaN's not
allowed if 'na.rm' is FALSE") ... :
  the condition has length > 1 and only the first element will be used
(this warning is repeated 12 times)

Question: what does the error mean? What am I doing wrong?
Thanks a bunch.
Jen, Germany
Max Planck for Biogeochemistry

[[elided Yahoo spam]]

R-help_at_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. Received on Wed 07 May 2008 - 16:41:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 07 May 2008 - 22:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive