library(nls) time <- 0:20 year <- c(1790,1800,1810,1820,1830,1840,1850,1860,1870,1880,1890,1900,1910,1920,1930,1940,1950,1960,1970,1980,1990) population <- c(3.929,5.308,7.240,9.638,12.866,17.069,23.192,31.443,39.818,50.156,62.948,75.995,91.972,105.711,122.775,131.669,150.697,179.323,203.302,226.542,248.710) plot(year, population) pop.mod <- nls(population ~ beta1/(1 + exp(beta2 + beta3*time)), start=list(beta1 = 350, beta2 = 4.5, beta3 = -0.3),trace=T) summary(pop.mod) plot(year, population) lines(year, fitted.values(pop.mod), lwd=2) plot(year, residuals(pop.mod), type='b') abline(h=0, lty=2)