Liaw, Andy
2006-Apr-20 16:53 UTC
[R] Bootstrap error message: Error in statistic(data, origina l, ...) : unused argument(s) ( ...) [Broadcast]
I quoted the relevant part of the documentation for you. Have you actually try to read what it says? Sure, you don't get any error, but have you checked whether any bootstrapping was actually done? Most of those functions are generics, thus having the "..." argument that can take anything. Doesn't mean they will be used. See if the following helps:> x <- 1:10 > myMean <- function(x, idx) mean(x[idx]) > library(boot) > x.boot <- boot(x, mean, R=10) > str(x.boot)List of 11 $ t0 : num 5.5 $ t : num [1:10, 1] 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 $ R : num 10 $ data : int [1:10] 1 2 3 4 5 6 7 8 9 10 $ seed : int [1:626] 403 101 106329237 1120199471 -647917002 -657447328 355480739 291889089 -398656592 -2023350578 ... $ statistic:function (x, ...) $ sim : chr "ordinary" $ call : language boot(data = x, statistic = mean, R = 10) $ stype : chr "i" $ strata : num [1:10] 1 1 1 1 1 1 1 1 1 1 $ weights : num [1:10] 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 - attr(*, "class")= chr "boot"> x.boot2 <- boot(x, myMean, R=10) > str(x.boot2)List of 11 $ t0 : num 5.5 $ t : num [1:10, 1] 5.7 6.4 5.4 4.9 7.2 4.6 4.4 5.4 5.7 5.9 $ R : num 10 $ data : int [1:10] 1 2 3 4 5 6 7 8 9 10 $ seed : int [1:626] 403 201 106329237 1120199471 -647917002 -657447328 355480739 291889089 -398656592 -2023350578 ... $ statistic:function (x, idx) ..- attr(*, "source")= chr "function(x, idx) mean(x[idx])" $ sim : chr "ordinary" $ call : language boot(data = x, statistic = myMean, R = 10) $ stype : chr "i" $ strata : num [1:10] 1 1 1 1 1 1 1 1 1 1 $ weights : num [1:10] 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 - attr(*, "class")= chr "boot" Andy -----Original Message----- From: Michael [mailto:comtech.usa@gmail.com] Sent: Thursday, April 20, 2006 12:19 PM To: Liaw, Andy Cc: R-help@stat.math.ethz.ch Subject: Re: [R] Bootstrap error message: Error in statistic(data, origina l, ...) : unused argument(s) ( ...) [Broadcast] btw, if you change "myFun" to any R internal function, such as "cov", or "corr", it can run successfully... On 4/20/06, Michael <comtech.usa@gmail.com <mailto:comtech.usa@gmail.com> > wrote: Andy, I've noticed there should be a "weight" or "frequency" somewhere... but my function does not need it. I have tried to cheat it by declareing a weight, but not using it:> myFun=function(X, w)> { > return(mean(X[, 1])/var(X[, 2])); > } >> bootResults=boot(X, myFun, R=10000, stype='w');The result is zero: Bootstrap Statistics : original bias std. error t1* 2.305412 0 0 On 4/20/06, Liaw, Andy < andy_liaw@merck.com <mailto:andy_liaw@merck.com> > wrote:> -----Original Message----- > From: r-help-bounces@stat.math.ethz.ch<mailto:r-help-bounces@stat.math.ethz.ch>> [mailto: r-help-bounces@stat.math.ethz.ch<mailto:r-help-bounces@stat.math.ethz.ch> ] On Behalf Of Michael> Sent: Thursday, April 20, 2006 3:50 AM > To: R-help@stat.math.ethz.ch <mailto:R-help@stat.math.ethz.ch> > Subject: [R] Bootstrap error message: Error in > statistic(data, original, ...) : unused argument(s) ( ...) [Broadcast] > > > Dear colleagues, > > I've been swamped and fighting with error for a few hours but > still desperately having absolutely no clue:You really don't have to do that, but just RTFM instead. ?boot says: statistic A function which when applied to data returns a vector containing the statistic(s) of interest. [...] In all other cases statistic must take at least two arguments. The first argument passed will always be the original data. The second will be a vector of indices, frequencies or weights which define the bootstrap sample. [...] Your "myFun" clearly does not fit that description. boot() tried to call "myFun" with a second argument, but "myFun" doesn't know what to do with a second argument, and that's where you get the error. Andy> What's wrong with my bootstraping code? > > Thanks a lot! > > ------------------------ > Error Message: > > > bootResults=boot(X, myFun, R=10000); > Error in statistic(data, original, ...) : unused argument(s) ( ...) > > ------------------------ > My code is: > > X=cbind(column_vector_1, column_vector_2); > myFun=function(X) > { > return(mean(X[, 1])/var(X[, 2])); > } > > bootResults=boot(X, myFun, R=10000); > > --------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch <mailto:R-help@stat.math.ethz.ch> mailing list > https://stat.ethz.ch/mailman/listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>> PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html<http://www.R-project.org/posting-guide.html>> >---------------------------------------------------------------------------- -- Notice: This e-mail message, together with any attachments,...{{dropped}}
German
2010-Nov-15 23:13 UTC
[R] Bootstrap error message: Error in statistic(data, origina l, ...) : unused argument(s) ( ...) [Broadcast]
Hey everybody. I found the solution to the problem - at least for univariate statistics. In order to use the bootstrap method for an arbitrary statistic, the syntax for the function has to be in the form: Given a univariate formula with argument 'x': myfunction <- function(x,p){formula(x[p])} The idea of the boot() function seems to be to generate a randon vector of integers (representing the bootstrapped samples) and evaluate the data matrix at said vector, evaluate the function, store the bootstrapped statistic, and repeat. That's why it needs the second argument, and also why it gives the same value of t* when no such argument is present (i.e. "all values are equal to 21.10958105") Cheers! -- View this message in context: http://r.789695.n4.nabble.com/Re-Bootstrap-error-message-Error-in-statistic-data-origina-l-unused-argument-s-Broadcast-tp798359p3043991.html Sent from the R help mailing list archive at Nabble.com.
Maybe Matching Threads
- Bootstrap error message: Error in statistic(data, origina l, ...) : unused argument(s) ( ...)
- Bootstrap error message: Error in statistic(data, original, ...) : unused argument(s) ( ...)
- how to use apply with two variables
- Trouble combining plotmath, bquote, expressions
- R CMD INSTALL --build: Folders /inst and /etc not in zip-file and WindowsXP locks /library/[package]/etc/