load(file='../../BookCode/nlrwr/data/M.merluccius.rda') # Plot the data to get an idea of what it looks like: # plot(num.fish ~ spawn.biomass, data=M.merluccius, xlab='spawn', ylab='number of fish') grid() c_start = 1/2 k_start = c_start * max(M.merluccius$spawn.biomass) + 1 fit = nls(num.fish ~ spawn.biomass * ( 1 - c*spawn.biomass/k )^(1/c), data=M.merluccius, algorithm='plinear', start=c(c=c_start, k=k_start)) print(summary(fit)) S_grid = with(M.merluccius, seq(min(spawn.biomass), max(spawn.biomass), length.out=100)) f_hat = predict(fit, newdata=data.frame(spawn.biomass=S_grid)) plot(num.fish ~ spawn.biomass, data=M.merluccius, pch=19, cex=1.5, xlab='spawn', ylab='number of fish') lines(S_grid, f_hat, type='l') grid()