peter dalgaard
2015-Jan-31 08:19 UTC
[R] naming rows/columns in 'array of matrices' | solved
> On 30 Jan 2015, at 20:34 , Evan Cooch <evan.cooch at gmail.com> wrote: > > The (obvious, after the fact) solution at the bottom. D'oh... >[snip]> Forgot I was dealing with a multi-dimensional array, not a list. So, following works fine. I'm sure there are better approaches (where 'better' is either 'cooler', or 'more flexible'), but for the moment...) > > P <- array(0, c(2,2,2),dimnames=list(c("live","dead"),c("old","young"),NULL)) > > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T); > > print(P); >Just for completeness, this also works:> P <- array(0, c(2,2,2)) > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T);> dimnames(P)[[1]] <- c("live","dead") > dimnames(P)[[2]] <- c("live","dead")-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
I am trying to understand the Error function and its use in ANOVA. In particular I want to understand the difference between two models that differ only with respect to the Error statement: aovsubj<- aov(value~group+time+Error(subject),data=dataRMANOVA) and aovsubjgroup<-aov(value~group+time+Error(subject/group),data=dataRMANOVA) You will note that in my data I have two subject identifiers, subject and subject2. I am also trying to trying to understand how I should identify subjects, within group (i.e. intervention vs. control) or within time (0=baseline, 1=post)> dataRMANOVAvalue time group subject subject2 1 1.000000 0 int 1 1 2 2.000000 0 int 2 2 3 3.000000 0 int 3 3 4 4.000000 0 int 4 4 5 5.000000 0 int 5 5 6 6.000000 0 int 6 6 7 7.000000 0 int 7 7 8 8.000000 0 int 8 8 9 9.000000 0 int 9 9 10 10.000000 0 int 10 10 11 11.000000 0 int 11 11 12 12.000000 0 int 12 12 13 13.000000 0 int 13 13 14 14.000000 0 int 14 14 15 15.000000 0 int 15 15 16 16.000000 0 int 16 16 17 17.000000 0 int 17 17 18 18.000000 0 int 18 18 19 19.000000 0 int 19 19 20 20.000000 0 int 20 20 21 21.000000 0 cont 1 21 22 22.000000 0 cont 2 22 23 23.000000 0 cont 3 23 24 24.000000 0 cont 4 24 25 25.000000 0 cont 5 25 26 26.000000 0 cont 6 26 27 27.000000 0 cont 7 27 28 28.000000 0 cont 8 28 29 29.000000 0 cont 9 29 30 30.000000 0 cont 10 30 31 31.000000 0 cont 11 31 32 32.000000 0 cont 12 32 33 33.000000 0 cont 13 33 34 34.000000 0 cont 14 34 35 35.000000 0 cont 15 35 36 36.000000 0 cont 16 36 37 37.000000 0 cont 17 37 38 38.000000 0 cont 18 38 39 39.000000 0 cont 19 39 40 40.000000 0 cont 20 40 41 2.879131 1 int 1 1 42 1.533651 1 int 2 2 43 2.487756 1 int 3 3 44 3.446068 1 int 4 4 45 5.179854 1 int 5 5 46 5.775819 1 int 6 6 47 6.923979 1 int 7 7 48 8.163734 1 int 8 8 49 9.545974 1 int 9 9 50 8.792186 1 int 10 10 51 11.657503 1 int 11 11 52 12.681393 1 int 12 12 53 15.058688 1 int 13 13 54 13.757673 1 int 14 14 55 15.459029 1 int 15 15 56 15.535549 1 int 16 16 57 16.433237 1 int 17 17 58 17.247330 1 int 18 18 59 19.061927 1 int 19 19 60 21.165003 1 int 20 20 61 20.436705 1 cont 1 21 62 23.143230 1 cont 2 22 63 23.456946 1 cont 3 23 64 23.132284 1 cont 4 24 65 24.902017 1 cont 5 25 66 26.450399 1 cont 6 26 67 27.356943 1 cont 7 27 68 27.402023 1 cont 8 28 69 29.759883 1 cont 9 29 70 27.969628 1 cont 10 30 71 30.061475 1 cont 11 31 72 32.532427 1 cont 12 32 73 33.378877 1 cont 13 33 74 34.852244 1 cont 14 34 75 34.958594 1 cont 15 35 76 35.673225 1 cont 16 36 77 37.908208 1 cont 17 37 78 37.982471 1 cont 18 38 79 39.016917 1 cont 19 39 80 39.507583 1 cont 20 40 Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
David L Carlson
2015-Jan-31 20:11 UTC
[R] naming rows/columns in 'array of matrices' | solved
You can also add names to the dimensions:> dimnames(P)[[1]] <- c("live","dead") > dimnames(P)[[2]] <- c("old","young") > names(dimnames(P)) <- c("status", "age", NULL) > P, , 1 age status old young live 1 2 dead 3 4 , , 2 age status old young live 5 6 dead 7 8 David L. Carlson Department of Anthropology Texas A&M University -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of peter dalgaard Sent: Saturday, January 31, 2015 2:19 AM To: Evan Cooch Cc: r-help at r-project.org Subject: Re: [R] naming rows/columns in 'array of matrices' | solved> On 30 Jan 2015, at 20:34 , Evan Cooch <evan.cooch at gmail.com> wrote: > > The (obvious, after the fact) solution at the bottom. D'oh... >[snip]> Forgot I was dealing with a multi-dimensional array, not a list. So, following works fine. I'm sure there are better approaches (where 'better' is either 'cooler', or 'more flexible'), but for the moment...) > > P <- array(0, c(2,2,2),dimnames=list(c("live","dead"),c("old","young"),NULL)) > > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T); > > print(P); >Just for completeness, this also works:> P <- array(0, c(2,2,2)) > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T);> dimnames(P)[[1]] <- c("live","dead") > dimnames(P)[[2]] <- c("live","dead")-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
On 01/02/15 02:17, John Sorkin wrote:> I am trying to understand the Error function and its use in ANOVA. In > particular I want to understand the difference between two models > that differ only with respect to the Error statement: > > > aovsubj <- aov(value~group+time+Error(subject),data=dataRMANOVA) > and > aovsubjgroup <- aov(value~group+time+Error(subject/group),data=dataRMANOVA) > > You will note that in my data I have two subject identifiers, > subject and subject2. I am also trying to trying to understand how I > should identify subjects, within group (i.e. intervention vs. > control) or within time (0=baseline, 1=post)Since no-one else seems to have answered you let me point out that your first formulation treats subject 1 in the "int" group as being the same as subject 1 in the "cont" group, and similarly for subject 2 and so on. The second formulation (subject nested within group) treats subject 1 in the "int" group as being *different* from subject 1 in the "cont" group. If you were using subject2 instead of subject there would (I *think*) be no difference between the two formulations. HTH cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 Home phone: +64-9-480-4619