Skip to main content

An implementation of the GRIM test, in Python

Project description

The GRIM test

An implementation of the GRIM test, in python

Introduction

This package is based on the GRIM (Granularity-Related Inconsistency of Means) test first highlighted by Heathers & Brown in their 2016 paper.

The test makes use of a simple numerical property to identify if the mean of integer values has been correctly calculated.

You don't need the original integer values. You just need the mean and the number (n) of items.

What about rounding?

Often the mean you are testing has previously been rounded. You can check if the mean is consistent with a particular rounding type by including that as an argument.

This implementation supports all the rounding types currently found in Python 3.8's decimal implementation.

(They are: ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_UP, ROUND_05UP)

If no rounding type is included then the test assumes ROUND_HALF_UP.

How do I install it?

On the command line:

pip install grim

In a google Colab/iPython notebook:

!pip install grim

Example: Is this mean, n and rounding type consistent?

from grim import mean_tester
import decimal

# mean is 11.09 and n is 21
print(mean_tester.consistency_check('11.09', '21', decimal.ROUND_HALF_UP))

This will return False as the mean could not be correct given a list of 21 integers (and using ROUND_HALF_UP rounding.)

Example: Is this mean & n consistent using any rounding type?

from grim import mean_tester
import decimal

# mean is 11.09 and n is 21
print(mean_tester.summary_consistency_check('11.09', '21'))

This will return:

{'ROUND_CEILING': False, 'ROUND_DOWN': True, 'ROUND_FLOOR': True, 'ROUND_HALF_DOWN': False, 'ROUND_HALF_EVEN': False, 'ROUND_HALF_UP': False, 'ROUND_UP': False, 'ROUND_05UP': True}

As you can see, a given mean and n might be consistent using one form of rounding but not others.

You can pass in the numbers as Strings or Decimals, this avoids floating point accuracy issues that are more likely to occur when using a 'float'.

How do I see some logging about how the possible matches the algorithm has considered?

Add an extra argument, True.

print(mean_tester.summary_consistency_check('11.09', '21', True))

A warning about floating point numbers & computers:

  1. Beware of creating Decimals from floating point numbers as these may have floating point inaccuracies. e.g.:
import decimal

print(decimal.Decimal(1.1))
1.100000000000000088817841970012523233890533447265625

Notice how the inaccurate representation of 1.1 from the floating point number has been preserved in the Decimal. Its better to create a decimal from a String E.g.:

import decimal

print(decimal.Decimal('1.1'))
1.1

Many tools can be configured to read in text [that might be a number] as a string with out parsing. Some tools, such as Webdriver, only return a string (Which is useful!)

For more information on the origins of these issues in modern computer languages read this.

How can I find out more about the GRIM test?

James Heathers has published articles that explain how the technique works and how he used it to expose inconsistencies in scientific papers.

Citation file

There is a citation file included in the code repo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grim-0.1.5.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grim-0.1.5-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file grim-0.1.5.tar.gz.

File metadata

  • Download URL: grim-0.1.5.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for grim-0.1.5.tar.gz
Algorithm Hash digest
SHA256 55abe0bf34fd427facfeccd99d11f56bfc2ef7938fbe217bbe9cd4c13a74ba8d
MD5 0f2036b7c09b836f17b3469b17ac5f33
BLAKE2b-256 2c4ba288fa68818ce1cb2c13c43a27dfb9ee64e5adaa14c86825ea9b41911f65

See more details on using hashes here.

File details

Details for the file grim-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: grim-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for grim-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e181b8b49f693987044efa70ffde76fe114af38e620401caaf89d5652251bb34
MD5 ffa420b57beecdae40e288b8b537456c
BLAKE2b-256 9c61925e2dd150df460c6226e9a6b764965a798d9b472216fba23e0a244306e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page