Hello, I am new to using R and I am having problems get boot() to work properly. Here is what I am trying to do: I have statistic called "cs". cs takes a data matrix (154 x 5) and calculates 12 different scores for me. cs outputs the data as a vector (12 x 1). cs doesn't really use weights, per se, however I have included this as one of the 2 arguments cs can take. I try performing a bootstrap by issuing: myout<-boot(data, cs,R=999) I have tried other versions where I specify stype="w", etc... The problem I get is that the dataset does not seem to be resampled. I end up with 999 replicates that have the exact same value of the output of cs. In the end I have something like Bootstrap Statistics : original bias std. error t1* 0.865122275 1.698641e-14 0 t2* -0.005248414 -9.627715e-17 0 t3* -0.052833740 -8.812395e-16 0 t4* 0.807040121 1.287859e-14 0 t5* 0.542082588 -9.103829e-15 0 t6* -0.018617838 -7.285839e-17 0 t7* 0.006409704 1.422473e-16 0 t8* 0.529874453 8.104628e-15 0 t9* 0.074804390 2.359224e-16 0 t10* -0.007153634 1.301043e-16 0 t11* -0.018241243 -2.359224e-16 0 t12* 0.049409513 -1.200429e-15 0 Clearly the bootstrap is not working. What am I doing wrong? Thanks, Ben ------------------------------- Benjamin Ridenhour School of Biological Sciences Washigton State University P.O. Box 644236 Pullman, WA 99164-4236 Phone (509)335-7218 -------------------------------- "Nothing in biology makes sense except in the light of evolution." -T. Dobzhansky [[alternative HTML version deleted]]
The first thing you are doing wrong is that you are not including a copy of cs for us to see ;). Based on what you have written, I speculate that cs does not use the index correctly. if so then a simple, although inefficient, workaround is to rewrite cs: cs <- function(dataframe, index) { dataframe <- dataframe[index,] ... } Good luck, Andrew On Tue, Jan 17, 2006 at 10:02:49PM -0800, Ben Ridenhour wrote:> Hello, > I am new to using R and I am having problems get boot() to work properly. Here is what I am trying to do: > > I have statistic called "cs". cs takes a data matrix (154 x 5) and calculates 12 different scores for me. cs outputs the data as a vector (12 x 1). cs doesn't really use weights, per se, however I have included this as one of the 2 arguments cs can take. > > I try performing a bootstrap by issuing: > myout<-boot(data, cs,R=999) > I have tried other versions where I specify stype="w", etc... > > The problem I get is that the dataset does not seem to be resampled. I end up with 999 replicates that have the exact same value of the output of cs. > > In the end I have something like > > Bootstrap Statistics : > original bias std. error > t1* 0.865122275 1.698641e-14 0 > t2* -0.005248414 -9.627715e-17 0 > t3* -0.052833740 -8.812395e-16 0 > t4* 0.807040121 1.287859e-14 0 > t5* 0.542082588 -9.103829e-15 0 > t6* -0.018617838 -7.285839e-17 0 > t7* 0.006409704 1.422473e-16 0 > t8* 0.529874453 8.104628e-15 0 > t9* 0.074804390 2.359224e-16 0 > t10* -0.007153634 1.301043e-16 0 > t11* -0.018241243 -2.359224e-16 0 > t12* 0.049409513 -1.200429e-15 0 > > Clearly the bootstrap is not working. What am I doing wrong? > > Thanks, > Ben > > > ------------------------------- > Benjamin Ridenhour > School of Biological Sciences > Washigton State University > P.O. Box 644236 > Pullman, WA 99164-4236 > Phone (509)335-7218 > -------------------------------- > "Nothing in biology makes sense except in the light of evolution." > -T. Dobzhansky > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 Email: a.robinson at ms.unimelb.edu.au http://www.ms.unimelb.edu.au
Hi, R users: I have a data.frame (not a matrix), I got a vector with the same length as the number of records (rows) of the data frame, and each element of that vector is the column number (in a specific range of columns) of the corresponding record that I must set to zero. How can I do this without a "for" loop? Thank you for your help. Kenneth
try: DF2 <- as.data.frame(matrix(vec, nr=nrow(DF),nc=ncol(DF))= matrix(1:ncol(DF),nr=nrow(DF),nc=ncol(DF),byrow=T)) DF3 <- data.frame(mapply(function(z,x,y) { x[y] <- 0 ; x }, names(DF), DF, DF2, SIMPLIFY=F)) but there must be an easier way... Kenneth Cabrera a ??crit :> Hi, R users: > > I have a data.frame (not a matrix), I got a vector with the same > length as the > number of records (rows) of the data frame, and each element of > that vector is the column number (in a specific range of columns) of > the corresponding > record that I must set to zero. > > How can I do this without a "for" loop? > > Thank you for your help. > > Kenneth > >------------------------------------------------------------------------ > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Hi eg. your data frame has 35 rows and 6 columns a<-sample(1:6, 35, replace=T) b<-1:35 vec<-rep(0,35*6) vec[a+6*(b-1)]<-1 This shall do the replacement your.d.f[matrix(vec,35,6, byrow=T)==1] <- 0 But I am not sure if it is quicker than a loop. HTH Petr On 18 Jan 2006 at 2:35, Kenneth Cabrera wrote: Date sent: Wed, 18 Jan 2006 02:35:35 -0500 From: Kenneth Cabrera <krcabrer at epm.net.co> To: r-help at stat.math.ethz.ch Subject: [R] Data frame index?> Hi, R users: > > I have a data.frame (not a matrix), I got a vector with the same > length as the number of records (rows) of the data frame, and each > element of that vector is the column number (in a specific range of > columns) of the corresponding record that I must set to zero. > > How can I do this without a "for" loop? > > Thank you for your help. > > Kenneth > >Petr Pikal petr.pikal at precheza.cz
you could try something like the following: dat <- data.frame(matrix(rnorm(200), 20, 10)) index <- sample(10, 20, TRUE) ############### mat.ind <- matrix(FALSE, nrow(dat), length(dat)) mat.ind[cbind(seq(along = index), index)] <- TRUE dat[mat.ind] <- 0 index dat I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Kenneth Cabrera" <krcabrer at epm.net.co> To: <r-help at stat.math.ethz.ch> Sent: Wednesday, January 18, 2006 8:35 AM Subject: [R] Data frame index?> Hi, R users: > > I have a data.frame (not a matrix), I got a vector with the same > length > as the > number of records (rows) of the data frame, and each element of > that vector is the column number (in a specific range of columns) of > the > corresponding > record that I must set to zero. > > How can I do this without a "for" loop? > > Thank you for your help. > > Kenneth > >--------------------------------------------------------------------------------> ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlDisclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Reasonably Related Threads
- Help - lm, glm, aov results inconsistent with other stati stical package
- Help - lm, glm, aov results inconsistent with other statistical package
- Confident interval for nls predictions
- Modifying glm.fit() / execution path
- Mixed GLM methodology and execution question