if( !require('drc') ){ install.packages('drc', dependencies=TRUE, repos='http://cran.rstudio.com/') } library(drc) # get the dataset G.aparine if( !require('nlme') ){ install.packages('nlme', dependencies=TRUE, repos='http://cran.rstudio.com/') } library(nlme) source('../Chapter5/SSlogLogistic.R') # Avoid log(0) when dose=0: # mask = G.aparine$dose == 0 G.aparine$dose[mask] = G.aparine$dose[mask] + 1.e-3 # Fit a model to all the data: # G.aparine.m0 = nls(drymatter ~ SSlogLogistic(dose, b, c, d, e), data=G.aparine) print(summary(G.aparine.m0)) # Fit each model separately: # G.aparine.m1 = nlsList(drymatter ~ SSlogLogistic(dose, b, c, d, e) | treatment, data=G.aparine) print(summary(G.aparine.m1)) nd = data.frame(dose=500, treatment=1) print(sprintf('(dose= %.2f; treatment= %d): prediction(group independent)= %f', nd$dose, nd$treatment, predict(G.aparine.m0, newdata=nd))) print(sprintf('(dose= %.2f; treatment= %d): prediction(group dependent)= %f', nd$dose, nd$treatment, predict(G.aparine.m1, newdata=nd))) nd = data.frame(dose=500, treatment=2) print(sprintf('(dose= %.2f; treatment= %d): prediction(group independent)= %f', nd$dose, nd$treatment, predict(G.aparine.m0, newdata=nd))) print(sprintf('(dose= %.2f; treatment= %d): prediction(group dependent)= %f', nd$dose, nd$treatment, predict(G.aparine.m1, newdata=nd)))