fitPM {pcts}R Documentation

Fit periodic time series models

Description

Generic function with methods for fitting periodic time series models.

Usage

fitPM( model, x, ...)

Arguments

x

the time series.

model

a periodic model, see Details.

...

further arguments to be passed on to individual methods.

Details

This is a generic function.

model provides the specification of the model. In particular, the class of model determines what model is fitted. Specific values of the parameters are generally ignored by non-iterative methods but some methods can handle more detailed specifications, see the individual methods.

Value

the fitted model, typically an object of class class(model)

Methods

signature(model = "ANY", x = "ANY")

This is the default method. It simply exits with an error message stating that fitPM does not have a method for the model specified by model.

signature(model = "numeric", x = "ANY")

Fits a PAR model to x. model should be a vector of non-negative integers giving the PAR order. The length of this vector is taken to be the number of seasons.

This is a convenience method. It constructs a PAR model and callls the method for model = "PeriodicArModel".

signature(model = "PeriodicArModel", x = "ANY")

Fits a PAR model.

signature(model = "mcSpec", x = "ANY")

Fits a periodic model according to the specification given by model.

Currently this method uses mC.ss to set up the optimisation environment and then calls one of the optimisation functions in that environment as specified by argument optim.method, see below.

Additional arguments may be specified to control the optimisation.

Argument init can be used to give initial values. It is passed on to mC.ss (and so has the format required by it).

optim.method is the name of an optimisation function in the environment returned by mC.ss. The default is optim.method = "minim", which is based on the standard R function optim. Alternatives are "minimBB" or "minimBBLU". All this needs to be documented but see mC.ss and xx.ss for details.

Further arguments are passed on to the optimisation method. A typical argument supported by most optimisation functions is control.

signature(model = "PiPeriodicArModel", x = "ANY")

Fits a periodically integrated PAR model using the parameters of model as initial values. Calls pclspiar to do the actual work.

signature(model = "SiPeriodicArModel", x = "ANY")

Fits a seasonally integrated PAR model.

signature(model = "PeriodicArModel", x = "PeriodicMTS")
signature(model = "PeriodicArModel", x = "PeriodicTS")

Author(s)

Georgi N. Boshnakov

References

(todo: to be completed properly later)

Hipel KW, McLeod AI (1994). Time series modelling of water resources and environmental systems, Developments in water science; 45. London; Amsterdam: Elsevier.

Boshnakov GN, Iqelan BM (2009). “Generation of time series models with given spectral properties.” J. Time Series Anal., 30(3), 349–368. ISSN 0143-9782, doi:10.1111/j.1467-9892.2009.00617.x.

Examples

## newm1 <- list(phi = matrix(1:12, nrow=4), p=rep(3,4), period=4, si2 = rep(1,4))
## new_pfm1 <- PeriodicFilterModel(newm1, intercept=0)

## generate some data;
set.seed(1234)
simts1 <- pcts(rnorm(1024), nseasons = 4)

fitPM(c(3,3,3,3), simts1)
fitPM(3, simts1)
## the fit on the underlying data is equivalent.
fitPM(c(3,3,3,3), as.numeric(simts1))

## equivalently, use a PAR(3,3,3,3) model for argument 'model'
## here the coefficients of pfm1 are ignored, since the estimation is linear.
pfm1 <- PeriodicArModel(matrix(1:12, nrow = 4), order = rep(3,4), sigma2 = 1)
pfm1
## these give same results as above
fitPM(pfm1, simts1)
fitPM(pfm1, as.numeric(simts1))

fitPM(c(1,1,1,1), simts1)
fitPM(c(3,2,2,1), simts1)
fitPM(c(3,2,2,2), simts1)

pdSafeParOrder(c(3,2,2,1))
pdSafeParOrder(rev(c(3,2,2,1)))

x <- arima.sim(list(ar = 0.9), n = 960)
pcx <- pcts(x, nseasons = 4)
mx <- matrix(x, nrow = 4)

##pc.acf(mx)
##pc.acf(mx, maxlag=10)
## TODO: avoid the warning when length ot the time series is not multiple
autocovariances(t(mx), maxlag = 6, nseasons = 4)
autocovariances(t(mx))

##It is an error to have more columns than rows.
## autocovariances(mx, maxlag = 6, nseasons = 4)
## autocovariances(mx)

num2pcpar(mx, c(1,1,1,1), period = 4)
num2pcpar(mx, c(3,3,3,3), period = 4)

sipfm1 <- new("SiPeriodicArModel", iorder = 1, siorder = 1, pcmodel = pfm1)
sipfm1
fitPM(sipfm1, mx)
pfm1


## experiments and testing
fit1    <- fitPM(c(3,3,3,3), simts1)
fit1_mf <- new("MultiFilter", coef = fit1@ar@coef)
vs      <- mcompanion::mf_VSform(fit1_mf, form = "I")
tmp <- mcompanion::VAR2pcfilter(vs$Phi[ , -4],
                                Phi0inv = vs$Phi0inv, D = fit1@sigma2, what = "")
names(tmp) #  "pcfilter" "var"      "Uform"   
tmp$var
zapsmall(tmp$pcfilter)
fit1@ar@coef
all.equal(tmp$pcfilter[ , 1:3], fit1@ar@coef, check.attributes = FALSE) # TRUE
tmp$Uform
fit1@sigma2

## both give the matrix Sigma for the "I" form
identical(
    vs$Phi0inv %*% diag(fit1@sigma2) %*% t(vs$Phi0inv)
    ,
    tmp$Uform$U0inv %*% diag(tmp$Uform$Sigma)  %*% t(tmp$Uform$U0inv)
) # TRUE

## no, this is a different matrix
var1_mat <- cbind(vs$Phi0, # identity matrix
                  - vs$Phi) # drop trailing zero columns?
var1_mat <- mcompanion::mCompanion(var1_mat)
var1_Sigma <- vs$Phi0inv %*% diag(fit1@sigma2) %*% t(vs$Phi0inv)
abs(eigen(diag(nrow(var1_mat)) - var1_mat)$values)

[Package pcts version 0.15.7 Index]