I’m trying to run the function lmervoxel on SPM-generated 1st level contrast images. I keep getting this error and I don’t know where this variable “voxel1…” comes from. I input con_images (my dependent variable) as paths to the lmervoxel function, together with a mask and covariates:
Loop over each subject and session
for (i in 1:length(con_images)) {
Select the NIfTI image path for the current subject
current_image_path <- con_paths[[i]]
Call the lmerVoxel function with the selected image path
lmerVoxel(image = current_image_path, mask = mask_path, fourdOut = fourd_out_path,
formula = formula,
subjData = cov_reduced_data, mc.preschedule = TRUE, ncores = 1)
}
Each con_image is an image array double:
enter image description here
the formula I use is the following:
formula <- "con_images ~ Group + Propofol_Concentration + Gender + (1 + session| Subjects) + (1 + Subjects| Propofol_Concentration)"
When I run the code, it says:
[1] "Created time series to matrix" [1] "Created formula list" [1] "Running test model" **Error in eval(predvars, data, env) : object 'voxel1con_images' not found**
Can someone help please?
Thanking a lot in advance,
Benedetta
# read in nii files
library(RNifti)
library(oro.nifti)
library(voxel)
library(neurobase)
library(readxl)
library(neurobase)
library(readxl)
cov_reduced_data <- read_excel("cov_reduced_data.xlsx",
col_types = c("numeric", "numeric", "text",
"numeric", "numeric", "text"))
View(cov_reduced_data)
# Path to the main folder containing subject folders
main_folder <- "/Users/benedetta/DISC_CONS_LME/Data_reduced"
# Path to the joint mask file (same for all subjects)
mask_path <- "/Users/benedetta/DISC_CONS_LME/try-bin 2.nii"
# Initialize lists to store file paths
con_paths <- list()
# Loop through each row of the covariates data
for (i in 1:nrow(cov_reduced_data)) {
# Extract subject and session information from the covariates data
subject <- cov_reduced_data$Subjects[i]
session <- cov_reduced_data$Session[i]
# Construct subject folder path
subject_folder <- file.path(main_folder, sprintf("s0%d", subject))
# Construct session folder path
session_folder <- file.path(subject_folder, sprintf("Ses-%d", session))
# Construct the file paths for con_0003.nii and con_0004.nii
con_path_3 <- file.path(session_folder, "con_0003.nii")
con_path_4 <- file.path(session_folder, "con_0004.nii")
# Add the file paths to the list
con_paths[[i]] <- c(con_path_3, con_path_4)
}
# Create variables to store NIfTI image objects
con_images <- list()
mask_image <- readNifti(mask_path)
# Read each NIfTI image and assign it to a variable
for (i in 1:length(con_paths)) {
con_image <- readNifti(con_paths[[i]][1]) # Selecting the first NIfTI image
con_images[[i]] <- con_image
}
# Define the path for the 4D output image
fourd_out_path <- "/Users/benedetta/DISC_CONS_LME/fourd_out/output_4d_image.nii"
formula <- "con_images ~ Group + Propofol_Concentration + Gender + (1 + session| Subjects) + (1 + Subjects| Propofol_Concentration)"
# Loop over each subject and session
for (i in 1:length(con_images)) {
# Select the NIfTI image path for the current subject
current_image_path <- con_paths[[i]]
# Call the lmerVoxel function with the selected image path
lmerVoxel(image = current_image_path, mask = mask_path, fourdOut = fourd_out_path,
formula = formula,
subjData = cov_reduced_data, mc.preschedule = TRUE, ncores = 1)
}