predict.ceplda: Classify Multivariate Time Series

Description Usage Arguments Details Value See Also Examples

Description

Classify time series. Run as part of cep.lda, and can be run seperatly after running cep.lda.

Usage

1
2
## S3 method for class 'ceplda'
predict(object, newdata, ...)

Arguments

object

Object of class "ceplda".

newdata

Data frame of cases to be classified. Data frame can be obtained by cep.get.

...

argument based from or to other methods.

Details

This function is a method for the generic function predict() for class "ceplda". It can be invoked by calling predict(x) for an object x of the appropriate class, or directly by calling predict.lda(x) regardless of the class of the object. Details usage of this function is similar to predict.lda(MASS).

Value

List with components

class

Classification result (a factor).

posterior

Posterior class probabilities.

x

Scores from test data.

See Also

cep.lda, predict.lda

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## See cep.lda for predicting new data simultaneously while fitting a model to training data.
## Below is predicting new data after fitting a model to the training data.  

## Simulate training data
nj = 50  #number of series in training data
N = 500  #length of time series
traindata1 <- r.cond.ar2(N=N,nj=nj,r.phi1=c(.01,.7),r.phi2=c(-.12,-.06),r.sig2=c(.3,3))
traindata2 <- r.cond.ar2(N=N,nj=nj,r.phi1=c(.5,1.2),r.phi2=c(-.36,-.25),r.sig2=c(.3,3))
traindata3 <- r.cond.ar2(N=N,nj=nj,r.phi1=c(.9,1.5),r.phi2=c(-.56,-.75),r.sig2=c(.3,3))
train <- cbind(traindata1$X,traindata2$X,traindata3$X)
y <- c(rep(1,nj),rep(2,nj),rep(3,nj))

## Fit the discriminant analysis
fit <- cep.lda(y,train)

## Simulate test data
testdata1 <- r.cond.ar2(N=N,nj=nj,r.phi1=c(.01,.7),r.phi2=c(-.12,-.06),r.sig2=c(.3,3))
testdata2 <- r.cond.ar2(N=N,nj=nj,r.phi1=c(.5,1.2),r.phi2=c(-.36,-.25),r.sig2=c(.3,3))
testdata3 <- r.cond.ar2(N=N,nj=nj,r.phi1=c(.9,1.5),r.phi2=c(-.56,-.75),r.sig2=c(.3,3))
test <- cbind(testdata1$X,testdata2$X,testdata3$X)
yTest <- c(rep(1,nj),rep(2,nj),rep(3,nj))


## Classifty new data
pre <- predict(fit,cep.get(yTest,test))
mean(pre$class == yTest)
table(yTest,pre$class)

CepLDA documentation built on May 1, 2019, 6:50 p.m.