forked from xies/xies_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat_utils
31 lines (24 loc) · 957 Bytes
/
stat_utils
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 2 22:17:24 2019
@author: xies
"""
import numpy as np
import matplotlib.pyplot as plt
def plot_ci_manual(t, s_err, n, x, x2, y2, ax=None):
"""Return an axes of confidence bands using a simple approach.
Notes
-----
.. math:: \left| \: \hat{\mu}_{y|x0} - \mu_{y|x0} \: \right| \; \leq \; T_{n-2}^{.975} \; \hat{\sigma} \; \sqrt{\frac{1}{n}+\frac{(x_0-\bar{x})^2}{\sum_{i=1}^n{(x_i-\bar{x})^2}}}
.. math:: \hat{\sigma} = \sqrt{\sum_{i=1}^n{\frac{(y_i-\hat{y})^2}{n-2}}}
References
----------
.. [1]: M. Duarte. "Curve fitting," JUpyter Notebook.
http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/CurveFitting.ipynb
"""
if ax is None:
ax = plt.gca()
ci = t*s_err*np.sqrt(1/n + (x2-np.mean(x))**2/np.sum((x-np.mean(x))**2))
ax.fill_between(x2, y2+ci, y2-ci, color="#b9cfe7", edgecolor="")
return ax