# Adjust the file path! pop<-read.table("C:/Users/Helmut/Dropbox/population.tab") # A table with the world population from 1950-2005: pop x<-pop[[1]] x y<-pop[[2]] y plot(x,y,xlab="Year",ylab="World Population (in billions)") ylog<-log(y) plot(x,ylog) # Finding the least-squares fit: lsf<-lsfit(x,ylog) lsf ylfit<-lsf$coefficients[[1]]+x*lsf$coefficients[[2]] ylfit # The next two commands graphs the log-plot and its best linear fit plot(x,ylog) abline(lsf) # Now we will transform back to the original data: yfit<-exp(ylfit) yfit plot(x,y,xlab="Year",ylab="World Population (in billions)") lines(x,yfit) # Now we will extend into the future: xf<-c(x,2010,2015,2020,2025) xf yf<-c(y,NA,NA,NA,NA) yf ylfitf<-exp(lsf$coefficients[[1]]+xf*lsf$coefficients[[2]]) ylfitf plot(xf,yf,xlab="Year",ylab="World Population (in billions)",ylim=c(2,10)) lines(xf,ylfitf)