Learn R Programming

ciftiTools (version 0.21.1)

impute_xifti: Impute "xifti" data

Description

Impute locations using the values of neighboring locations.

Usage

impute_xifti(
  xifti,
  mask = NULL,
  method = c("laplacian", "layerwise"),
  layerwise_FUN = function(x) {
     mean(x, na.rm = TRUE)
 },
  smooth = NULL,
  smooth_args = NULL,
  ...
)

Value

The input xifti with imputed data values.

Arguments

xifti

A "xifti" object. The corresponding surface must be included for each cortex with data. add_surf can be used to add HCP fs_LR surfaces.

mask

A logical vector whose length matches the number of rows in xifti, indicating which locations in xifti to impute. (Locations that are TRUE will be imputed.)

If NULL (default), will use the mask of locations with at least one NA and NaN value across the columns of xifti. The NA and NaN locations will be replaced with numeric values (except in the case of any voxels with no immediate neighbors).

On the other hand, if mask is provided, the NA and NaN values originally in xifti, and not in mask, will be left alone. Only locations in mask will be imputed.

Can also be a matrix to impute different locations for different columns.

method

The imputation method, applied to both the cortex and subcortex. "laplacian" (default) solves a sparse linear system (harmonic interpolation) to impute all masked locations simultaneously, whereas "layerwise" iteratively fills in boundary vertices/voxels one layer at a time using layerwise_FUN applied to neighboring values.

For high-resolution cortex data or the subcortex, the Laplacian method may run out of memory, in which case the layerwise method is an alternative.

layerwise_FUN

The function to use to impute the values if method=="layerwise". It should accept a vector of numeric values (the values of neighboring locations) and return a single numeric value (the value to assign). Default: mean(..., na.rm=TRUE). Not used if method="laplacian".

smooth

Smooth the imputed values? Smoothing will be calculated using the original and imputed data together, but only at imputed locations will the data be replaced with the smoothed values. If NULL (default), smooth if method=="layerwise" and not if method=="laplacian", which already produces very smooth results.

smooth_args

List of arguments to smooth_cifti. Ignored if !smooth. x and cifti_target_fname should not be provided: x will be set to xifti, and cifti_taget_fname will remain NULL.

...

Additional arguments to layerwise_FUN.

Details

Cortex vertices will be imputed using the five or six other vertices which share a face. The surface geometry must be present in the "xifti".

Subcortex voxels will be imputed using the six immediate neighbors (ignoring any out-of-mask location): above, below, left, right, forward, and back.

Note that during imputation, locations in mask, as well as the medial wall for the cortex, are temporarily set to NA.

Note that handling of NA values and the mask slightly differs from the cortex and subcortex. layerwise_FUN like mean will behave similarly, but functions which change depending on the amount of neighbor locations with NA values may differ. layerwise_FUN should handle NA values accordingly. For most use cases, it will make sense to pass na.rm=TRUE to ... if layerwise_FUN is a summary function like mean.

See Also

Other manipulating xifti: add_surf(), apply_parc(), apply_xifti(), combine_xifti(), convert_xifti(), merge_xifti(), move_to_mwall(), move_to_submask(), newdata_xifti(), remap_cifti(), remove_xifti(), resample_cifti(), resample_cifti_from_template(), scale_xifti(), select_xifti(), set_names_xifti(), smooth_cifti(), transform_xifti()