Quality Assurance of Code for Analysis and Research

This Analysis Function and Government Statistical Service (GSS) guidance is produced by the Best Practice and Impact division of the Office for National Statistics.

The guidance has been written to support analysts in government who use coding in their work. This includes those who produce statistics, carry out modelling or apply data science.

The guidance is a living document, so will be continually updated. You can refer to the current version of the guidance by it’s version number, found below the site table of contents. We are extremely grateful for any feedback that you are able to provide on existing and future content. Please get in touch via GitHub Issues or gsshelp@statistics.gov.uk.

About us

The Best Practice and Impact division supports government analysis by providing guidance, consultancy and training.

You can find us on:

Citing the book

The following structure can be used to reference the current version of the book:

UK Government Analytical Community. (2020). Quality assurance of code for analysis and research (version 2021.8). Office for National Statistics, Best Practice and Impact division: https://best-practice-and-impact.github.io/qa-of-code-guidance/

How to get the most out of the book

This guidance is tailored to government analysts who would like to quality assure their code and increase the reproducibility of their analyses. We have tried to interpret the requirements of pieces of guidance (the principles) into actions and deliverables for analytical programming.

However, the practices outlined in the book are general to many applications of programming, so may also be relevant for those outside of government. This book might be most useful for you if you are:

  • writing code to automate part of your work and would like to assure that it is working as expected

  • developing a statistical production pipeline and would like to assure that it is sustainable and reproducible

  • developing models and would like to assure that they are transparent and reproducible

  • developing data science techniques and would like your code to be useful to others

  • looking for a high level introduction to software engineering practices in the context of analysis and research

This book can be used to guide your learning and as a reference. Each chapter describes the risks that the described practices may help to address. Therefore, you should strive to apply the most appropriate practices given the risks associated with your work.

The principles in this book are language agnostic. It does not form a comprehensive learning resource and you may often need to study further resources to implement these practices. That said, examples and useful references are provided for Python and R, as open source languages that are commonly applied across government.

Accessibility statement

This accessibility statement applies to the Quality Assurance of Code for Analysis and Research. Please note that this does not include third-party content that is referenced from this guidance.

The website is managed by the Best Practice and Impact division of the Office for National Statistics. We would like this guidance to be accessible for as many people as possible. This means that you should be able to:

  • change colours, contrast levels and fonts

  • zoom in up to 300% without the text spilling off the screen

  • navigate most of the website using just a keyboard

  • navigate most of the website using speech recognition software

  • listen to most of the website using a screen reader (including the most recent versions of JAWS, NVDA and VoiceOver)

For keyboard navigation, Up Arrow and Down Arrowkeys can be used to scroll up and down on the current page. Left Arrow and Right Arrow keys can be used to move forwards and backwards through the pages of the book. Tabbed content (including code example) can be focused using the Tab key. Left Arrow and Right Arrow keys are then used to focus the required tab option, where Enter can be used to select that option and display the associated content.

Feedback and reporting accessibility problems

We’re always looking to improve the accessibility of our guidance. If you find any problems not listed on this page or think that we’re not meeting accessibility requirements, please contact us by email at gsshelp@statistics.gov.uk. Please also get in touch if you are unable to access any part of this guidance, or require the content in a different format.

We will consider your request and aim to get back to you within 5 working days.

Enforcement procedure

The Equality and Human Rights Commission (EHRC) is responsible for enforcing the Public Sector Bodies (Websites and Mobile Applications) (No. 2) Accessibility Regulations 2018 (the ‘accessibility regulations’). If you’re not happy with how we respond to your complaint, you should contact the Equality Advisory and Support Service (EASS).