[R] Create an AR(1) covariance matrix
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Fri May 11 16:55:09 CEST 2007
Dimitris Rizopoulos wrote:
> one option is the following:
>
> times <- 1:5
> rho <- 0.5
> sigma <- 2
> ###############
> H <- abs(outer(times, times, "-"))
> V <- sigma * rho^H
> p <- nrow(V)
> V[cbind(1:p, 1:p)] <- V[cbind(1:p, 1:p)] * sigma
> V
>
>
Hmm, I'd rather use
x <- diag(5)
x <- sigma * rho^abs(row(x)-col(x))
-p
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list