Page 168 - Data Science Algorithms in a Week
P. 168

Time Series Analysis


            Input:

            We store the data from the table above in the vectors year and profit in R script.
                # source_code/7/profit_year.r
                business_profits = data.frame(
                    year = c(2011,2012,2013,2014,2015,2016,2017),
                    profit = c(40,43,45,50,54,57,59)
                )
                model = lm(profit ~ year, data = business_profits)
                print(model)

            Output:

                $ Rscript profit_year.r
                Call:
                lm(formula = profit ~ year, data = business_profits)
                Coefficients:
                (Intercept)    year
                  -6711.571   3.357

            Visualization:





































                                                    [ 156 ]
   163   164   165   166   167   168   169   170   171   172   173