A Fitting Problem

A problem from Stewart Calculus: Concepts and Contexts 2/e p. 38. It appears in Chapter 1.

Using mosaic

require(mosaic)
pop = fetchData("PREP-Stewart-World-Population.csv")
## Retrieving data from
## http://www.mosaic-web.org/go/datasets/PREP-Stewart-World-Population.csv
head(pop)
##   Year Population
## 1 1900       1650
## 2 1910       1750
## 3 1920       1860
## 4 1930       2070
## 5 1940       2300
## 6 1950       2560

What skills are needed to do this? Careful spelling, attention to punctuation, use of quotes, understanding the structure of a file name, understanding the syntax for use of R functions, understanding assignment.

plotPoints(Population ~ Year, data = pop)

plot of chunk world-pop-plot

What do you need to know to answer the questions posed earlier?

Some techniques:

Fit a quadratic

quadf = fitModel(Population ~ a * Year^2 + b * Year + c, data = pop)
quadf(1925)
## [1] 1878
quadfResids = with(pop, Population - quadf(Year))

Fit a cubic

You figure it out!

Fit a Spline

splinef = spliner(Population ~ Year, data = pop)
splinef(1925)
## [1] 1956
splinefResids = with(pop, Population - splinef(Year))

You can also try a monotonic spline. Use help(spliner) to find out how.

Fit an Exponential

This is hard, for reasons that relate to the data and numerics. Here, a guess is being made for a doubling time of 30 years.

expf = fitModel(Population ~ A + B * 2^((Year - 1900)/30), data = pop)

According to this model, what's the population in 1925?

QUESTIONS