Hg.conc<- c(2.5,22,60,90,105,144,178,210,233,256,300,400) Y.gammaGT<-c(13.57,15.33,16.92,16.08,17.14,18.85,18.63,19.30,25.77, 28.44,35.46,45.26) mercury.df<- data.frame(Hg.conc=Hg.conc,log.conc=log(Hg.conc),resp=Y.gammaGT) Hg.nls.fit<- nls(resp~g0+b1*(log.conc-tau)*(log.conc>tau), data=mercury.df, start=list(g0=18.63,b1=38.88,tau=5.1818), trace=T) summary(Hg.nls.fit) Formula: resp ~ g0 + b1 * (log.conc - tau) * (log.conc > tau) Formula: resp ~ g0 + b1 * (log.conc - tau) * (log.conc > tau) Parameters: Value Std. Error t value g0 16.64570 0.6254910 26.6122 b1 39.26700 3.2909700 11.9318 tau 5.24608 0.0390842 134.2250 Residual standard error: 1.65489 on 9 degrees of freedom Correlation of Parameter Estimates: g0 b1 b1 8.98e-09 tau 4.08e-01 7.75e-01 # - now refit with the gradient provided I hockey<- function(g0,b1,tau,x) { indicate.gt.tau <- as.numeric(log.conc>tau) model.func<- g0 + b1*(x-tau)*indicate.gt.tau Temp<- cbind(1,(x-tau)*indicate.gt.tau,-b1*indicate.gt.tau) dimnames(Temp) <- list(NULL, c("g0","b1","tau")) attr(model.func,"gradient")<-Temp model.func } Hg.nls.fit.g<- nls(resp~hockey(g0,b1,tau,log.conc), data=mercury.df, start=list(g0=18.63,b1=38.88,tau=5.1818), trace=T) summary(Hg.nls.fit.g) Formula: resp ~ hockey(g0, b1, tau, log.conc) Formula: resp ~ hockey(g0, b1, tau, log.conc) Parameters: Value Std. Error t value g0 16.64570 0.6254910 26.6122 b1 39.26700 3.2909700 11.9318 tau 5.24608 0.0390842 134.2250 Residual standard error: 1.65489 on 9 degrees of freedom Correlation of Parameter Estimates: g0 b1 b1 5.55e-17 tau 4.08e-01 7.75e-01