Please excuse a question from somebody who is new to R. I'm using R version 0.90.1 (from an RPM package for redhat-linux) and am running into difficulties with code that looks like: nls(~ relative.error(..., x, y),data,start=list(...)) I've taken this code, which attempts to do a nonlinear curve-fit with weighted deviations, from section 10.3 of the book 'Statistical models in S' by Chambers and Hastings. Attached are 'test.ess' (my program file) and 'test.dat' (a data file). The files are very short (24 lines and 5 lines, respectively), and I'm hoping that somebody on this list would be willing to have a look and see why I get an error (as I've indicated in the first few comment-lines of the 'test.ess' file). Maybe my question is even more basic. Does R support library(nls) nls(~ ...) or only the library(nls) nls(y ~ ...) form? If only the latter, how may I specify weights for the data? I send thanks in advance for any help that folks can give me on this basic problem. Dan E. Kelley internet: mailto:Dan.Kelley at Dal.CA Oceanography Department phone: (902)494-1694 Dalhousie University fax: (902)494-2885 Halifax, NS, CANADA, B3H 4J1 http://www.phys.ocean.dal.ca/~kelley -------------- next part -------------- # Demonstrate problem using nls(), yielding the error: # # Error in relerr(A, B, x, y) : Object "A" not found # # # QUESTION: any advice as to how I can make this work? # # PS: For reference, I'm trying to copy what's in section 10.3 # of Chambers and Hastie's 'Statistical models in S', and my # platform is redhat-linux version 6.1, with R version 0.98.1-1. library(nls) mydata <- read.table("test.dat", header=TRUE, col.names=list("x","y")) attach(mydata) relerr <- function(A, B, z, observed) { pred <- A + B * x (pred - observed) / sqrt(observed) } nls.test <- nls(~ relerr(A, B, x, y), mydata, start = list(A = 9, B = 2)) summary(nls.test) -------------- next part -------------- x y 1 11 2 21 3 31 4 41