if( !require('nlme')){ install.packages('nlme', dependencies=TRUE, repos='http://cran.rstudio.com/') } library(nlme) source('../../BookCode/nlrwr/R/SSexp.R') 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() RGRcurve.m2 = gnls(RGR ~ SSexp(Day, a, b), data=RGRcurve, weights=varExp()) # change the assumed form for the variance print(summary(RGRcurve.m2)) # Plot the curve and the fit: # DayVals = with(RGRcurve, seq(min(Day), max(Day), length.out=100)) RGR_predicted = predict(RGRcurve.m2, newdata=data.frame(Day=DayVals)) plot(RGRcurve$Day, RGRcurve$RGR, xlab='Day', ylab='RGR') lines(DayVals, RGR_predicted, col='blue') grid()