Re: [R] Why aov() with Error() gives three strata?
At any rate: Error(SUBJECT/IV) specifies two random effects: SUBJECT and SUBJECT:IV. This is most easily understood if you conceptually arrange your data in a SUBJECT x IV table: One effect is a set of random errors added to each row, the other is a set of effects added to each cell. If you have more than one observation within each cell, then you need a third set of errors to account for differences within cells and this is labeled "Within" variation. With one observation per cell, this stratum disappears (as far as I recall, haven't checked). Actually, this oversimplifies a little: What actually happens is that data gets split into 1: row means 2: differences between cells within rows 3: differences between observations within cells and if the stratum variances are decreasing, then this can be interpreted using random effects as above, with variances of each component proportional to the successive differences. (All assuming that you have a balanced data layout, otherwise aov() is just the wrong tool.) -pd > On 28 Dec 2017, at 19:36 , Jorge Fernando Saraiva de Menezes >wrote: > > Bert, thanks for the reply but I feel that my question is less about > statistics and more about R interface. Specifically, because the output of > R seems different than other programs (systat, for example, gives a between > and a within table instead of a three level one). > > I am familiar with the connection between mixed models and repeated > measures,and how mixed models are essentially replacing the aov models due > to their greater flexibility. But I feel that despite understanding a > little of the logic behind the mixed models that aov error terms seem > completely different to me than lmer randoms. > > I will post in those support lists you pass to me, if nothing comes from > here. However I had little luck in the stats exchange when I tried there. > > About a local expert, I am once more in a corner. there are many people in > my department who excel in statistics. But I none use R, drastically > reducing their ability to explain to me the output of aov. > > Em 28 de dez de 2017 20:04, "Bert Gunter" escreveu: > >> Jorge: >> >> FYI, *generally speaking,* queries that are mostly statistical in >> nature, such as yours, are off topic here -- this list is about R >> programming help, not statistical help. Having said that, you still >> may get a useful response here -- the r-help/statistics intersection >> *is* nonempty. However, if not, 2.5 suggestions: >> >> 1. Try posting to r-sig-mixed-models instead. Repeated measures are a >> type of mixed/multilevel model and you may receive some useful >> suggestions there, including alternative R approaches to fitting such >> model (e.g. using lme() or lmer() ). >> >> 2. Alternatively, try posting to a statistics site like >> stats.stackexchange.com. >> >> 2.5. Or, if you can, the best idea might be to sit down with a local >> statistics expert. >> >> Cheers, >> Bert >> >> >> >> Bert Gunter >> >> "The trouble with having an open mind is that people keep coming along >> and sticking things into it." >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >> >> >> On Thu, Dec 28, 2017 at 7:52 AM, Jorge Fernando Saraiva de Menezes >> wrote: >>> Dear list users, >>> >>> I am trying to learn Repeated measures ANOVA using the aov() interface, >> but >>> I'm struggling to understand its output. >>> >>> According to tutorials on the web, formula for a repeated measures design >>> is: >>> >>> aov(Y ~ IV+ Error(SUBJECT/IV) ) >>> >>> This formula does work but it returns three strata (Error:SUBJECT, Error: >>> SUBJECT:IV, Error: Within), when I would expect two strata (Within and >>> Between subjects). I've seems some tutorials show the exactly same >> setup, >>> but returning only the two first strata. >>> >>> Is it possible to have two or three strata depending on the data? >>> If there is always three strata, how this would fit the interpretation of >>> between vs within effects? >>> >>> Below a reproducible example that gives three strata: >>> >>> data(beavers) >>> data=data.frame(id = >>> rep(c("beaver1","beaver2"),c(nrow(beaver1),nrow(beaver2))), >> rbind(beaver1,beaver2)) >>> data$activ=factor(data$activ) >>> #balance dataset to have 6 samples for every combination of beaver and >>> activity. >>> balanced = split(data,interaction(data$id,data$activ)) >>> sizes = sapply(balanced,nrow) >>> selected = lapply(sizes,sample.int,6) >>> balanced = mapply(function(x,y) {x[y,]}, balanced,selected,SIMPLIFY=F) >>> balanced = do.call(rbind,balanced) >>> aov(temp~activ+Error(id/activ),data=balanced) >>> >>> Thanks, >>> Jorge >>> >>>[[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>
Re: [R] Help with script
Hello, Just use ?aggregate. Example <- read.table(text = " ID ABCDEFG a1 0001120 a2 0101221 a2 0112021 a3 0111111 ", header = TRUE) aggregate(. ~ ID, Example , sum) Happy holidays, Rui Barradas On 12/29/2017 12:03 AM, PABLO ORTIZ PINEDA wrote: Hello there. Happy new year for everyone! I need help with a table. This table contains 300 rows and 192 columns. Being the first column the ID of my samples that can have several observations. I need to generate e NEW table that contains a single ID with the sum of the observations by columns: For example: Example ID A B C D E F G 191 columns a1 0 0 0 1 1 2 0... a2 0 1 0 1 2 2 1... a2 0 1 1 2 0 2 1... a3 0 1 1 1 1 1 1 ...300rows In this case I want to make a new table in which there is only 1 ID and the values of each columns A...G are added. I n the example the new table would have only 3 IDs. a1, a2 and 3 and a2 has the values added by column: a2 0 2 1 3 2 4 2.. Thank you so much and have a wonderful year!. __ R-help@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.
Re: [R] Help with dates
Le 28/12/2017 à 18:13, Ramesh YAPALPARVI a écrit : Hi all, I’m struggling to get the dates in proper format. I have dates as factors and is in the form 02/27/34( 34 means 1934). If I use Try this x <- "02/27/34" x2 <- paste0(substr(x, 1, 6), "19", substr(x, 7, 8)) as.Date(x2, format="%m/%d/%Y") [1] "1934-02-27" or x2 <- gsub("(../../)(..)", "\\119\\2", x) Marc as.Date with format %d%m%y it gets converted to 2034-02-27. I tried changing the origin in the as.Date command but nothing worked. Any help is appreciated. Thanks, Ramesh __ R-help@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. -- __ Marc Girondot, Pr Laboratoire Ecologie, Systématique et Evolution Equipe de Conservation des Populations et des Communautés CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079 Bâtiment 362 91405 Orsay Cedex, France Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53 e-mail: marc.giron...@u-psud.fr Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html Skype: girondot __ R-help@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.
Re: [R] Help with script
Hi Pablo, There are probably many ways to do this in R. This suggestion uses dplyr. The solution is actually only one line (see the line starting with dat2). The first section simply creates the example data. library(dplyr) # 1. set up the example data m <- matrix( c(0,0,0,0,0,1,1,1,0,0,1,1,1,1,2,1,1,2,0,1,2,2,2,1,0,1,1,1), nrow=4) dat <- as.data.frame(m) dat$ID <- c("a1","a2","a2","a3") dat <- dat[,c(8,1:7)] colnames(dat) <- c("ID",LETTERS[1:7]) #2. group the data by ID, summing the columns in each group dat2 <- group_by(dat,ID) %>% summarise_all( sum ) #3. show the results dat2 # # A tibble: 3 x 8 # ID A B C D E F G # # 1a1 0 0 0 1 1 2 0 # 2a2 0 2 1 3 2 4 2 # 3a3 0 1 1 1 1 1 1 HTH, Eric On Fri, Dec 29, 2017 at 2:03 AM, PABLO ORTIZ PINEDAwrote: > Hello there. Happy new year for everyone! > > I need help with a table. This table contains 300 rows and 192 columns. > Being the first column the ID of my samples that can have several > observations. > > I need to generate e NEW table that contains a single ID with the sum of > the observations by columns: > For example: > > Example > ID ABCDEFG 191 columns > a1 0001120... > a2 0101221... > a2 0112021... > a3 0111111 > ...300rows > In this case I want to make a new table in which there is only 1 ID and > the values of each columns A...G are added. I > n the example the new table would have only 3 IDs. a1, a2 and 3 and a2 > has the values added by column: > a2 0 2 1 3 2 4 2.. > > Thank you so much and have a wonderful year!. > > -- > Pablo A. Ortiz-Pineda (Ph.D.) > Molecular Biology & Bioinformatics > Yale University. School of Medicine. > Pediatrics Department. > New Haven, CT 06510 > > > [[alternative HTML version deleted]] > > __ > R-help@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. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] RQuantLib
On Thu, Dec 28, 2017 at 6:02 PM, rsherry8wrote: > > I have recently installed R on my new computer. I also want to install the > package RQuantLib. So I run the following command and get the following > output: > >> install.packages("RQuantLib") > Installing package into ‘C:/Users/rsher/Documents/R/win-library/3.2’ > (as ‘lib’ is unspecified) > --- Please select a CRAN mirror for use in this session --- > Warning message: > package ‘RQuantLib’ is not available (for R version 3.2.4 Revised) > > The package did not install. Am I doing something wrong. Is the package > going to be updated for the latest version of R? > Windows binary packages are only built for the most current (major) version of R. You need to upgrade to at least R-3.4.0, or you will have to install RQuantLib (and therefore QuantLib itself) from source. > Thanks, > Bob > > __ > R-help@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. -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2018 | www.rinfinance.com __ R-help@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.
[R] Help with script
Hello there. Happy new year for everyone! I need help with a table. This table contains 300 rows and 192 columns. Being the first column the ID of my samples that can have several observations. I need to generate e NEW table that contains a single ID with the sum of the observations by columns: For example: Example ID A B C D E F G 191 columns a1 0 0 0 1 1 2 0... a2 0 1 0 1 2 2 1... a2 0 1 1 2 0 2 1... a3 0 1 1 1 1 1 1 ...300rows In this case I want to make a new table in which there is only 1 ID and the values of each columns A...G are added. I n the example the new table would have only 3 IDs. a1, a2 and 3 and a2 has the values added by column: a2 0 2 1 3 2 4 2.. Thank you so much and have a wonderful year!. -- Pablo A. Ortiz-Pineda (Ph.D.) Molecular Biology & Bioinformatics Yale University. School of Medicine. Pediatrics Department. New Haven, CT 06510 [[alternative HTML version deleted]] __ R-help@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.
[R] RQuantLib
I have recently installed R on my new computer. I also want to install the package RQuantLib. So I run the following command and get the following output: > install.packages("RQuantLib") Installing package into ‘C:/Users/rsher/Documents/R/win-library/3.2’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- Warning message: package ‘RQuantLib’ is not available (for R version 3.2.4 Revised) The package did not install. Am I doing something wrong. Is the package going to be updated for the latest version of R? Thanks, Bob __ R-help@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.
Re: [R] Help with dates
Your dates have an incomplete year information with 34. R assumes that 00-68 are 2000 to 2068 and 69 to 99 are 1969 to 1999. See ?strptime and the details for %y. You can either append “19” to the start of your year variable to make it completely express the year or check if the date is in the future (assuming all dates should be in the past) and subtract 100 years from the date. > On Dec 28, 2017, at 11:13 AM, Ramesh YAPALPARVI >wrote: > > Hi all, > > I’m struggling to get the dates in proper format. > I have dates as factors and is in the form 02/27/34( 34 means 1934). If I use > > as.Date with format %d%m%y it gets converted to 2034-02-27. I tried changing > the origin in the as.Date command but nothing worked. Any help is appreciated. > > Thanks, > Ramesh > __ > R-help@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. __ R-help@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.
Re: [R] Why aov() with Error() gives three strata?
Bert, thanks for the reply but I feel that my question is less about statistics and more about R interface. Specifically, because the output of R seems different than other programs (systat, for example, gives a between and a within table instead of a three level one). I am familiar with the connection between mixed models and repeated measures,and how mixed models are essentially replacing the aov models due to their greater flexibility. But I feel that despite understanding a little of the logic behind the mixed models that aov error terms seem completely different to me than lmer randoms. I will post in those support lists you pass to me, if nothing comes from here. However I had little luck in the stats exchange when I tried there. About a local expert, I am once more in a corner. there are many people in my department who excel in statistics. But I none use R, drastically reducing their ability to explain to me the output of aov. Em 28 de dez de 2017 20:04, "Bert Gunter"escreveu: > Jorge: > > FYI, *generally speaking,* queries that are mostly statistical in > nature, such as yours, are off topic here -- this list is about R > programming help, not statistical help. Having said that, you still > may get a useful response here -- the r-help/statistics intersection > *is* nonempty. However, if not, 2.5 suggestions: > > 1. Try posting to r-sig-mixed-models instead. Repeated measures are a > type of mixed/multilevel model and you may receive some useful > suggestions there, including alternative R approaches to fitting such > model (e.g. using lme() or lmer() ). > > 2. Alternatively, try posting to a statistics site like > stats.stackexchange.com. > > 2.5. Or, if you can, the best idea might be to sit down with a local > statistics expert. > > Cheers, > Bert > > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Thu, Dec 28, 2017 at 7:52 AM, Jorge Fernando Saraiva de Menezes > wrote: > > Dear list users, > > > > I am trying to learn Repeated measures ANOVA using the aov() interface, > but > > I'm struggling to understand its output. > > > > According to tutorials on the web, formula for a repeated measures design > > is: > > > > aov(Y ~ IV+ Error(SUBJECT/IV) ) > > > > This formula does work but it returns three strata (Error:SUBJECT, Error: > > SUBJECT:IV, Error: Within), when I would expect two strata (Within and > > Between subjects). I've seems some tutorials show the exactly same > setup, > > but returning only the two first strata. > > > > Is it possible to have two or three strata depending on the data? > > If there is always three strata, how this would fit the interpretation of > > between vs within effects? > > > > Below a reproducible example that gives three strata: > > > > data(beavers) > > data=data.frame(id = > > rep(c("beaver1","beaver2"),c(nrow(beaver1),nrow(beaver2))), > rbind(beaver1,beaver2)) > > data$activ=factor(data$activ) > > #balance dataset to have 6 samples for every combination of beaver and > > activity. > > balanced = split(data,interaction(data$id,data$activ)) > > sizes = sapply(balanced,nrow) > > selected = lapply(sizes,sample.int,6) > > balanced = mapply(function(x,y) {x[y,]}, balanced,selected,SIMPLIFY=F) > > balanced = do.call(rbind,balanced) > > aov(temp~activ+Error(id/activ),data=balanced) > > > > Thanks, > > Jorge > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
[R] Help with dates
Hi all, I’m struggling to get the dates in proper format. I have dates as factors and is in the form 02/27/34( 34 means 1934). If I use as.Date with format %d%m%y it gets converted to 2034-02-27. I tried changing the origin in the as.Date command but nothing worked. Any help is appreciated. Thanks, Ramesh __ R-help@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.
Re: [R] Why aov() with Error() gives three strata?
Jorge: FYI, *generally speaking,* queries that are mostly statistical in nature, such as yours, are off topic here -- this list is about R programming help, not statistical help. Having said that, you still may get a useful response here -- the r-help/statistics intersection *is* nonempty. However, if not, 2.5 suggestions: 1. Try posting to r-sig-mixed-models instead. Repeated measures are a type of mixed/multilevel model and you may receive some useful suggestions there, including alternative R approaches to fitting such model (e.g. using lme() or lmer() ). 2. Alternatively, try posting to a statistics site like stats.stackexchange.com. 2.5. Or, if you can, the best idea might be to sit down with a local statistics expert. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Dec 28, 2017 at 7:52 AM, Jorge Fernando Saraiva de Menezeswrote: > Dear list users, > > I am trying to learn Repeated measures ANOVA using the aov() interface, but > I'm struggling to understand its output. > > According to tutorials on the web, formula for a repeated measures design > is: > > aov(Y ~ IV+ Error(SUBJECT/IV) ) > > This formula does work but it returns three strata (Error:SUBJECT, Error: > SUBJECT:IV, Error: Within), when I would expect two strata (Within and > Between subjects). I've seems some tutorials show the exactly same setup, > but returning only the two first strata. > > Is it possible to have two or three strata depending on the data? > If there is always three strata, how this would fit the interpretation of > between vs within effects? > > Below a reproducible example that gives three strata: > > data(beavers) > data=data.frame(id = > rep(c("beaver1","beaver2"),c(nrow(beaver1),nrow(beaver2))),rbind(beaver1,beaver2)) > data$activ=factor(data$activ) > #balance dataset to have 6 samples for every combination of beaver and > activity. > balanced = split(data,interaction(data$id,data$activ)) > sizes = sapply(balanced,nrow) > selected = lapply(sizes,sample.int,6) > balanced = mapply(function(x,y) {x[y,]}, balanced,selected,SIMPLIFY=F) > balanced = do.call(rbind,balanced) > aov(temp~activ+Error(id/activ),data=balanced) > > Thanks, > Jorge > > [[alternative HTML version deleted]] > > __ > R-help@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. __ R-help@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.
[R] Why aov() with Error() gives three strata?
Dear list users, I am trying to learn Repeated measures ANOVA using the aov() interface, but I'm struggling to understand its output. According to tutorials on the web, formula for a repeated measures design is: aov(Y ~ IV+ Error(SUBJECT/IV) ) This formula does work but it returns three strata (Error:SUBJECT, Error: SUBJECT:IV, Error: Within), when I would expect two strata (Within and Between subjects). I've seems some tutorials show the exactly same setup, but returning only the two first strata. Is it possible to have two or three strata depending on the data? If there is always three strata, how this would fit the interpretation of between vs within effects? Below a reproducible example that gives three strata: data(beavers) data=data.frame(id = rep(c("beaver1","beaver2"),c(nrow(beaver1),nrow(beaver2))),rbind(beaver1,beaver2)) data$activ=factor(data$activ) #balance dataset to have 6 samples for every combination of beaver and activity. balanced = split(data,interaction(data$id,data$activ)) sizes = sapply(balanced,nrow) selected = lapply(sizes,sample.int,6) balanced = mapply(function(x,y) {x[y,]}, balanced,selected,SIMPLIFY=F) balanced = do.call(rbind,balanced) aov(temp~activ+Error(id/activ),data=balanced) Thanks, Jorge [[alternative HTML version deleted]] __ R-help@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.