# Higham (2002), p. 334
(mat <- matrix(c(1, 1, 0, 1, 1, 1, 0, 1, 1), byrow = TRUE, ncol = 3))
matProj <- matrix(c(1, 0.7607, 0.1573, 0.7607, 1, 0.7607, 0.1573, 0.7607, 1),
byrow = TRUE, ncol = 3)
nrPDT.mat <- nearPDToeplitz(mat, type = "correlation")
stopifnot( identical(unname(matProj), unname(round(as.matrix(nrPDT.mat$projection),
digits=4) ) ))
eigen(nrPDT.mat$projection)$values
# Toeplitz banded matrix near to the covariance matrix of 100 realizations
# of an MA(5) with following parameters:
n <- 1e2
alphas <- c(-2, 0.5, -4, 0, 0.75)
(true.acf <- ARMAacf(ma = alphas))
alphasMat <- symBandedToeplitz(true.acf, n = n)
stopifnot( min(eigen(alphasMat)$values) > 0 ) # alphasMat is a positive definite matrix
(l <- length(true.acf))
(acf.modified <- c(true.acf[-c(l - 1, l)], 0.25)) # modifying original acf
x <- acf.modified
acfMat <- symBandedToeplitz(x, n = n)
# no. of non positive eigenvalues of acfMat (6)
length( eigen(acfMat)$values[eigen(acfMat)$values < 0 ] )
# acfMat is a 100 x 100 symmetric banded Toeplitz matrix
acfMat[1:15, 1:30]
system.time(nrPDT.acfMat <- nearPDToeplitz(acfMat, type = "correlation"))
y <- eigen(nrPDT.acfMat$projection)$values
# no. of non positive eigenvalues of nrPDT.acfMat
length( y[ y < 0 ] ) # none!
Run the code above in your browser using DataLab