{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Calculating Weighted Mean, Standard Deviation, $\\chi^2$ and $\\chi^2$-probability.\n", "\n", "### Authors: \n", "- Christian Michelsen (Niels Bohr Institute)\n", "- Troels C. Petersen (Niels Bohr Institute)\n", "\n", "### Date: \n", "- 11-11-2020 (latest update)\n", "\n", "***\n", "\n", "Very small notebook testing if your calculation of the weighted mean, the standard deviation, the $\\chi^2$-value and the $\\chi^2$-probability are correct. We use as example five measurements of a distance (too a hook!) with uncertainty. You should insert your own code in the cells below. If you can run the entire notebook without any (Assertion)errors, your code has passed!\n", "\n", "***\n", "\n", "First, we import the modules we want to use:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below we define the data for the measurements of the heights of the hook (in mm, though that is irrelavant here) and their estimated uncertainties:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "dhook = np.array([17.8, 18.1, 17.7, 17.7 ])\n", "err_dhook = np.array([0.5, 0.3, 0.5, 0.2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Testing the weighted mean calculation. This is where you should start pasting your code! " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "\n", "# Insert own code here to calculate the weighted mean, mean_weighted\n", "\n", "# mean_weighted = ...\n", "\n", "\n", "\n", "print(mean_weighted)\n", "assert np.isclose(mean_weighted, 17.80982367758186)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Testing the weighted error:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "\n", "# Insert own code here to calculate the weighted error, err_weighted\n", "\n", "\n", "# err_weighted = ...\n", "\n", "\n", "\n", "print(err_weighted)\n", "assert np.isclose(err_weighted, 0.15056568396854866)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Testing the $\\chi^2$-value:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "\n", "# Insert own code here to calculate the chi2 value, chi2\n", "\n", "\n", "#chi2 = ...\n", "\n", "\n", "\n", "print(chi2)\n", "assert np.isclose(chi2, 1.2857430730478727)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Testing the $\\chi^2$-probability:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "\n", "\n", "\n", "# Insert own code here to calculate the chi2 probability, chi2_prob\n", "\n", "\n", "#chi2_prob = ...\n", "\n", "\n", "\n", "print(chi2_prob)\n", "assert np.isclose(chi2_prob, 0.7325212770446814)" ] } ], "metadata": { "executable": "/usr/bin/env python2", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" }, "main_language": "python" }, "nbformat": 4, "nbformat_minor": 2 }