Page 172 - Data Science Algorithms in a Week
P. 172
Time Series Analysis
17.900000, 19.200000, 18.800000, 20.400000, 23.000000,
16.500000, 17.900000, 19.600000, 20.200000, 19.100000,
19.700000, 19.700000, 20.500000, 20.300000, 20.300000,
22.400000, 23.800000, 18.900000, 19.500000, 19.800000,
19.700000, 20.800000, 21.100000, 21.000000, 21.000000,
20.600000, 21.400000, 23.700000, 24.600000, 20.000000,
20.800000, 22.100000, 20.900000, 21.500000, 22.100000,
22.600000, 22.700000, 21.900000, 22.900000, 24.000000,
26.600000)
)
model = lm(sale ~ year, data = sales)
print(model)
Output:
$ Rscript sales_year.r
Call:
lm(formula = sale ~ year, data = sales)
Coefficients: (Intercept) year
-2557.778 1.279
Therefore, the equation of the trend line is:
sales = 1.279*year-2557.778
Visualization:
Now we add the trend line to the graph:
[ 160 ]