# TH2D covariance with error

**URL:** <https://root-forum.cern.ch/t/th2d-covariance-with-error/57837>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [January 14, 2024, 10:58am UTC](https://root-forum.cern.ch/t/th2d-covariance-with-error/57837 "2024-01-14T10:58:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zainingwang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/58f4c7/32.png) [@zainingwang](https://root-forum.cern.ch/u/zainingwang)\
**Post date:** [January 14, 2024, 10:58am UTC](https://root-forum.cern.ch/t/th2d-covariance-with-error/57837/1 "2024-01-14T10:58:25Z")

</div>

Hi, experts!  
Actually I face some problems when I calculate covariance of TH2D.

I know that we can get error of Mean with GetMeanError.  
Is there a way to obtain the error of GetCovariance?

For example, I generate a TH2D with Sumw2 called psi4\_psi2, then I calculate:

```auto
float covpsi4_psi2 = psi4_psi2->GetCovariance(1,2);

```

How should I get the errors of the result with this step just like GetMean&GetMeanError?

Thanks in advance!  
Zaining

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [January 15, 2024, 1:41pm UTC](https://root-forum.cern.ch/t/th2d-covariance-with-error/57837/2 "2024-01-15T13:41:33Z")

</div>

Hi,

We don’t have in ROOT such a function to compute the error on the full covariance matrix. You can compute the error only on the standard deviations (diagonal element of your covariance matrix).

I would suggest you to use a bootstrapping method to estimate these uncertainty, it would be probably anyway more reliable, since there are no prior assumption on the data distribution. You would need to generate many different histograms according to what you have in your original one and see the spread you get in the obtained covariance matrix.

Best regards

Lorenzo

---

<div class="post-metadata">

**Author:** ![zainingwang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/58f4c7/32.png) [@zainingwang](https://root-forum.cern.ch/u/zainingwang)\
**Post date:** [January 19, 2024, 3:17am UTC](https://root-forum.cern.ch/t/th2d-covariance-with-error/57837/3 "2024-01-19T03:17:29Z")

</div>

Hi, Lorenzo

Sorry for the late reply.

As you say, the bootstrapping method is a perfect way to gain errors, I will have a try.

Thanks for your advice.

Cheers,  
Zaining
