Skip to contents

Fit PAR models using least squares. The model may contain intercepts and linear trends, seasonal or non-seasonal.

Usage

pclsdf(x, d, lags = integer(0), sintercept = TRUE, sslope = FALSE,
       intercept = FALSE, slope = FALSE, xreg, contrasts = NULL,
       seasonof1st = NULL, coefonly = FALSE)

Arguments

x

time series, a numeric vector.

d

period, an integer.

lags

an integer vector, typically 1:p, where p is the order of the autoregression. The same lags are used for all seasons.

sintercept

if TRUE include seasonal intercepts.

sslope

if TRUE include seasonal linear trend.

intercept

if TRUE include non-seasonal intercept.

slope

if TRUE include non-seasonal linear trend.

xreg

additional regressors, not used currently.

contrasts

contrasts to use for the seasons factor variable.

seasonof1st

season of the first observation in the time series, see Details.

coefonly

if TRUE, return only the parameters of the fitted model, otherwise include also the object returned by lm.

Details

This function fits PAR models by the method of least squares. Seasonal intercepts are included by default. Non-seasonal intercepts are available, as well as seasonal and non-seasonal linear trend. Separate arguments are provided, so that any combination of seasonal and non-seasonal intercepts and slopes can be specified.

If coefonly is TRUE, pclsdf returns only the estimated parameters, otherwise it includes additional statistical information, see section Note for the current details.

Value

A list with the components listed below. Some components are present only if included in the model specification.

par

the PAR coefficients, a matrix with a row for each season.

sintercept

(if specified) seasonal intercepts, a numeric vector.

sigma2hat

innovation variances.

formula.char

the formula used in the call of lm, a character string.

fit

(if coefonly = FALSE) the fitted object obtained from lm.

Author

Georgi N. Boshnakov

Note

Currently, pclsdf prepares a model formula according to the specification and calls lm to do the fitting. Component "fit" in the result (available when coefonly = FALSE) contains the raw fitted object returned by lm. Statistical inference based on this object would, in general, not be justified for correlated data.

todo: currently some of the parameters are returned only via the fitted object from lm.

See also

Examples

## data(dataFranses1996)
cu <- pcts(dataFranses1996[ , "CanadaUnemployment"])
cu <- window(cu, start = availStart(cu), end = availEnd(cu))

pclsdf(cu, 4, 1:2, sintercept = TRUE)
#> $par
#>           [,1]       [,2]
#> [1,] 1.6727479 -0.6086116
#> [2,] 0.6076993  0.4000458
#> [3,] 1.6703750 -0.7011981
#> [4,] 1.1580936 -0.2012461
#> 
#> $sintercept
#>   Season1   Season2   Season3   Season4 
#> 103.87879 -27.91949  27.53365  47.18863 
#> 
#> $sigma2hat
#> [1] 1917.9150 3967.1090  899.7107 1314.2189
#> 
#> $formula.char
#> [1] "x ~ -1 + Season   + Lagged_1:Season + Lagged_2:Season"
#> 
#> $fit
#> 
#> Call:
#> lm(formula = fomodel, data = res, na.action = na.exclude)
#> 
#> Coefficients:
#>          Season1           Season2           Season3           Season4  
#>         103.8788          -27.9195           27.5336           47.1886  
#> Season1:Lagged_1  Season2:Lagged_1  Season3:Lagged_1  Season4:Lagged_1  
#>           1.6727            0.6077            1.6704            1.1581  
#> Season1:Lagged_2  Season2:Lagged_2  Season3:Lagged_2  Season4:Lagged_2  
#>          -0.6086            0.4000           -0.7012           -0.2012  
#> 
#> 

pclsdf(austres, 4, lags = 1:3)
#> $par
#>          [,1]        [,2]        [,3]
#> [1,] 1.528572 -0.26968659 -0.25942556
#> [2,] 1.335708  0.06294708 -0.39888301
#> [3,] 1.257598  0.34822562 -0.60613046
#> [4,] 1.650766 -0.63662585 -0.01077079
#> 
#> $sintercept
#>   Season1   Season2   Season3   Season4 
#>  11.08871  14.87099  18.57018 -32.42783 
#> 
#> $sigma2hat
#> [1]  36.39442 105.19204  33.77605  96.32893
#> 
#> $formula.char
#> [1] "x ~ -1 + Season   + Lagged_1:Season + Lagged_2:Season + Lagged_3:Season"
#> 
#> $fit
#> 
#> Call:
#> lm(formula = fomodel, data = res, na.action = na.exclude)
#> 
#> Coefficients:
#>          Season1           Season2           Season3           Season4  
#>         11.08871          14.87099          18.57018         -32.42783  
#> Season1:Lagged_1  Season2:Lagged_1  Season3:Lagged_1  Season4:Lagged_1  
#>          1.52857           1.33571           1.25760           1.65077  
#> Season1:Lagged_2  Season2:Lagged_2  Season3:Lagged_2  Season4:Lagged_2  
#>         -0.26969           0.06295           0.34823          -0.63663  
#> Season1:Lagged_3  Season2:Lagged_3  Season3:Lagged_3  Season4:Lagged_3  
#>         -0.25943          -0.39888          -0.60613          -0.01077  
#> 
#> 
pclsdf(austres, 4, lags = 1:3, sintercept = TRUE)
#> $par
#>          [,1]        [,2]        [,3]
#> [1,] 1.528572 -0.26968659 -0.25942556
#> [2,] 1.335708  0.06294708 -0.39888301
#> [3,] 1.257598  0.34822562 -0.60613046
#> [4,] 1.650766 -0.63662585 -0.01077079
#> 
#> $sintercept
#>   Season1   Season2   Season3   Season4 
#>  11.08871  14.87099  18.57018 -32.42783 
#> 
#> $sigma2hat
#> [1]  36.39442 105.19204  33.77605  96.32893
#> 
#> $formula.char
#> [1] "x ~ -1 + Season   + Lagged_1:Season + Lagged_2:Season + Lagged_3:Season"
#> 
#> $fit
#> 
#> Call:
#> lm(formula = fomodel, data = res, na.action = na.exclude)
#> 
#> Coefficients:
#>          Season1           Season2           Season3           Season4  
#>         11.08871          14.87099          18.57018         -32.42783  
#> Season1:Lagged_1  Season2:Lagged_1  Season3:Lagged_1  Season4:Lagged_1  
#>          1.52857           1.33571           1.25760           1.65077  
#> Season1:Lagged_2  Season2:Lagged_2  Season3:Lagged_2  Season4:Lagged_2  
#>         -0.26969           0.06295           0.34823          -0.63663  
#> Season1:Lagged_3  Season2:Lagged_3  Season3:Lagged_3  Season4:Lagged_3  
#>         -0.25943          -0.39888          -0.60613          -0.01077  
#> 
#> 
pclsdf(austres, 4, lags = 1:3, sintercept = TRUE, sslope = TRUE)
#> $par
#>          [,1]        [,2]       [,3]
#> [1,] 1.370470  0.05946978 -0.4607858
#> [2,] 1.282184  0.10653624 -0.4132554
#> [3,] 1.291900  0.31313365 -0.5901552
#> [4,] 1.859568 -1.01171474  0.1055395
#> 
#> $sintercept
#>   Season1   Season2   Season3   Season4 
#>  395.6552  327.4550 -176.4203  601.7557 
#> 
#> $sslope
#> Season1:TimeIndex Season2:TimeIndex Season3:TimeIndex Season4:TimeIndex 
#>         1.6136930         1.2845380        -0.8039129         2.6183438 
#> 
#> $sigma2hat
#> [1] 28.99261 98.63279 31.33658 71.72827
#> 
#> $formula.char
#> [1] "x ~ -1 + Season  + TimeIndex:Season + Lagged_1:Season + Lagged_2:Season + Lagged_3:Season"
#> 
#> $fit
#> 
#> Call:
#> lm(formula = fomodel, data = res, na.action = na.exclude)
#> 
#> Coefficients:
#>           Season1            Season2            Season3            Season4  
#>         395.65518          327.45502         -176.42026          601.75566  
#> Season1:TimeIndex  Season2:TimeIndex  Season3:TimeIndex  Season4:TimeIndex  
#>           1.61369            1.28454           -0.80391            2.61834  
#>  Season1:Lagged_1   Season2:Lagged_1   Season3:Lagged_1   Season4:Lagged_1  
#>           1.37047            1.28218            1.29190            1.85957  
#>  Season1:Lagged_2   Season2:Lagged_2   Season3:Lagged_2   Season4:Lagged_2  
#>           0.05947            0.10654            0.31313           -1.01171  
#>  Season1:Lagged_3   Season2:Lagged_3   Season3:Lagged_3   Season4:Lagged_3  
#>          -0.46079           -0.41326           -0.59016            0.10554  
#> 
#> 

x <- rep(1:4,10)
pclsdf(x, 4, lags = 1:3, sintercept = TRUE, sslope = TRUE)
#> $par
#>      [,1] [,2] [,3]
#> [1,]   NA   NA   NA
#> [2,]   NA   NA   NA
#> [3,]   NA   NA   NA
#> [4,]   NA   NA   NA
#> 
#> $sintercept
#> Season1 Season2 Season3 Season4 
#>       1       2       3       4 
#> 
#> $sslope
#> Season1:TimeIndex Season2:TimeIndex Season3:TimeIndex Season4:TimeIndex 
#>      8.816396e-18     -1.469171e-18      2.383641e-17      5.209739e-17 
#> 
#> $sigma2hat
#> [1] 1.934585e-32 5.372172e-34 1.414124e-31 9.553764e-31
#> 
#> $formula.char
#> [1] "x ~ -1 + Season  + TimeIndex:Season + Lagged_1:Season + Lagged_2:Season + Lagged_3:Season"
#> 
#> $fit
#> 
#> Call:
#> lm(formula = fomodel, data = res, na.action = na.exclude)
#> 
#> Coefficients:
#>           Season1            Season2            Season3            Season4  
#>         1.000e+00          2.000e+00          3.000e+00          4.000e+00  
#> Season1:TimeIndex  Season2:TimeIndex  Season3:TimeIndex  Season4:TimeIndex  
#>         8.816e-18         -1.469e-18          2.384e-17          5.210e-17  
#>  Season1:Lagged_1   Season2:Lagged_1   Season3:Lagged_1   Season4:Lagged_1  
#>                NA                 NA                 NA                 NA  
#>  Season1:Lagged_2   Season2:Lagged_2   Season3:Lagged_2   Season4:Lagged_2  
#>                NA                 NA                 NA                 NA  
#>  Season1:Lagged_3   Season2:Lagged_3   Season3:Lagged_3   Season4:Lagged_3  
#>                NA                 NA                 NA                 NA  
#> 
#> 

## this is for the version when contrasts arg. was passed on directly to lm.
## tmp1 <- pclsdf(austres, 4, lags = 1, sintercept = FALSE, sslope = TRUE,
##                contrasts = list(Season = "contr.sum" ))