A collection of functions that simplify the process of creating calibration curves.
Project description
ChemCal
Install
pip install ChemCal
How to use
First we generate some data to work with.
# generate training data and sample data
test_data = pd.DataFrame({'concentration': [0.2, 0.05, 0.1, 0.8, 0.6, 0.4], "abs": [0.221, 0.057, 0.119, 0.73, 0.599, 0.383]})
sample_data = pd.DataFrame({'unknown': [0.490, 0.471, 0.484, 0.473, 0.479, 0.492]})
Now, create a CalibrationModel object and pass the predictor and response variables from our dataset as the x and y values respectively.
cal = CalibrationModel(x=test_data['concentration'], y=test_data['abs'])
When we call .fit_ols(), an ordinary least squares regression is fit to
the data and the slope, intercept and values are stored in the object
and can be retrieved by calling .slope
, .intercept
and .r_squared
respectively.
cal.fit_ols()
print(f"Slope: {cal.slope: .3f}" )
print(f"Intercept: {cal.intercept: .3f}" )
print(f"R2: {cal.r_squared: .3f}" )
Slope: 0.904
Intercept: 0.027
R2: 0.998
We can also call the method .linest_stats()
to return a series of
statistics you might expect when using the linest function in excel or
sheets.
cal.linest_stats()
Slope | Intercept | Uncertainty in slope | Uncertainty in intercept | Standard error of regression | F-statistic | Degrees of freedom | Regression sum of squares | Residual sum of squares | |
---|---|---|---|---|---|---|---|---|---|
0 | 0.904411 | 0.027419 | 0.0312 | 0.017178 | 0.020745 | 840.261133 | 4 | 0.361606 | 0.001721 |
Finally, we can calculate an inverse prediction from unknown data and retrieve the uncertainty but calling .inverse_prediction().
pred = cal.inverse_prediction(sample_data['unknown'])
print(pred)
0.5020733029033536 ± 0.031053583676141718
The uncertainty is calculated according to the following expression:
$$ U = {S_{\hat{x}}}_0 * T $$
Where if a single sample is provided:
$$ {S_{\hat{x}}}0 = \frac{S{y/x}}{b} \sqrt{\frac{1}{m} + \frac{1}{n}} $$
Or, if multiple replicate samples are provided:
$$ s_{\hat{x}0}=\frac{1}{b} \sqrt{\frac{s_r^2}{m}+\frac{s{y / x}^2}{n}+\frac{s_{y / x}^2\left(y_0-\bar{y}\right)^2}{b^2 \sum_{i=1}^n\left(x_i-\bar{x}\right)^2}} $$
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
Built Distribution
File details
Details for the file ChemCal-0.0.5.tar.gz
.
File metadata
- Download URL: ChemCal-0.0.5.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cd73faa40a93d82866410cbecef086f9c374eec988f24963d76bae3dba9d316 |
|
MD5 | 4bb3b74959090974823233c1d7f61508 |
|
BLAKE2b-256 | 7434916bf205a8bd030e3456906ea5da66ad7242e9ab5a291c92e69626695f5c |
File details
Details for the file ChemCal-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: ChemCal-0.0.5-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04a841e91ab96015a43208ad5f1cf29e858ce9a3632bd6fe038b066d3cb17f4c |
|
MD5 | 00b024c3ad598e3b7f3fd43e1793b223 |
|
BLAKE2b-256 | 2ef1e15a01ae787ac12931816bcf65231bd163cdf11af7564d53b4438175a56e |