This function performs batch effect correction using the ComBat method from the sva package. It applies ComBat to the data after imputing missing values, but preserves the missing data (NA values) in the output.

combat_with_na(df, batch)

Arguments

df

A numeric matrix or data frame with missing values (NA) that you want to adjust for batch effects.

batch

A numeric or character vector containing the batch assignments (must have the same length as the number of samples in df).

Value

A numeric matrix or data frame with batch effects corrected, while preserving the original NA values from df.

Examples

# Assuming 'df' is your data frame with missing values and 'batch' is a vector of batch assignments
# adjusted_data <- combat_with_na(df, batch)