# ChemCal
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
## Install
``` sh
pip install ChemCal
```
## How to use
First we generate some data to work with.
``` python
# 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.
``` python
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.
``` python
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.
``` python
cal.linest_stats()
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| | 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 |
</div>
Finally, we can calculate an inverse prediction from unknown data and
retrieve the uncertainty but calling .inverse_prediction().
``` python
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}} $$
Raw data
{
"_id": null,
"home_page": "https://github.com/Rhys-McAlister/ChemCal",
"name": "ChemCal",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "nbdev jupyter notebook python",
"author": "Rhys McAlister",
"author_email": "mcalisterrhys@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/74/34/916bf205a8bd030e3456906ea5da66ad7242e9ab5a291c92e69626695f5c/ChemCal-0.0.5.tar.gz",
"platform": null,
"description": "# ChemCal\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n## Install\n\n``` sh\npip install ChemCal\n```\n\n## How to use\n\nFirst we generate some data to work with.\n\n``` python\n# generate training data and sample data\ntest_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]})\nsample_data = pd.DataFrame({'unknown': [0.490, 0.471, 0.484, 0.473, 0.479, 0.492]})\n```\n\nNow, create a CalibrationModel object and pass the predictor and\nresponse variables from our dataset as the x and y values respectively.\n\n``` python\ncal = CalibrationModel(x=test_data['concentration'], y=test_data['abs'])\n```\n\nWhen we call .fit_ols(), an ordinary least squares regression is fit to\nthe data and the slope, intercept and values are stored in the object\nand can be retrieved by calling `.slope`, `.intercept` and `.r_squared`\nrespectively.\n\n``` python\ncal.fit_ols()\n\nprint(f\"Slope: {cal.slope: .3f}\" )\nprint(f\"Intercept: {cal.intercept: .3f}\" )\nprint(f\"R2: {cal.r_squared: .3f}\" )\n```\n\n Slope: 0.904\n Intercept: 0.027\n R2: 0.998\n\nWe can also call the method `.linest_stats()` to return a series of\nstatistics you might expect when using the linest function in excel or\nsheets.\n\n``` python\ncal.linest_stats()\n```\n\n<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n .dataframe tbody tr th {\n vertical-align: top;\n }\n .dataframe thead th {\n text-align: right;\n }\n</style>\n\n| | 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 |\n|-----|----------|-----------|----------------------|--------------------------|------------------------------|-------------|--------------------|---------------------------|-------------------------|\n| 0 | 0.904411 | 0.027419 | 0.0312 | 0.017178 | 0.020745 | 840.261133 | 4 | 0.361606 | 0.001721 |\n\n</div>\n\nFinally, we can calculate an inverse prediction from unknown data and\nretrieve the uncertainty but calling .inverse_prediction().\n\n``` python\npred = cal.inverse_prediction(sample_data['unknown'])\nprint(pred)\n```\n\n 0.5020733029033536 \u00b1 0.031053583676141718\n\nThe uncertainty is calculated according to the following expression:\n\n$$ U = {S_{\\\\hat{x}}}_0 * T $$\n\nWhere if a single sample is provided:\n\n$$ {S_{\\hat{x}}}_0 = \\frac{S_{y/x}}{b} \\sqrt{\\frac{1}{m} + \\frac{1}{n}} $$\n\nOr, if multiple replicate samples are provided:\n\n$$ 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}} $$\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "A collection of functions that simplify the process of creating calibration curves.",
"version": "0.0.5",
"project_urls": {
"Homepage": "https://github.com/Rhys-McAlister/ChemCal"
},
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2ef1e15a01ae787ac12931816bcf65231bd163cdf11af7564d53b4438175a56e",
"md5": "00b024c3ad598e3b7f3fd43e1793b223",
"sha256": "04a841e91ab96015a43208ad5f1cf29e858ce9a3632bd6fe038b066d3cb17f4c"
},
"downloads": -1,
"filename": "ChemCal-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "00b024c3ad598e3b7f3fd43e1793b223",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9852,
"upload_time": "2023-06-29T00:48:40",
"upload_time_iso_8601": "2023-06-29T00:48:40.333360Z",
"url": "https://files.pythonhosted.org/packages/2e/f1/e15a01ae787ac12931816bcf65231bd163cdf11af7564d53b4438175a56e/ChemCal-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7434916bf205a8bd030e3456906ea5da66ad7242e9ab5a291c92e69626695f5c",
"md5": "4bb3b74959090974823233c1d7f61508",
"sha256": "1cd73faa40a93d82866410cbecef086f9c374eec988f24963d76bae3dba9d316"
},
"downloads": -1,
"filename": "ChemCal-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "4bb3b74959090974823233c1d7f61508",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 11887,
"upload_time": "2023-06-29T00:48:44",
"upload_time_iso_8601": "2023-06-29T00:48:44.002613Z",
"url": "https://files.pythonhosted.org/packages/74/34/916bf205a8bd030e3456906ea5da66ad7242e9ab5a291c92e69626695f5c/ChemCal-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-29 00:48:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Rhys-McAlister",
"github_project": "ChemCal",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "chemcal"
}