resample_data¶
-
sherpa.astro.ui.
resample_data
(id=None, niter=1000, seed=None)¶ Resample data with asymmetric error bars.
The function performs a parametric bootstrap assuming a skewed normal distribution centered on the observed data point with the variance given by the low and high measurement errors. The function simulates niter realizations of the data and fits each realization with the assumed model to obtain the best fit parameters. The function returns the best fit parameters for each realization, and average and standard deviation for the total number of realizations.
Parameters: - id (int or str, optional) – The identifier of the data set to use.
- niter (int, optional) – The number of iterations to use. The default is
1000
. - seed (int, optional) – The seed for the random number generator. The default is
`None`
.
See also
load_ascii_with_errors()
- Load an ASCII file with asymmetric errors as a data set.
Example
Account for of asymmetric errors when calculating parameter uncertainties:
>>> load_ascii_with_errors(1, 'test.dat') >>> set_model('polynom1d.p0') >>> thaw(p0.c1) >>> fit() Dataset = 1 Method = levmar Statistic = leastsq Initial fit statistic = 4322.56 Final fit statistic = 247.768 at function evaluation 6 Data points = 61 Degrees of freedom = 59 Change in statistic = 4074.79 p0.c0 3.2661 +/- 0.193009 p0.c1 2162.19 +/- 65.8445 >>> result = resample_data(1, niter=10) p0.c0 : avg = 4.159973865314249 , std = 1.0575403309799554 p0.c1 : avg = 1943.5489865678633 , std = 268.64478808013547 >>> print(result) {'p0.c0': [5.856479033432613, 3.8252624107243465, 4.2049348991011755, 3.3561534201274403, 5.322970544450817, 5.86486160415201, 3.4260665826046868, 3.5730735695326947, 3.2995095277181736, 2.8704270612985345], 'p0.c1': [1510.049972062868, 1995.4742750432902, 1929.9678368288805, 2145.6409294683394, 1685.1157640896092, 1487.6241980402608, 2159.9157439562578, 2100.3068897110925, 2185.418945147045, 2235.9753113309894]}
For a large number of realizations the output can be stored in the dictionary and accessed, for example, to visualize the distributions.
>>> sample = resample_data(1, 5000) p0.c0 : avg = 3.966543284267264 , std = 0.9104639711036427 p0.c1 : avg = 1988.8417667057342 , std = 220.21903089622705 >>> plot_pdf(sample['p0.c0'], bins=40)