Learn R Programming

tsforecast (version 1.3.0)

tslm: Generate Time Series Regression Model

Description

Fit Time Series Regression Models.

Usage

tslm(
  x,
  trend.order = 1,
  seasonal = FALSE,
  period = NA,
  type = c("additive", "multiplicative"),
  train.prop = 1
)

# S3 method for tslm print(x, digits = max(3L, getOption("digits") - 3L), ...)

# S3 method for tslm summary( object, anova = TRUE, digits = max(3L, getOption("digits") - 3L), se = TRUE, signif.stars = TRUE, ... )

Value

An object of class `tslm` is a list containing at least the following components:

coefficients

a named vector of coefficients

residuals

the residuals, that is response minus fitted values

rank

the numeric rank of the fitted linear model

fitted.values

the fitted mean values

df.residual

the residual degrees of freedom

call

the matched call

terms

the terms object used

xlevels

(only where relevant) a record of the levels of the factors used in fitting

offset

the offset used (missing if none were used)

model

if requested (the default), the model frame used

train.prop

proportion of training data.

x

data of the original series.

x.time

list of time in which the series values were observed.

x.timegap

time gap between the series and forecasted values.

x.name

name of the time series for which forecasts was requested.

x.time.used

list of time in which the series values were used for model fitting. It will be the same as x.time if train.prop = 1.

x.used

data of the original series which were used for model fitting. It will be the same as x if train.prop = 1.

series

series name x in match call.

error

a list of prediction error estimators, including $ME for mean error, $RMSE for root mean squared error, $MAE for mean absolute error, $MPE for mean percentage error, $MAPE for mean absolute percentage error, $MASE for mean absolute scaled error, $MASE.S for seasonal mean absolute scaled error, and $ACF1 for lag 1 autocorrelation.

model.test

a list of information regarding the prediction of the testing data including `x.test` (part of `x` used for testing), `fitted.test` (predicted values of the testing data), `residuals.test` (prediction error of the testing data), and `error.test` (prediction error measurements based on the testing data). Only available if train.prop is smaller than 1.

Arguments

x

a univariate time series or a `tslm` object.

trend.order

an integer specifying the polynomial order of the trend line estimation. If trend.order = 0, no trend component will be included in the model. Default is 1.

seasonal

logical. If TRUE, seasonal component will be included in the model. Default is FALSE.

period

a numerical value specifying the seasonal cycle length of the series. If omitted, frequency(x) will be used here. Only effective if seasonal = TRUE. Default is NA.

type

string characters specifying the series type. Available options are `additive` and `multiplicative`. If `type = multiplicative`, interaction terms between trend and seasonal components will be added to the model. Default is `additive`.

train.prop

a numerical value specifying the proportion of training data in the series. The value must be between 0 and 1. Default is 1.

digits

the number of significant digits to use when printing

...

other printing or summary parameters.

object

a tslm object for summary

anova

logical. If TRUE, an anova table with significance tests for trend, seasonality and their interaction will be included in the summary.

se

logical. If TRUE, standard error will be included in displaying the result. Default is TRUE.

signif.stars

logical. If TRUE, `significance stars` are printed for each coefficient

Author

Ka Yui Karl Wu

References

Hyndman, R. J., Athanasopoulos, G. (2021). Forecasting: Principles and practice (3rd ed.). OTexts.
https://otexts.com/fpp3/

Examples

Run this code
tslm(airport$Travellers, trend.order = 2, 
     seasonal = TRUE, type = "multiplicative")

Run the code above in your browser using DataLab