Introduction

The following procedure was done to find the population growth in the United States starting from the year 1979 and continuing onward until the year 1985. Year 1979 was set to equal to year 0 in order to prevent complications and errors. This will be done by first making a curve by plotting the corresponding values.

## Final R Programming Project

# Years from 1979-1985
year <- c(0,10,20,30,40,50,60) 
year
## [1]  0 10 20 30 40 50 60
# Population in Millions
pop <-  c( 3.929, 5.308, 7.240, 9.638, 12.866, 17.069, 23.192)      
pop
## [1]  3.929  5.308  7.240  9.638 12.866 17.069 23.192
# Plotting
plot(year, pop, xlab = "Years (1979-1985)", ylab = "Population (Millions) ", main="Population Growth in the U.S.")

Line of Best Fit

In order to illustrate the best line of fit on the curve, the following equation will be used.Also,before we can display the best line of fit, the non-linear least square regression tool would have to be used and therefore needs to be downloaded beforehand. Command “nls2”.

pop = pop(ini) * exp (k*year) Where pop is equal to the population each year in the United States. Pop(ini) is the initial population or starting population. Exp x (k x year) is the exponential growth function. K is the growth constant in this scenario. T is the time in years.

# Plotting
plot(year, pop, xlab = "Years (1979-1985)", ylab = "Population (Millions) ", main="Population Growth in the U.S.")

# Best Line of Fit
library(nls2)
## Loading required package: proto
fline <- nls2(pop ~ pop_ini * exp(k * year), 
              start = list(pop_ini = 3.929, k = 0.03))

summary(fline)
## 
## Formula: pop ~ pop_ini * exp(k * year)
## 
## Parameters:
##          Estimate Std. Error t value Pr(>|t|)    
## pop_ini 3.9744064  0.0407277   97.58 2.14e-09 ***
## k       0.0293421  0.0002023  145.02 2.96e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09817 on 5 degrees of freedom
## 
## Number of iterations to convergence: 3 
## Achieved convergence tolerance: 6.91e-08
lines(year, predict(fline), col="blue")

Conclusion

The initial value of the equation, pop = pop(ini) * exp (k*year), was provided to be 3.9744064 from R Script. The value we used for the initial population was 3.929. Furthermore, the K value that was estimated by the equation equals 0.0293421. We can believe that these results are accurate as the estimated initial values are in the same range. Also, the line of fit can be seen to be an almost perfect curve as proved by the 0.0293421 result. Overall, the error resulted in by the equation which is 0.0002023 is quite low and furthermore proves the accuracy of our results.