Re: [R] repeated measures ANOVA using a cov matrix

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue, 19 Feb 2008 13:08:58 +0100

sun71 sun wrote:
> Dear all,
> how can I perform a repeated measures ANOVA using a covariance matrix as input?
> E.g., I have four repeated measures (N = 200) with mean vector tau (no
> BS factor):
>
> tau <- rbind(1.10, 2.51, 2.76, 3.52)
>
> and covariance matrix (sigma):
>
> sigma <- matrix(c(0.523, 0.268, 0.267, 0.211,
> 0.268, 0.444, 0.492, 0.571,
> 0.267, 0.492, 1.213, 1.112,
> 0.211, 0.571, 1.112, 1.811), nrow = 4, ncol
> = 4, byrow = TRUE)
>
> Thank you very much in advance!
>
>
(Please either include new information or wait a little longer for someone to react. Reposting after just over a day is a bit like pulling on peoples sleeves. And of course you always have the risk that nobody has anything to say.)

Your main problem is that few of the standard methods in R allow you to come in with pre-aggregated data. So either you have to do it yourself using matrix calculus - this is not massively hard if you know what you are doing - or you need to fake the raw data and take it from there.

The following generates X2 with variance exactly equal to sigma. I'm sure you can figure out how to get the means right as well.

X <- matrix(rnorm(4*200),200)
X2 <- X %*% solve(chol(var(X))) %*% chol(sigma)

 > var(X2)

      [,1] [,2] [,3] [,4]

[1,] 0.523 0.268 0.267 0.211
[2,] 0.268 0.444 0.492 0.571
[3,] 0.267 0.492 1.213 1.112
[4,] 0.211 0.571 1.112 1.811

(This must be doable with backsolve() too, but the proper incantation eludes me just now.)

> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
   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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 19 Feb 2008 - 12:13:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Feb 2008 - 14:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive