Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy.stats import norm, t\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import check_lab01 as p"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"plt.rcParams.update({'font.size': 18})\n",
"plt.rcParams['lines.linewidth'] = 3\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ME 3263 \n",
"## Lab #1 - Measurements of precision and accuracy of smartphone accelerometers \n",
"### How can you measure something?\n",
"\n",
"All measurements have traceable standards. There are seven base units in SI -\n",
"meter (length), second (time), Mole (amount of substance), Ampere (electric\n",
"current), Kelvin (temperature), Candela (Luminous intensity), and kilogram\n",
"(mass)[ [**1**](https://www.nist.gov/pml/weights-and-measures/metric-si/si-units) ]. SI derived units are units of measurement derived from the seven base units. They are either dimensionless or can be expressed as a product of one or more of the base units. Any measurement you make should have some method to check against a reference.\n",
"\n",
"In this lab, we will use different smartphones to measure acceleration due to gravity, g, (m/s$^{2}$). We will perform student's t-test to examine statistical equivalence of two phone measuremnets, and perform analysis to determine accuracy and precision of the measurements. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sources of measurement variations\n",
"\n",
"No measurement is exact. No surface is compeletely flat. Every measurement you\n",
"make has two types of uncertainties, *systematic* and *random*. *Systematic*\n",
"uncertainties come from faults in your assumptions or equipment.\n",
"\n",
"In theory, all uncertainies could be accounted for by factoring in all physics\n",
"in a problem e.g. Temperature-dependence, Coriolis effect, electrical\n",
"disturbances in your readings. In practice, the diminishing return on investment\n",
"prevents this practice. For something like measuring acceleration due to gravity,g, it is more than\n",
"sufficient to report the average and standard deviation. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, you will determine the probability that two groups of samples--e.g. group\n",
"A and group B--have the same average value. This process is called the Student\n",
"t-test[ [**2**](https://www.ruf.rice.edu/~bioslabs/tools/stats/ttest.html) ].The variable, \n",
"\n",
"$t=\\frac{|M_A-M_B|}{\\sqrt{ab}}$\n",
"\n",
"$a=\\frac{N_A+N_B}{N_A N_B}$\n",
"\n",
"$b=\\frac{(N_A-1)S_A^2+(N_B-1)S_B^2}{N_A+N_B-2}$\n",
"\n",
"is a function of the two group means, $M_A$\n",
"and $M_B$, two group deviations, $S_A$ and $S_B$, and number of samples per\n",
"group, $N_1$ and $N_2$. Calculate $t$ for groups A and B by filling in Table 2. \n",
"\n",
"**Table 2: Determining t for groups A and B**\n",
"\n",
"|Sample | A Length | $(L-M_A)^2$ | B Length | $(L-M_A)^2$|\n",
"| --- | --- | --- | --- | --- |\n",
"|1 | \n",
"|2 | \n",
"|3 | \n",
"|4 | \n",
"|5 | \n",
"|**sum** |\n",
"|$M$ and $S^2$ |$sum/N_A$ | $sum/(N_A-1)$|$sum/N_B$ | $sum/(N_B-1)$\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example calculations in Python\n",
"Let's consider two groups of samples A and B. Sample indicates measuremnts of a bar using caliper. Compare two saple sets A and B using t-statistics \n",
"\n",
"|group| sample 1|sample 2|sample 3|sample 4|sample 5|\n",
"|--- | --- | --- | --- | --- | --- |\n",
"|A|104.14 mm | 101.61 mm | 99.06 mm | 102.87 mm | 106.68 mm |\n",
"|B|104.12 mm | 101.63 mm | 97.79 mm | 101.58 mm | 104.17 mm |"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"example groups A and B have t=0.59\n"
]
}
],
"source": [
"A=np.array([104.14, 101.61 , 99.06, 102.87, 106.68])\n",
"B=np.array([104.12, 101.63 , 97.79, 101.58 , 104.17])\n",
"meanA=np.sum(A)/len(A)\n",
"meanB=np.sum(B)/len(B)\n",
"s2A=np.sum((A-meanA)**2)/(len(A)-1)\n",
"s2B=np.sum((B-meanB)**2)/(len(B)-1)\n",
"a=(len(A)+len(B))/(len(A)*len(B)*1.0)\n",
"b=((len(A)-1)*s2A+(len(B)-1)*s2B)/(len(A)+len(B)-2)\n",
"#tstat=(meanA-meanB)/np.sqrt(s2A/len(A)+s2B/len(B))\n",
"tstat=(meanA-meanB)/np.sqrt(a*b)\n",
"\n",
"print('example groups A and B have t=%1.2f'%tstat)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"df=8\n",
"| p=0.05 | p=0.025 | p=0.01 | p=0.005 |\n",
"| --- | --- | --- | --- |\n",
"| 2.31 | 2.75 | 3.36 | 3.83 |\n"
]
}
],
"source": [
"df=len(A)+len(B)-2\n",
"# Print out the table for df degrees of freedom (N1+N2-2)\n",
"print('df=%i'%df )\n",
"print('| p=0.05 | p=0.025 | p=0.01 | p=0.005 |')\n",
"print('| --- | --- | --- | --- |')\n",
"print(\"| %1.2f | %1.2f | %1.2f | %1.2f |\"%(t.interval(0.95, df)[1],\\\n",
" t.interval(0.975, df)[1],\\\n",
" t.interval(0.99, df)[1],\\\n",
" t.interval(0.995, df)[1]))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x7fc0280d3490>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZYAAAEWCAYAAABFSLFOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3de5hcVZnv8e8v93ALSAIkwSYgIBxgREgExIGEAR0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sR/rLeYca2l0t6RvAdcAfJc0g/aKcTLovsj3rXqU8QBo5dWaWiN4CFkTEf9X62coBVZ8AAAEwSURBVCqYBfybpOER8XKO7eYqm8rlUOCXOV9FWg/jKxZrWhHxBeBfSL/YzyCNappEuoo4owvtXg8cBawgPcfyNdIv97ZnXVaU1F1Eet5jMPAj0jMjx9Z67HZMJyWzju4n9QQHAC3UPnrOGkTbOH4z6yJJXwcuBPaLiPu7+diXkx5w/GDZ0N8eQ9LNpMQyOvyLp6k5sZhVSdIAYE1ErCkp2wR4FNgMGFH6XEo3xbQVacDCKRExrTuP3RmS9gQeBsZFxL1Fx2P15XssZtXbAbhD0g2kUWLDSV1s2wPHdndSAYg0T9iQ7j5uZ0WaNt9d772EE4tZ9V4D7ifNO7YV6eb9Y8DpEXFTkYGZ9QTuCjMzs1z50tTMzHLlxGJmZrlyYjEzs1w5sZiZWa6cWMzMLFf/H8u4VW6lmz5EAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Example : Plotting histogram\n",
"\n",
"plt.hist(A,np.linspace(97,105,5),histtype='step',label='A')\n",
"plt.hist(B,np.linspace(97,105,5),histtype='step',label='B')\n",
"plt.xlabel('length (mm)')\n",
"plt.ylabel('counts')\n",
"plt.legend()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 1\n",
"\n",
"Groups A and B have different measurements of the mean length. Is it statistically significant?"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Whoops, try again\n"
]
},
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Answer = 'maybe' # replace 1 with 'yes' or 0 'no'\n",
"p.check_p01(Answer)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 2\n",
"\n",
"Compare two groups of samples:\n",
"\n",
"|group| sample 1|sample 2|sample 3|sample 4|sample 5|\n",
"|-- | --- | --- | --- | --- | --- |\n",
"|A|103.5| 99.0| 104.5| 110.7| 98.4|\n",
"|B|108.8| 117.9| 113.8| 107.7| 112.7|\n",
"\n",
"Calculate the t-statistic and the t-value comparing the average of group A and group B. Is there a statisitically significant difference between the two sets of measurements?\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tstat=3\n"
]
}
],
"source": [
"A=np.array([103.5, 99.0, 104.5, 110.7, 98.4])\n",
"B=np.array([108.8, 117.9, 113.8, 107.7, 112.7])\n",
"meanA=np.sum(A)/len(A)\n",
"meanB=np.sum(B)/len(B)\n",
"s2A=np.sum((A-meanA)**2)/(len(A)-1)\n",
"s2B=np.sum((B-meanB)**2)/(len(B)-1)\n",
"a=(len(A)+len(B))/(len(A)*len(B)*1.0)\n",
"b=((len(A)-1)*s2A+(len(B)-1)*s2B)/(len(A)+len(B)-2)\n",
"\n",
"tstat=(meanB-meanA)/np.sqrt(a*b) # your work here\n",
"print('tstat=%i'%tstat )\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Whoops, try again\n"
]
},
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Leave this alone, execute to check the answer\n",
"degrees_of_freedom = len(A)+len(B)-2\n",
"tvar=t.interval(0.95,degrees_of_freedom)[1]\n",
"Answer = 'maybe' # = 'yes' or 'no'\n",
"p.check_p02(tstat,Answer)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Lab 01 Procedure - Measuring gravitational acceleration, g, with smartphones \n",
"\n",
"Smartphone accelerometers use [**Micro Electronics Mechanical Systems (MEMS)**](https://www.youtube.com/watch?v=T_iXLNkkjFo&list=LLaKRw5uXV1fO_c_jxFua8MA&index=2&t=184s) to measure the acceleration of the phone. In the current experiment, you will use smartphone to measure acceleration due to gravity. Real-time recording of data gives you multiple measurements of g which are different from exact value of [g at the surface of the Earth](https://physics.nist.gov/cuu/Constants/index.html) is $g=9.80665~ m/s^{2}$.. The difference can be attributed to _systematic_ and _random_ uncertainties. These uncertainties are introduced by factors such as flatness of the surface, environmental vibrations, and other factors. In this lab exercise, you will collect data for two different smartphones (preferably from different manufacturers) and perform statistical analysis to compare performance of two phones.\n",
"\n",
"- [Download the phyphox app from appstore : Android/ Appple](https://phyphox.org/download/)\n",
"\n",
"- Scan the QR code for Sensor Statistics experiment\n",
"<img src=\"./figures/sensor_statistics_QRcode.png\" alt=\"Drawing\" style=\"width: 150px;\"/>\n",
"- Run the timed experiment and export data for Phone 1, say Sample A\n",
"- Run the timed experiment and export data for Phone 2, say Sample B"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"./figures/android.png\" alt=\"Drawing\" style=\"width: 300px;\"/>\n",
"<center>Figure 1: Measurements of g from phone 1, (Sample A)</center>\n",
"<img src=\"./figures/iphone.png\" alt=\"Drawing\" style=\"width: 300px;\"/>\n",
"<center>Figure 2: Measurements of g from phone 2, (Sample B)</center>\n",
"\n",
"1. Assume accurate value of [g at the surface of the Earth](https://physics.nist.gov/cgi-bin/cuu/Value?gn|search_for=gravity) is $g=9.80665~ m/s^{2}$. Which phone yeilds more accurate measurements? Which phone is more precise?\n",
"\n",
"2. Choose 30 measurements from each data set for analysis. Explain if the sample of 30 measurements is statistically equivalent to the complete dataset, for both cases.\n",
"\n",
" You need to perform two individual one-sample t-tests [ [**3**](http://sites.utexas.edu/sos/guided/inferential/numeric/claim/one-sample-t) ] for A & B. Assume that the average for all of the measurements is the true mean of the data set. For example, to compare sample mean to population of set A, the t-statistics variable\n",
"\n",
" $t=\\frac{|M_A-\\mu_A|*\\sqrt{N_A}}{{S_A}}$\n",
"\n",
" is a function of the mean of the data set, $M_A$ , group standard deviation, $S_A$ , group population mean $\\mu_A$ and number of samples in the group, $N_A$=30. \n",
"\n",
"3. Perform t-test using equal-sized groups from the two data sets. Do the 2 phones provide stastistically equivalent measurements of g? _If there are differences are these __systematic__ or __random__?_ What is the resulting error?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing your data to Jupyter\n",
"\n",
"1. While you're in the Lab_01 folder, click the \"Upload\" button in the top right.\n",
"2. Choose your csv file from your cell phone data collection of your accelerometer\n",
"3. Click the blue \"Upload\" button next to the file. \n",
"4. In this folder, there is an example file called `google.csv`\n",
"5. In the next code cell, I load the `google.csv` file into a variable called `data`.\n",
"6. The `google.csv` file has a column for each x-, y-, and z-directions, so I'll load just the z-direction to measure $$g$$\n",
"7. Finally, I create a histogram of the accelerometer values"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = pd.read_csv('google.csv')\n",
"zacc = data['Acceleration z (m/s^2)'].values\n",
"\n",
"plt.hist(zacc,30)\n",
"plt.ylabel('number of measurements')\n",
"plt.xlabel('acceleration (m/s/s)');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Your Report \n",
"\n",
"Your report should include:\n",
"\n",
"1. Introduction\n",
"\n",
"2. Methods\n",
" \n",
"3. Results and Discussion\n",
"\n",
"4. Conclusion\n",
"\n",
"\n",
"\n",
"### References\n",
"1. [https://www.nist.gov/pml/weights-and-measures/metric-si/si-units](https://www.nist.gov/pml/weights-and-measures/metric-si/si-units)\n",
"\n",
"2. [Student\n",
"t-test](https://www.ruf.rice.edu/~bioslabs/tools/stats/ttest.html)\n",
"\n",
"3. [One-sample Student's\n",
"t-test](http://sites.utexas.edu/sos/guided/inferential/numeric/claim/one-sample-t/)\n",
"\n",
"4. [Layer, H. P. Length—Evolution from Measurement Standard to a Fundamental Constant](./museum-length.pdf)\n",
"\n",
"5. [Uncertainty\n",
"Notes](https://courses.washington.edu/phys431/uncertainty_notes.pdf)\n",
"\n",
"6. [A guide to smartphone sensors](https://spacemath.gsfc.nasa.gov/Sensor/SensorsBook.pdf)\n",
"\n",
"7. g at the surface of the earth, https://physics.nist.gov/cgi-bin/cuu/Value?gn|search_for=gravity (copy-paste the link in browser if click does not work ]\n"
]
}
],
"metadata": {
"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.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}