Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Apparently, bcajack loses the final element of a vector when that final element has been included in a subset. #7

Open
R180 opened this issue Dec 28, 2021 · 2 comments

Comments

@R180
Copy link

R180 commented Dec 28, 2021

@bnaras

# BUG: Apparently, bcajack loses the final element of a vector when that final element has been included in a subset.
#
# ----------------------------------------------------------------------------
# This does NOT work (produces NAs for the BCA confidence interval limits).
# ----------------------------------------------------------------------------
myData <- c(4,8,2,5,4,6,7,7,1,8,2,2,5,3,6,7,3,6,2,2,1,9,3,2,335)
myFunction <- function(k) {
    myStat <- mean(k[1:25]) # This causes bcajack to produce NAs for the BCA confidence limits
                            # because the subset includes the final value in the input-vector.
    return(myStat)
}
set.seed(5)
myBcaResult <- bcajack(x = myData, B = 5000, func = myFunction,
verbose = FALSE, alpha = c(0.001,0.01,0.05))
myBcaResult
#
# ----------------------------------------------------------------------------
# This DOES work since the function doesn't use the final value of the input vector.
# ----------------------------------------------------------------------------
myData <- c(4,8,2,5,4,6,7,7,1,8,2,2,5,3,6,7,3,6,2,2,1,9,3,2,335)
myFunction <- function(k) {
    myStat <- mean(k[1:24]) # This produces proper output 
                            # since the subsetting excludes the input-vector's final value.
return(myStat)
}
set.seed(5)
myBcaResult <- bcajack(x = myData, B = 5000, func = myFunction,
verbose = FALSE, alpha = c(0.001,0.01,0.05))
myBcaResult
 
# ----------------------------------------------------------------------------
# This DOES work, since there's no subsetting.
# ----------------------------------------------------------------------------
myData <- c(4,8,2,5,4,6,7,7,1,8,2,2,5,3,6,7,3,6,2,2,1,9,3,2,335)
myFunction <- function(k) {
    myStat <- mean(k) # This produces proper output 
                                   # since there's no subsetting.
return(myStat)
}
set.seed(5)
myBcaResult <- bcajack(x = myData, B = 5000, func = myFunction,
verbose = FALSE, alpha = c(0.001,0.01,0.05))
myBcaResult
@R180 R180 mentioned this issue Dec 28, 2021
@R180 R180 changed the title BUG. Apparently, bcajack loses the final value in any subset of a vector. BUG: Apparently, bcajack loses the final element of a vector when that final element has been included in a subset. Dec 28, 2021
@bnaras
Copy link
Owner

bnaras commented Jan 2, 2022

I don't see how this is a bug. myFunction is under your control and you've hardwired a constant into the index vector (k[1:25]). Nowhere is a guarantee made about length(x); indeed, for the jack-knife calculations, the length is n-1, but best not to assume that either. Also, the documentation for bcajack states that func(x) should return a real value.

@R180
Copy link
Author

R180 commented Jan 3, 2022

Thanks. I had not realized that the element numbers (e.g., row numbers) corresponded to the element numbers in the original data set rather than the bootstrapped (or jackknifed) data set. S I have included the following note my self in the following R code (which does indeed work):

myData <- cbind(c(4,8,2,5,4,6,7,7,1,8,5,2,3,5,8,2),c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2))
myFunction <- function(k) {
 
  # Note. The function should not refer to element numbers (row numbers, column numbers, 
  # or vector element numbers) within the function's input data, since bcajack controls
  # which element numbers are utilized at any given point in time. 
    
  myStat <- mean(k[k[,2] == 1, 1]) - mean(k[k[,2] == 2 ,1])   
return(myStat)
}
set.seed(5)
myBcaResult <- bcajack(x = myData, B = 5000, func = myFunction,
verbose = FALSE, alpha = c(0.001,0.01,0.05))
myBcaResult

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants