# Michaelis-Menten example mm=read.csv('http://rls.sites.oasis.unc.edu/faculty/rs/source/Data/mmex.csv',header=T) # crude method based on 1/y v. 1/x regression lmod=lm(1/mm$y~I(1/mm$x)) theta1=1/lmod$coef[1] theta2=lmod$coef[2]/lmod$coef[1] # use as starting values for nls routine nreg=nls(y~th1*x/(th2+x),start=list(th1=as.numeric(theta1),th2=as.numeric(theta2)),mm) # plot the results both ways par(mfrow=c(1,2)) plot(mm$x,mm$y,xlab='x',ylab='y') lines(mm$x,theta1*mm$x/(theta2+mm$x)) lines(mm$x,summary(nreg)$coef[1,1]*mm$x/(summary(nreg)$coef[2,1]+mm$x),lty=2) plot(1/mm$x,1/mm$y,xlab='1/x',ylab='1/y') lines(1/mm$x,lmod$coef[1]+lmod$coef[2]/mm$x) lines(1/mm$x,1/summary(nreg)$coef[1,1]+(summary(nreg)$coef[2,1]/summary(nreg)$coef[1,1])*(1/mm$x),lty=2) # Running example p. 378 MM=matrix(scan('http://rls.sites.oasis.unc.edu/faculty/rs/source/Data/mmile1.txt'),ncol=2,byrow=T) # for women's data use WM=matrix(scan('http://rls.sites.oasis.unc.edu/faculty/rs/source/Data/wmile1.txt'),ncol=2,byrow=T) yr=MM[,1] time=MM[,2] th3=0.01 lm1=lm(time~I(exp(-th3*(yr-1955)))) #nreg=nls(time~th1+th2*exp(-th3*(yr-1955)),start=c(th1=130.9,th2=108.77,th3=0.01) nreg=nls(time~th1+th2*exp(-th3*(yr-1955)),start=list(th1=lm1$coef[1],th2=lm1$coef[2],th3=0.01))