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

From: sun71 sun <sun.sonny71_at_googlemail.com>
Date: Tue, 19 Feb 2008 15:22:20 +0100

Peter,

thank you - that was helpful!!!
I know, there is a more elegant way of doing it, but

N <- 200
dat <- as.data.frame(X2)
m <- tau - mean(dat)
tau_sim <- cbind(rep(m[1,],N), rep(m[2,],N), rep(m[3,],N), rep(m[4,], N)) mat <- X2+tau_sim
data <- as.data.frame(mat)
mean(data)

should give me the correct means...

(I got a rebounce notice on my original message and after I did not see it go through for a day, I decided to repost it. Did not mean to tear on peoples sleeves - my apologies!)

On 2/19/08, Peter Dalgaard <p.dalgaard_at_biostat.ku.dk> wrote:
> 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_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.
> >
>
>
> --
> 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 - 14:25:20 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 - 15: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