# The Additive Model for a Time Series # Example 1.1.1. (Unemployed1 Data). The monthly numbers of unemployed workers in the # building trade in Germany from July 1975 to September 1979. unemployed1 <- read.table("unemployed1.txt") unemployed1 colnames(unemployed1) <- c("month","t","unemplyd") unemployed1 plot(unemplyd~t,data=unemployed1,type="b") # The logistic function with different values of the parameters t <- seq(-10,10,length=100) flog <- function(t,b1,b2,b3) b3/(1+b2*exp(-t*b1)) plot(range(t),c(0,1),type="n",xlab="t",ylab="flog") lines(t,flog(t,0.5,0.1,1)) lines(t,flog(t,0.5,1,1),col="red") lines(t,flog(t,1,0.1,1),col="blue") lines(t,flog(t,1,1,1),col="green") # Example 1.1.2. (Population1 Data). The population sizes in millions # of the area of North-Rhine-Westphalia in 5 years steps from 1935 to 1980 population1 <- read.table("population1.txt") colnames(population1) <- c("year","t","pop") population1 plot(pop~t,data=population1) fit.pop1 <- nls(pop ~ b3/(1+b2*exp(-t*b1)),data = population1, start = list(b1=0.2,b2=1,b3=17)) fit.pop1 predict(fit.pop1) lines(predict(fit.pop1)~t,data=population1) # The Gompertz function with different values of the parameters t <- seq(0,4,length=100) fG <- function(t,b1,b2,b3)exp(b1+b2*b3^t) plot(range(t),c(1,8),type="n",xlab="t",ylab="fG") lines(t,fG(t,1,-1,0.05)) lines(t,fG(t,1,-1,0.5),col="red") lines(t,fG(t,1,1,0.05),col="blue") lines(t,fG(t,1,1,0.5),col="green") # Example 1.1.3. (Income Data). The (accumulated) annual average # increases of gross and net incomes in thousands DM (deutsche mark) # in Germany, starting in 1960. income <- read.table("income.txt") colnames(income) <- c("year","t","gross","net") income plot(net~t,data=income) fit.net <- lm(log(income$net[-1]) ~ log(income$t[-1])) summary(fit.net) coef(fit.net) b1 <- coef(fit.net)[2] b2 <- exp(coef(fit.net)[1]) b1 b2 y <- income$net[-1] y.hat <- b2*(income$t[-1])^b1 y y.hat y-y.hat 1-sum((y-y.hat)^2)/sum((y-mean(y))^2) predict(fit.pop1) lines(predict(fit.pop1)~t,data=population1)