Extracting effect sizes & p values?

Hello all,

I’ve been working on a project wherein I need to extract the following values prior to publication. I’ve ran scripts to extract these before (see below), but I’m unsure that they worked correctly, and so want to double check with you all prior to running with it. I followed these steps listed here: https://mrtrix.readthedocs.io/en/dev/fixel_based_analysis/mt_fibre_density_cross-section.html in order to extract the FDC values for subjects, and then correlated them with clinical variables of interest. I need to extract:

  1. The average FDC value of significant fixels in each subject to plot against the clinical variable scores for our scatterplots.
  2. The average effect size for the correlational analysis. This can be from each subject like the last one or just overall.
  3. The average p value for the correlational analysis. Again similar to the last one.

These are the last steps I need to complete so I want to be sure I do them right. Thank you all for your time!

Here is the script I used before:


#!/bin/bash

# Loop over stats_fdc_1 through stats_fdc_8
for i in {1..8}; do
    stats_dir="stats_fdc_$i"
    # Skip if directory does not exist
    if [ ! -d "$stats_dir" ]; then
        echo "Directory $stats_dir not found, skipping."
        continue
    fi
    log_file="${stats_dir}/fdc_extraction_debug.log"
    csv_file="${stats_dir}/fdc_mean_values.csv"
    # Initialize/clear CSV and log
    echo "subject_id,t,mean_value" > "$csv_file"
    echo "Starting FDC extraction in $stats_dir" > "$log_file"

    # Loop over timepoints t1..t12
    for t in $(seq 1 12); do
        mask_in="${stats_dir}/fwe_1mpvalue_t${t}.mif"
        if [ ! -f "$mask_in" ]; then
            echo "Missing mask file fwe_1mpvalue_t${t}.mif, skipping t${t}" >> "$log_file"
            continue
        fi
        # Create a binary mask of significant fixels (p<0.05 -> 1-p>0.95)
        mask_bin="${stats_dir}/mask_t${t}.mif"
        mrthreshold -abs 0.95 "$mask_in" "$mask_bin" -force -quiet
        # Count non-zero fixels in mask
        fixel_count=$(mrstats "$mask_bin" -output count -ignorezero)
        if [ "$fixel_count" -eq 0 ]; then
            echo "No significant fixels in fwe_1mpvalue_t${t}.mif, skipping t${t}" >> "$log_file"
            rm -f "$mask_bin"
            continue
        fi

        # Loop over each subject FDC file
        for subj_file in fdc/*.mif; do
            [ -e "$subj_file" ] || { echo "No subject FDC files found in fdc/, skipping."; break; }
            subj_name=$(basename "$subj_file" .mif)
            # Extract subject ID (e.g. '001' from '001_subject')
            subject_id="${subj_name%%_*}"
            if [ ! -f "$subj_file" ]; then
                echo "Subject file $subj_file not found, skipping subject $subject_id" >> "$log_file"
                continue
            fi
            # Multiply subject FDC by the binary fixel mask and compute mean (ignoring zeros)
            mean_val=$(mrcalc "$subj_file" "$mask_bin" -mult - | mrstats - -quiet -ignorezero -output mean)
            # Check if mrstats returned a value
            if [ -z "$mean_val" ]; then
                echo "Failed to compute mean for subject $subject_id at t${t}" >> "$log_file"
                continue
            fi
            # Append result to CSV
            echo "${subject_id},t${t},${mean_val}" >> "$csv_file"
        done
        # Remove temporary mask file
        rm -f "$mask_bin"
    done
done