Hi, I using the boot package 1.2-20 on R 2.0.1. My statistics function estimates 6 parameters. In a small percentage of resampled data sets my statistics function doesn't produce an estimate for one parameter and the boot function stops with an error. I can write an ifelse(exists('parameter.estimate'), parameter.estimate, NA) statement within the statistic function to substitute an NA for the missing estimate value. However, the boot.ci function to generate CIs from the boot object won't accept NAs. My problem is writing code to impute a numeric value for the missing estimate. ifelse won't generate a numeric value if the test is mode logical. Any suggestions? Nathan Nathan Leon Pace, MD, MStat Work:n.l.pace at utah.edu Department of Anesthesiology Home:nlpaces at comcast.net University of Utah Work:801.581.6393 Salt Lake City, Utah Home:801.467.2925 Fax:801.581.4367 Cell:801.558.3987
On Sat, 4 Dec 2004 18:37:43 -0700, "Nathan Leon Pace, MD, MStat" <n.l.pace at utah.edu> wrote:>Hi, > >I using the boot package 1.2-20 on R 2.0.1. > >My statistics function estimates 6 parameters. > >In a small percentage of resampled data sets my statistics function >doesn't produce an estimate for one parameter and the boot function >stops with an error. > >I can write an ifelse(exists('parameter.estimate'), parameter.estimate, >NA) statement within the statistic function to substitute an NA for the >missing estimate value. > >However, the boot.ci function to generate CIs from the boot object >won't accept NAs. > >My problem is writing code to impute a numeric value for the missing >estimate. ifelse won't generate a numeric value if the test is mode >logical.The test in ifelse is always logical or is coerced to be logical, so this isn't right. For example, x <- c(1,2,NA) ifelse(is.na(x), 0, x) I suspect the problem has to do with the fact that a bare "NA" is mode logical, but without sample code, I can't see exactly where you're going wrong. Perhaps you got the arguments to ifelse in the wrong order? x <- NA ifelse(is.na(x), 0, x) # Gives numeric result ifelse(is.na(x), x, 0) # Gives logical result Duncan Murdoch
On Sun, 2004-12-05 at 01:37, Nathan Leon Pace, MD, MStat wrote:> Hi, > > I using the boot package 1.2-20 on R 2.0.1. > > My statistics function estimates 6 parameters. > > In a small percentage of resampled data sets my statistics function > doesn't produce an estimate for one parameter and the boot function > stops with an error. > > I can write an ifelse(exists('parameter.estimate'), parameter.estimate, > NA) statement within the statistic function to substitute an NA for the > missing estimate value. > > However, the boot.ci function to generate CIs from the boot object > won't accept NAs. > > My problem is writing code to impute a numeric value for the missing > estimate. ifelse won't generate a numeric value if the test is mode > logical. > > Any suggestions? > > Nathan > >Hi Nathan, I had this problem also. The boot package assumes that the bootstrap statistic has all ways the same dimension. The way I found to over come this was to create a vector with the number of dimensions my statistic was suppose to have and allocate each dimension to is own place on the vector. Whenever you have a statistic with less dimensions you get an NA or 0 or whatever you want, on that vector position. Regards EJ
Hi Nathan, sorry about the delay in responding. The test of whether all of the bootstrap values are equal is in the wrong place. I will correct it in the next release. Meanwhile, I think the simplest solution is to fix(boot.ci) and move the line if (const(t, min(1e-08, mean(t)/1e+06))) { print(paste("All values of t are equal to ", mean(t), "\n Cannot calculate confidence intervals")) return(NULL) } from its current position to directly after the line t <- t[fins] boot.ci should then work properly for missing statistic values. Angelo On Sat, 4 Dec 2004, Nathan Leon Pace, MD, MStat wrote:> Hi, > > I using the boot package 1.2-20 on R 2.0.1. > > My statistics function estimates 6 parameters. > > In a small percentage of resampled data sets my statistics function > doesn't produce an estimate for one parameter and the boot function > stops with an error. > > I can write an ifelse(exists('parameter.estimate'), parameter.estimate, > NA) statement within the statistic function to substitute an NA for the > missing estimate value. > > However, the boot.ci function to generate CIs from the boot object > won't accept NAs. > > My problem is writing code to impute a numeric value for the missing > estimate. ifelse won't generate a numeric value if the test is mode > logical. > > Any suggestions? > > Nathan > > > Nathan Leon Pace, MD, MStat Work:n.l.pace at utah.edu > Department of Anesthesiology Home:nlpaces at comcast.net > University of Utah Work:801.581.6393 > Salt Lake City, Utah Home:801.467.2925 > Fax:801.581.4367 Cell:801.558.3987 > > ______________________________________________ > 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 >-- ------------------------------------------------------------------ | Angelo J. Canty Email: cantya at mcmaster.ca | | Mathematics and Statistics Phone: (905) 525-9140 x 27079 | | McMaster University Fax : (905) 522-0935 | | 1280 Main St. W. | | Hamilton ON L8S 4K1 |