Author: Richard Chukwu
Introduction
Since everyone’s talking about AI Agents, I decided to explore how well an LLM could interpret electrochemical impedance spectroscopy (EIS) data, using my previous research as a test case. The analysis of EIS data traditionally involves three key stages: data quality verification using tools like Boukamp’s linKK, fitting equivalent circuit models (ECM) using complex non-linear least squares (CNLS), and analyzing the distribution of relaxation times (DRT).
An idea came to my mind. What if we could use domain knowledge to constrain an LLM and reduce its mistakes in interpreting the results of an EIS analysis? Simply put, we build a workflow where we give the LLM access to the EIS analysis tools and have it orchestrate them to analyse data and explain the results.
Introducing Impedance Agent [1]
Impedance Agent [1] is a Python package developed for automated impedance spectroscopy analysis. This tool leverages LLM workflows to streamline EIS data analysis while maintaining human oversight for critical decisions. The package incorporates three primary tools:” fit-LinKK”, “fit-DRT”, and “fit-ECM”, which can be run concurrently or sequentially to analyse data quality, fit quality, and underlying physical processes.
Technical Implementation
To allow the LLM to provide a rich summary, we provide a context in the form of a fit result object that captures all elements of the analysis. This context is used to craft a prompt that nudges the LLM towards a plausible explanation. The tricky part was guiding the LLM to determine when the ECM fit was good. For this, I employed several criteria.
Vector Difference:
- For each frequency, we examine the difference in the complex plane between the fitted impedance and the experimental impedance point.
- We then divide the magnitude of this complex difference by the magnitude of the experimental point.
- Finally, we average these normalized differences across all frequencies to see how close the fitted curve is to the data on average.
- A threshold of 0.10 is used in Impedance-Agent.
Path Deviation / Following
- Measures how well the model follows the shape/trajectory of the experimental data. Values greater than 10% indicate that the model fundamentally misses key features of the impedance response. 10% was chosen because it is large enough to allow for some experimental noise and minor model imperfections but small enough to ensure the model captures essential features of the experimental data.
AIC Calculations:
- Follow Ingdal, Johnsen, and Harrington’s methodology.[4]
DRT Analysis:
- Implements Kulikovsky’s approach for PEM fuel cell relaxation times.[5]
Additional Metrics:
- Include chi-square, correlation matrix, and parameter standard errors as obtained for the classical CNLS fit
Benefits and Features
The package offers several advantages:
- Automated approach reduces analysis time substantially
- Robust numerical methods for parameter extraction
- LLM-assisted interpretation with adaptability based on context and system
Information
- Comprehensive validation through Lin-KK testing and sanity checking
- Flexible output formats and publication-ready visualizations
Plot and LLM Summary (in italics) of a Reasonable Fit from the Program

**LLM Analysis Summary:**
1. **Path Following Analysis (ECM Fit):**
– The model shows acceptable performance with 5.87% deviation, indicating valid model structure though refinement is possible.
2. **Vector Difference Analysis (ECM Fit):**
– Excellent fit quality demonstrated by 0.155% average deviation between experimental and modeled data.
3. **Parameter Correlation Analysis:**
– Expected correlations observed between CPE parameters (Qh-nh), diffusion parameters (Wad-Cad), and interface parameters (Rint-Wint).
4. **DRT Analysis:**
– Six distinct processes identified across frequency ranges from 29.5 Hz to 125.6 kHz, with highest polarization (0.336) at high frequency suggesting dominant charge transfer processes.
5. **Lin-KK Analysis:**
– Data satisfies Kramers-Kronig relations with minimal residuals, confirming high measurement quality.
6. **ECM Fit Metrics:**
– Strong fit quality indicated by low chi-square (0.000133) and AIC (-346.52) values.
Plot and LLM Summary (in italics) of a Bad Fit from the Program

**LLM Analysis Summary:**.
1. **Path Following Analysis (ECM Fit)**
– **Path Deviation**: 1.179 (Poor)
– The model does NOT follow the experimental arc shape adequately.
– **Implications**: The model structure is invalid. The circuit elements are missing or incorrectly specified. This cannot be fixed by parameter adjustment alone. The model structure MUST be modified.
2. **Vector Difference Analysis (ECM Fit)
– **Vector Difference**: 0.080 (Acceptable)
– While the vector difference is acceptable, this metric is secondary to path following. Since the path deviation is poor, the vector difference is not meaningful in this context.
3. **Parameter Correlation Analysis (ECM Fit)**
– **Rs-Rct Correlation**: -0.727 (Moderate negative correlation)
– **Rs-Cdl Correlation**: 0.745 (Moderate positive correlation)
– **Rct-Cdl Correlation**: -0.412 (Weak negative correlation)
– **Interpretation**: The moderate correlations between Rs, Rct, and Cdl suggest some interdependence, but this is not the primary issue. The poor path deviation indicates structural inadequacy, not overparameterization.
4. **DRT Analysis**
– **Peak Frequencies**: [29.5, 123.0, 250.5, 1581.0, 19905.5, 125594.5] Hz
– **Peak Polarizations**: [0.123, 0.016, 0.137, 0.117, 0.095, 0.336]
– **Interpretation**: The DRT reveals multiple time constants, indicating multiple physical processes. The largest polarization (0.336) at 125.6 kHz suggests a dominant process at high frequency, likely related to charge transfer or double-layer effects. The lower-frequency peaks (29.5 Hz, 123 Hz, 250.5 Hz) may correspond to diffusion or interfacial processes.
5. **Lin-KK Analysis**
– **Residuals**:
– Real residuals: Mean = 0.000456, Max = 0.001119
– Imaginary residuals: Mean = -0.000456, Max = 0.001119
– **Interpretation**: The residuals are small and randomly distributed, indicating good data quality and no systematic errors. The Lin-KK validation confirms the data is Kramers-Kronig consistent.
6. **ECM Fit Quality Metrics**
– **Chi-Square**: 0.405
– **AIC**: 359.434
– **WRMS**: 0.00466
– **Interpretation**: The fit metrics are reasonable, but the poor path deviation overshadows these results. The model structure must be revised.
Recommendations
#### For ECM Fit:
1. **Model Structure Revision**:
– The current model (Rs + Rct || Cdl) is insufficient. Consider adding elements to account for the multiple time constants observed in the DRT.
– Suggested additions:
– A Warburg element for diffusion processes (evident in low-frequency DRT peaks).
– A second RC element or CPE to capture distributed effects (evident in high-frequency DRT peaks).
2. **Parameter Optimization**:
– Once the model structure is revised, re-optimize parameters to improve path following.
#### For Non-ECM Analysis:
1. **Data Quality**:
– The data is of high quality, as confirmed by Lin-KK validation. No measurement artifacts are evident.
2. **Model Structure Suggestions**:
– Use the DRT peaks to guide model development. For example:
– Add a Warburg element for the low-frequency peaks.
Conclusion
The summaries provided by the LLM do offer some insight into the analysis. While LLMs aren’t perfect and can hallucinate, Impedance Agent demonstrates promising capabilities in EIS and general electrochemical analyses. It serves as a working proof of concept (POC) of how an LLM workflow could be introduced into scientific data analysis. The tool aims to augment rather than replace expert analysis, reduce the time spent in analysing data, and provide valuable insights to guide experienced researchers.
References
- Impedance Agent, GitHub: [https://github.com/richinex/impedance-agent]
- Bernard A. Boukamp, A package for impedance/admittance data analysis, Solid State Ionics, 18-19(1), 1986.
- Schönleber, M. et al., A Method for Improving the Robustness of linear Kramers-Kronig Validity Tests, Electrochimica Acta 131, 20-27 (2014).
- Mats Ingdal, Roy Johnsen, David A. Harrington, The Akaike information criterion in weighted regression of immittance data, Electrochimica Acta 317 (2019)
- Andrei Kulikovsky, A model–based analysis of PEM fuel cell distribution of relaxation times, Electrochimica Acta 429 (2022)
See also: Equivalent Circuit Model