Mystery of 2.2e-16 in R


Burak Demirtas


April 2, 2023

Strange p-values

One of my friends asked help on some R code today. She was running a correlation test and even the data is different, p-value was coming exactly the same number. So she assumed she was doing something wrong.

I checked the code, it was just fine and I saw the same thing: 2.2e-16 was the value popping up even we use different data.

I suspected that since it’s a very small number and R insisting on that number, it should be some sort of limit. When I do some quick search, bam! I came up with the term called “Machine Epsilon”.👾🤖

But , why?

Before the term itself, let’s think that computer made a simple division:

Hide / show the code
1 / 3
[1] 0.3333333

Are these 3s really 7 times after 0? Or is it actually going to infinite number of 3s? We know there should be infinite number of 3s there even if we see just 7 here. Which means, normally, computer should have run this simple code forever right? But it didn’t. It stopped at some point and gave me the result. Why did it stop? Why your old school calculator or calculator on your phone stops?

Because, computers cannot run forever , they should stop at some point and generate a result. Their resources and their memory is also finite. So, they HAVE TO stop at one point.

Machine Epsilon

The point where your computer stops generating any more digits after zero is called Machine Epsilon. It’s also the smallest value you can use for any mathematical operation. (epsilon letter usually refers to limit)

The term was first introduced by James H. Wilkinson in his 1963 paper “Error Analysis of Direct Methods of Matrix Inversion”. In this paper, Wilkinson defined machine epsilon as “the smallest number which, when added to 1.0, yields a result distinct from 1.0”.

This definition is still valid: machine epsilon is the smallest number that can be added to 1.0 and produce a different result in the computer’s floating-point arithmetic.

Then, what’s happening to the values below this number? They simply get this value!

That’s why my friend was seeing the same p-value over and over even if she changes the data. She was getting a very low p-value, even lower than 0.00000000000000022. (2.2e-16) Since this is the machine epsilon of R, it was quite what we should have expected.

How to See Machine Epsilon

Just type in the console:

Hide / show the code
[1] 2.220446e-16

Do you want to see the full list? Go ahead without the $ sign:

Hide / show the code
[1] 2.220446e-16

[1] 1.110223e-16

[1] 2.225074e-308

[1] 1.797693e+308

[1] 2

[1] 53

[1] 5

[1] 0

[1] -52

[1] -53

[1] 11

[1] -1022

[1] 1024

[1] 2147483647

[1] 4

[1] 8

[1] 16

[1] 8

[1] 1.084202e-19

[1] 5.421011e-20

[1] 64

[1] 5

[1] 0

[1] -63

[1] -64

[1] 15

[1] -16382

[1] 16384

So, another new term for me which was discovered 60 years ago. 🤓