Wednesday, July 3, 2024

AI Corner: SWIM Plots?

MolDx often asks clients in the minimal residual disease space for data as SWIM or SWIMMER plots.  I assumed this was because each patient's data "swims" across the page with timepoints for data points.

I asked Chat GPT about SWIM plots and it gave detailed instructions.   However, it also opened by given SWIM as an ACRONYM.   (See below).

I hadn't seen this before, and in fact, it didn't seem to be on Google.  I asked a separate Chat GPT session whether SWIM was the indicated statistical acronym, and it said NO, that wasn't a generally known acronym.    Ha!

But it's a nice one anyway!

##

I work with medical statistics and a technology review group asked for more of our data (summarized in a publication) in supplemental per patient "SWIM PLOTS". This is data such as tests for drug response in 50 patients.


SWIM plots (Summarized With Individual Measurements) are an effective way to present detailed per-patient data, especially in clinical studies involving drug response. These plots can show the timeline of various events or measurements for each patient, providing a clear visual representation of the data.

Here's a step-by-step guide on how you can create SWIM plots for your 50 patients' drug response data:

  1. Data Collection:

    • Ensure you have the following data for each patient:
      • Patient ID
      • Dates of drug administration or tests
      • Test results or drug response values
      • Other relevant events (e.g., side effects, dose adjustments)
  2. Data Organization:

    • Organize your data in a structured format, such as a spreadsheet. Each row represents a test or event for a patient.
    • Example format:
      Patient IDDateEventValue
      0012023-01-01Drug Start-
      0012023-01-15Test Response0.5
      0022023-01-01Drug Start-
      0022023-01-20Test Response0.8
  3. Plotting:

    • Use a plotting software or library that supports timeline visualizations, such as R (ggplot2), Python (matplotlib), or specialized software like GraphPad Prism.
    • Create a timeline plot where the x-axis represents time and the y-axis represents individual patients.
    • Each patient will have a separate row, and events or measurements will be marked along the timeline.
  4. Example in Python (using matplotlib):

    python
    import matplotlib.pyplot as plt import pandas as pd # Sample data data = { 'Patient ID': ['001', '001', '002', '002'], 'Date': ['2023-01-01', '2023-01-15', '2023-01-01', '2023-01-20'], 'Event': ['Drug Start', 'Test Response', 'Drug Start', 'Test Response'], 'Value': [None, 0.5, None, 0.8] } df = pd.DataFrame(data) df['Date'] = pd.to_datetime(df['Date']) # Plot fig, ax = plt.subplots(figsize=(10, 8)) patients = df['Patient ID'].unique() for i, patient in enumerate(patients): patient_data = df[df['Patient ID'] == patient] for _, row in patient_data.iterrows(): if row['Event'] == 'Drug Start': ax.plot(row['Date'], i, 'go', label='Drug Start' if i == 0 else "") elif row['Event'] == 'Test Response': ax.plot(row['Date'], i, 'ro', label='Test Response' if i == 0 else "") ax.text(row['Date'], i, f'{row["Value"]}', fontsize=9, ha='right') ax.set_yticks(range(len(patients))) ax.set_yticklabels(patients) ax.set_xlabel('Date') ax.set_title('SWIM Plot') ax.legend() plt.show()
  5. Interpretation:

    • Ensure each plot clearly shows the timeline for each patient.
    • Use different colors or markers to distinguish between different types of events (e.g., drug administration vs. test response).
    • Include legends and labels for clarity.
  6. Supplemental Data:

    • Provide the SWIM plots as supplemental figures in your publication.
    • Include detailed captions explaining the plots and any relevant findings.

If you need more advanced customizations or have specific requirements for your plots, let me know, and I can provide further guidance or more detailed code examples.