Skip to content
Entourage
Article7 min read

Trend analysis in a GMP environment: what do Python and R deliver, and what do they require?

Forough Homayonpour

Forough Homayonpour

Consultant Quality Assurance

In brief

Where the EU GMP Guide requires trend analysis (Chapter 1 section 1.10, Chapter 6 sections 6.9 and 6.16, Annex 15 sections 5.28 to 5.32), what a script in Python or R changes compared with a spreadsheet, what Annex 11 requires of an analysis script and when a change becomes a finding that has to be investigated.

A single deviation says little about whether a quality system is running stably. Only the series shows whether events cluster on one line, in one shift or with one material. The first part of this series identified looking at each case in isolation as a weakness of root cause analysis. This part covers an important complement to it: trend analysis.

Python and R lend themselves to this. Both are freely available, and both describe an analysis as a script that can be read, checked and repeated. Compared with an analysis built by hand in a spreadsheet, that is the essential difference.

In a GMP environment, a second question arises. A script whose result feeds into a quality decision is itself part of a computerised system. In line with its intended use and the associated risks, it has to be checked and controlled in such a way that its result can be trusted.

The Guide requires trend analysis in several places. In section 1.10, Chapter 1 provides for regular product quality reviews, normally annually, which are intended, among other things, to verify process consistency and to highlight trends. In section 6.9, Chapter 6 requires data such as test results, yields and environmental controls to be recorded in a manner permitting trend evaluation, and results out of trend or out of specification to be investigated. Section 6.16, in the part on testing in the laboratory, additionally requires the test results for parameters identified as a quality attribute or as critical to be trended and checked for consistency with each other.

Annex 15 carries the idea forward to the manufacturing process. Trend analysis therefore also covers relevant process parameters of manufacturing and not only laboratory results. Ongoing process verification under sections 5.28 to 5.32 serves to monitor the manufacturing process over the entire product lifecycle. Where appropriate, statistical tools should support the conclusions on the variability and capability of the process. In Annex I.9, ICH Q9(R1) names such tools, including control charts, histograms, Pareto charts and process capability analysis. For control charts, the ISO 7870 series can be consulted in addition. Further areas of application for trend analysis include, for example, stability data and environmental monitoring.

None of the regulations mentioned prescribes a particular program. What is required is the analysis; the choice of tool remains with the company. The same applies to deviations and CAPA: Chapter 1 requires the effectiveness of actions to be monitored and evaluated, and trend analysis can help to assess that effectiveness.

What a script does differently from a spreadsheet

An analysis in Python or R consists of text: read in data, filter, count, calculate, plot. Every step is in the script and can be read by a second person. If the same script runs again with the same data, the same package versions and under controlled execution conditions, the result can be reproduced. In a spreadsheet, data, formulas and result often sit in the same file, and a manual change to a cell does not necessarily leave a traceable change history without additional safeguards.

Both languages offer ready-made building blocks for the questions of quality assurance. In Python, pandas handles reading in and condensing tables and matplotlib the graphical presentation. R was created as a language for statistical computing and graphics. There, the ggplot2 package makes it possible to create a variety of charts.

Following on from the first part, three analyses suggest themselves. The number of deviations per month, for example related to a reference figure that suits the process in question (such as the number of batches manufactured or of tests performed) and broken down by area and root cause category, can make clusters visible. A Pareto chart of root cause categories shows where the focus lies. A control chart for the test result of a parameter identified as a quality attribute or as critical can show a shift before a specification limit is breached.

Both languages are sufficient for these analyses. The choice depends on the setting: on the skills in the team, on the connection to existing systems and on who will maintain the script later.

An example from my research shows how important it is to take technical influencing factors into account in data analysis. Using Python and R, I compared data from different analyses in order to examine the influence of technical factors and different laboratory conditions on the results. It turned out that such factors can considerably influence the interpretation of the data. A comparable approach can also be applied to GMP-relevant data, for example to examine laboratory results or process parameters over a longer period and to detect conspicuous changes early.

What Annex 11 requires of an analysis script

Annex 11 applies to all forms of computerised systems used as part of GMP-regulated activities. The application has to be validated, the IT infrastructure qualified. The wording says "all forms", and this can be read to mean that a script whose result feeds into the product quality review, an effectiveness check or the assessment of a deviation falls within this scope, even if it is self-written and short. What matters here is the actual intended use and the GMP relevance of the script.

The extent depends on the risk. In section 1, Annex 11 requires decisions on the extent of validation and data integrity controls to be based on a justified and documented risk assessment. An exploratory analysis with which someone follows up a suspicion therefore has to be assessed differently, depending on its intended use and GMP relevance, from a script whose result regularly feeds into an approved report as evidence.

For a script of the second kind, a number of requirements can be derived from this. The version of the script and the versions of the packages used are recorded and assigned to the analysis. The script has been checked using suitable test cases, including a data set with a known result as well as relevant boundary and error cases. Changes are made in a controlled manner in accordance with a defined procedure, as Annex 11 requires in section 10 for computerised systems.

The same applies to the data. In section 5, Annex 11 requires appropriate checks for the correct and secure entry and processing of data when data are exchanged electronically between systems. The script should read from the leading system or from an export whose origin, time and scope are documented, and should not change the source data. Excluding a value belongs in the script as a justified step. If a value is deleted from the input file without a documented justification and a traceable change history, the traceability of the analysis is put at risk.

When a trend is a finding

A line that rises is not yet a statistically demonstrated trend. Whether a change goes beyond ordinary variation can be assessed with the help of evaluation rules defined in advance: the warning and action limits of a control chart, a threshold for the deviation rate, rules for runs of consecutive values.

This includes a sufficient data basis. The FDA guidance on process validation, which applies to the US market, recommends that data be evaluated statistically and reviewed by trained personnel. It provides for more intensive monitoring until sufficient data are available for reliable estimates of variability, and recommends involving a statistician or a person trained in statistical process control for the data collection plan and the methods. The script does not replace this expertise.

What follows a signal should also be defined in advance. Chapter 6 requires a procedure for the investigation of out-of-trend results. For deviation trends, the same route as in the first part suggests itself: the pattern is assessed in line with the risk and the internal procedures, for example as part of a PQR, a management review or the CAPA process. A separate deviation may be required, but is not necessary in every case. Conversely, a control chart can serve as a criterion of the effectiveness check defined in advance.

Python and R make a trend analysis repeatable and verifiable. Whether it holds up is decided by the same points as with any other GMP tool: defined limits, controlled data, a script checked in proportion to the risk and a person who can assess the result in substance. Then recurring deviations can be detected earlier, and the path from the data to the result can be shown step by step during an inspection. How such evidence can be prepared for a GMP inspection is the subject of the third part of this series.

Image notice: The illustrative and header images were generated using AI and do not depict real people, places, or events. The portrait photographs show real people.

Relevant for your project?

Similar questions in your current project?

In a first call we clarify what is specifically relevant for your situation, without obligation.

Request a call →

Regulations & standards considered

  • EU GMP Guide Part I, Chapter 1 (Pharmaceutical Quality System), section 1.10 (Product Quality Review) and section 1.4 (xiv)
  • EU GMP Guide Part I, Chapter 6 (Quality Control), sections 6.7, 6.9 and 6.16: trend evaluation, investigation of OOT results, trending of test results for quality attributes and critical parameters in the QC laboratory
  • EU GMP Guide Annex 15 (Qualification and Validation), sections 5.28 to 5.32: ongoing process verification
  • EU GMP Guide Annex 11 (Computerised Systems), revision January 2011
  • ICH Q9(R1) Quality Risk Management, Annex I.9: supporting statistical tools
Sources

Related insights

All insights →

Your project

Have a concrete project?

Briefly outline your situation. We'll respond with an initial assessment, usually within one business day.

Your inquiry goes to our team, which brings in the subject-matter experts as needed.

Prefer direct? +39 02 8904 1000
contact@theentourage.it

  • Reply usually within one working day
  • 3 locations: DE · CH · IT · projects in the US too
  • 100% life sciences