library(MASS) #data(wtloss) attach(wtloss) # Plot the data to get an idea of what it looks like: # plot(Days, Weight, xlab='Days', ylab='Weight') grid() # Guess at the paramters: # n = dim(wtloss)[1] beta1 = Weight[1] - Weight[n] target = mean(c(Weight[1], Weight[n]) ) target_indx = which.min(abs(Weight - target)) beta2 = Days[target_indx] beta3 = Weight[n] fit = nls(Weight ~ beta1 * 2^(-Days/beta2) + beta3, data=wtloss, start=c(beta1=beta1, beta2=beta2, beta3=beta3), trace=TRUE) print(summary(fit)) if( !require('investr') ){ install.packages('investr', dependencies=TRUE, repos='http://cran.rstudio.com/') } library(investr) plotFit(fit) grid()