if( !require('investr') ){ install.packages('investr', dependencies=TRUE, repos='http://cran.rstudio.com/') } library(investr) # has the function plotFit load(file='../../BookCode/nlrwr/data/L.minor.rda') # Plot the data to get an idea of what it looks like: # plot(L.minor$conc, L.minor$rate, xlab='conc', ylab='rate') grid() # Build a self-starter function for this model: # MMentenModel = function(predictor, K, Vm){ Vm * predictor / (K + predictor) } MMentenModelInit = function(mCall, LHS, data){ xy = sortedXyData(mCall[['predictor']], LHS, data) oneOverX = 1/xy[,'x'] oneOverY = 1/xy[,'y'] lmFit = lm(oneOverY ~ oneOverX) coefs = coef(lmFit) Vm = 1/coefs[1] K = coefs[2] * Vm value = c(K, Vm) names(value) = mCall[c('K','Vm')] value } MMentenModelSS = selfStart(MMentenModel, MMentenModelInit, c('K', 'Vm')) # Fit our model to the given data: # L.minor.m1 = nls(rate ~ MMentenModelSS(conc, K, Vm), data=L.minor, trace=FALSE) plotFit(L.minor.m1, main='L.minor data and fit') grid() print(summary(L.minor.m1))