Dear Vineeth,
You can compare your code wit the SPM implementation. You can select
GIfTI files in the "fMRI model specification" and "Factorial design
specification" modules and use the standard "Model estimation" to
estimate beta regression coefficients and write out residuals as GIfTI
files. The advantage being that it will also take into account temporal
and spatial non-sphericity, if necessary.
Best regards,
Guillaume.
On 19/04/2022 19:20, Vineeth Mohan wrote:
> Dear SPM12 and CAT12 experts,
>
> We want to estimate and write out vertex-wise regression coefficients
> and residuals using resampled & smoothed surface data processed using
> CAT12.7, and a set of covariates. Our code reads as follows:
>
> %% Read all GIfTI images
> tmp_gii = gifti(listGIfTI{1});
> num_vertices = tmp_gii.cdata.dim(1);
> all_gii = zeros([num_vertices, length(listGIfTI)]);
> sanityCheck = double(tmp_gii.faces);
> for gii = 1:length(listGIfTI)
> temp_gii = gifti(listGIfTI{gii});
> all_gii(:,gii) = double(temp_gii.cdata);
> end
>
> %% Estimate coefficients
> for vert = 1:num_vertices
> coeff(vert, 1:num_cov) = cov_mat\all_gii(vert,:)';
> end
>
> %% Calculate residuals
> for vert = 1:num_vertices
> yhat_HS = sum(bsxfun(@times, coeff(vert,1:num_cov),
> cov_mat),2);
> residuals(:,vert) = all_gii(vert,:)' - yhat_HS;
> end
>
> %% Write out coefficients
> for ncov = 1:num_cov
> tmp_gii.cdata = coeff(:,ncov);
> save(gifti(tmp_gii), fullfile(outDir, ['Betas_', num2str(ncov,
> '%02d'), '.gii']), 'ExternalFileBinary');
> end
>
> %% Write out residuals
> for subjs = 1:num_images_HS
> tmp_gii.cdata = residuals(subjs,:)';
> [~, subjName] = fileparts(listGIfTI{subjs});
> save(gifti(tmp_gii), fullfile(outDir, ['Residuals_', subjName,
> '.gii']), 'ExternalFileBinary');
> end
>
> Please suggest if this is the correct way to do it for GifTI files.
> Thank you,
> -Vineeth
--
Guillaume Flandin, PhD
Wellcome Centre for Human Neuroimaging
UCL Queen Square Institute of Neurology
London WC1N 3BG
|