Error In Boot.ci Subscript Out Of Bounds
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site
R Subscript Out Of Bounds In Matrices
About Us Learn more about Stack Overflow the company Business Learn more about error in pi[[j]] : subscript out of bounds rbind hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join
Solving Problems Of Subscript Out Of Bounds In R
the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R error type “Subscript out error during wrapup: subscript out of bounds of bounds” up vote 1 down vote favorite I am simulating a correlation matrix, where the 60 variables correlate in the following way: more highly (0.6) for every two variables (1-2, 3-4... 59-60) moderate (0.3) for every group of 12 variables (1-12,13-24...) mc <- matrix(0,60,60) diag(mc) <- 1 for (c in seq(1,59,2)){ # every pair of variables in order are given 0.6 correlation mc[c,c+1] <- error in * tmp * subscript out of bounds 0.6 mc[c+1,c] <- 0.6 } for (n in seq(1,51,10)){ # every group of 12 are given correlation of 0.3 for (w in seq(12,60,12)){ # these are variables 11-12, 21-22 and such. mc[n:n+1,c(n+2,w)] <- 0.2 mc[c(n+2,w),n:n+1] <- 0.2 } } for (m in seq(3,9,2)){ # every group of 12 are given correlation of 0.3 for (w in seq(12,60,12)){ # these variables are the rest. mc[m:m+1,c(1:m-1,m+2:w)] <- 0.2 mc[c(1:m-1,m+2:w),m:m+1] <- 0.2 } } The first loop works well, but not the second and third ones. I get this error message: Error in `[<-`(`*tmp*`, m:m + 1, c(1:m - 1, m + 2:w), value = 0.2) : subscript out of bounds Error in `[<-`(`*tmp*`, m:m + 1, c(1:m - 1, m + 2:w), value = 0.2) : subscript out of bounds I would really appreciate any hints, since I don't see the loop commands get to exceed the matrix dimensions. Thanks a lot in advance! r loops share|improve this question edited Jan 14 '14 at 13:48 asked Jan 14 '14 at 13:29 Gina Zetkin 71118 try putting cat() or print() statements in your code to see what's going on, or use options(error=recover) to have R d
returnsan n x n matrix. I want to take bootstrap samples form the input matrix inthe way as each row represent a multivariate observation, so eachbootstrap sample would be an n x m matrix,
Rbind Subscript Out Of Bounds
and on each sample I want tocalculate the n x n matrix.This task can options(error=recover) be done with the sample function, but I would like to usethe boot() function. I hope that it is going to be faster.Something
Subscript Out Of Bounds Shiny
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 matrixSince the final goal would be to put a confidence interval on thestatistics in each cell of the matrix http://stackoverflow.com/questions/21114784/r-error-type-subscript-out-of-bounds I would like to use the boot.ci.Even if I do the resampling with the sample function and I just use theboot.ci by artificially putting togethet an boot.out type of list I runinto problems. Any idea how to set it up?Also a note, the examples at the end of the boot.ci documentation, for thecity and gravity data set I get error messages for boot.ci() call. Didanyone else noticed that? E.g.boot.ci(grav1.boot, type=c("stud","norm"))[1] "odd number of coulumns"[,1] [,2][1,] http://grokbase.com/t/r/r-help/0342t2abds/r-can-boot-return-matrix "95/-5.803" "0.123/-6.929"Error in paste("(", ints1[, 2 * (1:n1)], ",", sep = "") :subscript out of boundsThanks for any help in advance!Katalin___Katalin CsilleryDivision of Biological SciencesUniversity of Montana, Missoula MT 59801Phone: 406 243 6106, E-mail: csillery at selway.umt.edu---------------------------------------------------- reply Tweet Search Discussions Search All Groups r-help 1 response Oldest Nested Thomas W Blackwell 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 <- Thomas W Blackwell at Apr 3, 2003 at 10:45 pm ⇧ You're certainly very close. I observe that you have interchangedpositions for the function which calculates the statistic (f2) andthe 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 spottedthis already. Details are in help("boot").And, a matrix is also a vector, so perhaps f1() can return a matrixwithout causing any problems. If not, usef2
messages Witold E Wolski Threaded Open this post in threaded view ♦ ♦ http://r.789695.n4.nabble.com/how-does-a-valid-subscript-can-produce-an-quot-subscript-out-of-bounds-quot-error-td4693536.html | Report Content as Inappropriate ♦ ♦ how does a valid subscript can produce an "subscript out of bounds" error? how does a valid subscript (see first 2 lines) can produce an "subscript out of bounds" error (see line 4)? 1> sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id) [1] 0 2> sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt)) subscript out [1] 0 3> class(msexp$rt) [1] "matrix" 4> msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,]) Error in msexp$rt[msexp$pepinfo$transition_group_id, ] : subscript out of bounds > -- Witold Eryk Wolski ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Duncan Murdoch-2 Threaded Open this post in threaded subscript out of view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: how does a valid subscript can produce an "subscript out of bounds" error? On 04/07/2014, 6:35 PM, Witold E Wolski wrote: > how does a valid subscript (see first 2 lines) can produce an > "subscript out of bounds" error (see line 4)? > > > 1> sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id) > [1] 0 > 2> sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt)) > [1] 0 > 3> class(msexp$rt) > [1] "matrix" > 4> msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,]) > Error in msexp$rt[msexp$pepinfo$transition_group_id, ] : > subscript out of bounds >> > How are we supposed to know, since you didn't show us msexp$pepinfo$transition_group_id or the thing it was indexing, msexp$rt ? Please post reproducible examples. Duncan Murdoch ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Duncan Murdoch-2 Threaded Open this post in threaded v