bbuchsbaum / rMVPA

Multivoxel Pattern Analysis in R
http://bbuchsbaum.github.io/rMVPA/
12 stars 11 forks source link

error with test_regional_analysis #6

Closed brynngithub closed 9 months ago

brynngithub commented 10 months ago

Hi! Recently I ran some examples in the test_mvpa_regional.R in testhat folder, but when I run the last line of the example "standard mvpa_regional and custom cross-validation runs without error/line 290" my RStudio throws me this error:

Error in purrr::map(): ℹ In index: 1. Caused by error in v@coords: ! no applicable method for @ applied to an object of class "integer"

Programming Language: R 4.3.1, Rstudio 2022.02.4 Operating System: Ununtu 16.04.7 Framework/Library Used: rMVPA 0.1.2, purr1.0.2, Matrix1.6-4

I really appreciate any help you can provide.

bbuchsbaum commented 10 months ago

Thanks for reporting this. This should now be fixed. Please don't hesitate to reach out to me if you want to use this package.

brynngithub commented 10 months ago

Thank you for your timely response. However, when I ran the following code, I faced the same error:

library(neuroim2) library(neurosurf) library(testthat) library(assertthat) library(rMVPA) test_that("standard mvpa_regional and custom cross-validation runs without error", { dataset <- gen_sample_dataset(c(5,5,5), 100, blocks=3) sample_set <- replicate(5, { list(train=sample(1:80), test=sample(1:100)) }, simplify=FALSE)

regionMask <- NeuroVol(sample(1:5, size=length(dataset$dataset$mask), replace=TRUE), space(dataset$dataset$mask)) cval <- custom_cross_validation(sample_set)

model <- load_model("sda_notune") mspec <- mvpa_model(model, dataset$dataset, design=dataset$design, model_type="classification", crossval=cval) res <- run_regional(mspec,regionMask) expect_true(!is.null(res)) })

2d8221836b6ae2cc2e1f5336cac1742d

bbuchsbaum commented 10 months ago

I don't think you successfully reinstalled the new version. I know this because the new code is as follows: (see the commented out line "#size <- sapply(vlist, function(v) nrow(v@coords))"

remotes::install_github("bbuchsbaum/rMVPA")

....

result <- purrr::map(1:length(batch_ids), function(i) { futile.logger::flog.info("mvpa_iterate: compute analysis for batch %s ...", i)

browser()

vlist <- vox_list[batch_ids[[i]]]
#size <- sapply(vlist, function(v) nrow(v@coords))
size <- sapply(vlist, function(v) length(v))

sf <- get_samples(dset, vox_list[batch_ids[[i]]]) %>% mutate(.id=batch_ids[[i]], rnum=rnums[[i]], size=size) %>% filter(size>=2)
if (nrow(sf) > 0) {
  sf <- sf %>% rowwise()  %>% mutate(roi=list(extract_roi(sample,dset))) %>% select(-sample) 
  fut_mvpa(mod_spec, sf, tot, do_fun, verbose, permute, compute_performance, return_fits, return_predictions)
}

}) %>% bind_rows()

brynngithub commented 9 months ago

Yes, as you mentioned, after successfully reinstalling the new version, the script runs smoothly now. Thank you very much for your help!