Dear All, I have a function which takes a n x m matrix as an argument and returns an n x n matrix. I want to take bootstrap samples form the input matrix in the way as each row represent a multivariate observation, so each bootstrap sample would be an n x m matrix, and on each sample I want to calculate the n x n matrix. This task can be done with the sample function, but I would like to use the boot() function. I hope that it is going to be faster. Something like this: f1 <- function(nxm.matrix){...; return(nxn.matrix)} f2 <- function(nxm.matrix, i) f1(nxm.matrix[i,]) boot.out <- boot(nxm.matrix, R, f2) Error: incorrect number of subscripts on matrix Since the final goal would be to put a confidence interval on the statistics in each cell of the matrix I would like to use the boot.ci. Even if I do the resampling with the sample function and I just use the boot.ci by artificially putting togethet an boot.out type of list I run into problems. Any idea how to set it up? Also a note, the examples at the end of the boot.ci documentation, for the city and gravity data set I get error messages for boot.ci() call. Did anyone else noticed that? E.g.> boot.ci(grav1.boot, type=c("stud","norm"))[1] "odd number of coulumns" [,1] [,2] [1,] "95/-5.803" "0.123/-6.929" Error in paste("(", ints1[, 2 * (1:n1)], ",", sep = "") : subscript out of bounds Thanks for any help in advance! Katalin ___ Katalin Csillery Division of Biological Sciences University of Montana, Missoula MT 59801 Phone: 406 243 6106, E-mail: csillery at selway.umt.edu ----------------------------------------------------
You're certainly very close. I observe that you have interchanged positions for the function which calculates the statistic (f2) and the number of replicates (R) in the third line of your example below. Swap positions, or assign arguments by name instead of by position, and I would expect this example to work. Probably, you've spotted this already. Details are in help("boot"). And, a matrix is also a vector, so perhaps f1() can return a matrix without causing any problems. If not, use f2 <- function(nxm.matrix, i) as.vector(f1(nxm.matrix[i, ])) The confidence intervals will require a separate call to boot.ci() for each entry in the matrix, changing the value of boot.ci(index= ) each time. - tom blackwell - u michigan medical school - ann arbor - On Wed, 2 Apr 2003, Katalin Csillery wrote:> Dear All, > > I have a function which takes a n x m matrix as an argument and returns > an n x n matrix. I want to take bootstrap samples form the input matrix > in the way as each row represent a multivariate observation, so each > bootstrap sample would be an n x m matrix, and on each sample I want to > calculate the n x n matrix. > > f1 <- function(nxm.matrix){...; return(nxn.matrix)} > f2 <- function(nxm.matrix, i) f1(nxm.matrix[i,]) > boot.out <- boot(nxm.matrix, R, f2) > Error: incorrect number of subscripts on matrix > > Since the final goal would be to put a confidence interval on the > statistics in each cell of the matrix I would like to use the boot.ci. > Even if I do the resampling with the sample function and I just use the > boot.ci by artificially putting togethet an boot.out type of list I run > into problems. Any idea how to set it up? > > Katalin Csillery > Division of Biological Sciences > University of Montana, Missoula MT 59801 > Phone: 406 243 6106, E-mail: csillery at selway.umt.edu > ----------------------------------------------------