load(file='../../BookCode/nlrwr/data/RGRcurve.rda') # Plot the data to get an idea of what it looks like: # plot(RGRcurve$Day, RGRcurve$RGR, xlab='Day', ylab='RGR') grid() # Guess at some initial values: # y0 = min(RGRcurve$RGR) x = 4 # a point on the curve y = 0.5 b = x/log(y / y0) fit = nls(RGR ~ y0*exp(Day/b), data=RGRcurve, start=c(y0=y0, b=b), trace=TRUE) print(summary(fit)) # Plot the curve and the fit: # DayVals = with(RGRcurve, seq(min(Day), max(Day), length.out=100)) RGR_predicted = predict(fit, newdata=data.frame(Day=DayVals)) plot(RGRcurve$Day, RGRcurve$RGR, xlab='Day', ylab='RGR') lines(DayVals, RGR_predicted, col='blue') grid()