Dear all, I have a (probably very basic) question. I am imputing data with the mice package, using 10 chains. I can then write out the 10 final values of the chains simply by name1 <- complete(imp, 1) : : name10 <- complete(imp,10) Not a big deal, I just wanted to do that in a little loop as follows: for (i in 1:10){ set[i] <- complete(imp,i)} Yet that doesn't work, I also tried other things like: for (i in 1:10){ set[[i]] <- complete(imp,i)} Again, no success. It only saves a couple of lines of code, but there must be an easy solution, right? Thanks, Florian -- View this message in context: http://r.789695.n4.nabble.com/Loop-tp4409865p4409865.html Sent from the R help mailing list archive at Nabble.com.
-- Helios de Rosario Mart?nez Researcher>>> El d?a 22/02/2012 a las 11:32, Florian Weiler <fweiler08 at jhubc.it>escribi?:> Dear all, > > I have a (probably very basic) question. I am imputing data with themice> package, using 10 chains. I can then write out the 10 final values ofthe> chains simply by > > name1 <- complete(imp, 1) > : > : > name10 <- complete(imp,10) > > Not a big deal, I just wanted to do that in a little loop asfollows:> > for (i in 1:10){ > set[i] <- complete(imp,i)} > > Yet that doesn't work, I also tried other things like: > for (i in 1:10){ > set[[i]] <- complete(imp,i)} > > Again, no success. It only saves a couple of lines of code, but theremust> be an easy solution, right? > Thanks, > FlorianHi Florian, Please give more context. There are various reasons why that could fail. Is your list "set" defined before starting to assign values? Try: set <- vector("list",10) before the loop. INSTITUTO DE BIOMEC?NICA DE VALENCIA Universidad Polit?cnica de Valencia ? Edificio 9C Camino de Vera s/n ? 46022 VALENCIA (ESPA?A) Tel. +34 96 387 91 60 ? Fax +34 96 387 91 69 www.ibv.org Antes de imprimir este e-mail piense bien si es necesario hacerlo. En cumplimiento de la Ley Org?nica 15/1999 reguladora de la Protecci?n de Datos de Car?cter Personal, le informamos de que el presente mensaje contiene informaci?n confidencial, siendo para uso exclusivo del destinatario arriba indicado. En caso de no ser usted el destinatario del mismo le informamos que su recepci?n no le autoriza a su divulgaci?n o reproducci?n por cualquier medio, debiendo destruirlo de inmediato, rog?ndole lo notifique al remitente.
Thanks for the answer, and sorry if I was not clear. So I run the data imputation using mice with 10 chains and then I get a mids-object. From that object I can then extract 10 data sets using the complete(imp, n) command (with n=c(1:10)). Now I can type this out 10 times: set1 <- complete(imp, 1) set2 <- complete(imp, 2) etc. Each of these set1 to set10 will be a data frame. That all is easy enough, but I would like to do this in a loop and create the same 10 data sets. If I use the command proposed by you, then the loop works but again the 10 data sets are stored in only one single object (a list) when I would like to create 10 separate data sets. Is that enough information? Thanks again, Florian -- View this message in context: http://r.789695.n4.nabble.com/Loop-tp4409865p4410333.html Sent from the R help mailing list archive at Nabble.com.
On 22-02-2012, at 14:40, Florian Weiler wrote:> Thanks for the answer, and sorry if I was not clear. > > So I run the data imputation using mice with 10 chains and then I get a > mids-object. From that object I can then extract 10 data sets using the > complete(imp, n) command (with n=c(1:10)). > > Now I can type this out 10 times: > set1 <- complete(imp, 1) > set2 <- complete(imp, 2) > etc. > > Each of these set1 to set10 will be a data frame. That all is easy enough, > but I would like to do this in a loop and create the same 10 data sets. > > If I use the command proposed by you, then the loop works but again the 10 > data sets are stored in only one single object (a list) when I would like to > create 10 separate data sets. > > Is that enough information?How about this for( k in 1:10 ) assign(paste("set",k,sep=""), complete(imp,k)) Berend Hasselman
Thanks a lot all of you! @ Berend, your code works fine, thanks. @ Milan, you have a point there, makes sense to create 1 instead of 10 objects! -- View this message in context: http://r.789695.n4.nabble.com/Loop-tp4409865p4410444.html Sent from the R help mailing list archive at Nabble.com.
Hi Florian, 'yet that doesn't work' is an improper question on this list, see the posting guide. Besides that, something like set<-vector(mode = "list", length = 10) for (i in 1:10){ set[[i]] <- complete(imp,i)} or saving some typing set<-lapply(1:10,function(i)complete(imp,i)) should work. cheers Am 22.02.2012 11:32, schrieb Florian Weiler:> Dear all, > > I have a (probably very basic) question. I am imputing data with the mice > package, using 10 chains. I can then write out the 10 final values of the > chains simply by > > name1 <- complete(imp, 1) > : > : > name10 <- complete(imp,10) > > Not a big deal, I just wanted to do that in a little loop as follows: > > for (i in 1:10){ > set[i] <- complete(imp,i)} > > Yet that doesn't work, I also tried other things like: > for (i in 1:10){ > set[[i]] <- complete(imp,i)} > > Again, no success. It only saves a couple of lines of code, but there must > be an easy solution, right? > Thanks, > Florian > > -- > View this message in context: http://r.789695.n4.nabble.com/Loop-tp4409865p4409865.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Pr?l?, Prof. Dr. Dr. Uwe Koch-Gromus
I've tried to create a loop for the following code but have failed miserably. This is what the code is: pnorm((Normal.Team.LnAveragePPPConceded.LnAveragePPPScores.HA.pred[1,1] -Normal.Team.LnAveragePPPConceded.LnAveragePPPScores.HA.pred[50,1])/ sqrt(prediction.SE[1]^2 + prediction.SE[50]^2)) I'd like a loop so that it is something like this: for (i in 1:50) { pnorm((Normal.Team.LnAveragePPPConceded.LnAveragePPPScores.HA.pred[i,1] -Normal.Team.LnAveragePPPConceded.LnAveragePPPScores.HA.pred[i+49,1])/ sqrt(prediction.SE[i]^2 + prediction.SE[i+49]^2)) } Many thanks -- View this message in context: http://r.789695.n4.nabble.com/Loop-tp4424128p4424128.html Sent from the R help mailing list archive at Nabble.com.