Hi Marco:
Here is a function that forms both symmetric and general Toeplitz
matrices:
toeplitz <- function (x, sym=T) {
if (!is.vector(x))
stop("x is not a vector")
n <- length(x)
if (!sym) {
if (!n%%2) stop("length of vector must be odd")
n2 <- (n+1)/2
A <- matrix(NA, n2, n2)
mat <- matrix(x[col(A) - row(A) + n2], n2, n2)
}
else {
A <- matrix(NA, n, n)
mat <- matrix(x[abs(col(A) - row(A)) + 1], n, n)
}
mat
}
Best,
Ravi.
----- Original Message -----
From: Marco Bianchi <M.Bianchi@nrcl.com>
Date: Tuesday, July 29, 2003 2:13 pm
Subject: [S] Toeplitz matrix
> Dear Splus users
>
> given a vector x = {x1, x2, ..., xp}, has anyone already worked
> out an Splus
> function producing the corresponding pxp Toeplitz matrix without
> looping?
> Many thanks
> Marco Bianchi
>
>
> -------------------------------------------------------------------
> -
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
|