Average/Mean and Standard Deviation
Stephen Lukacs (2) iquanta.org/instruct/python
| .. .
List of Measurements: (separated by commas) Sig.Figs.:Data comes in many forms. Straight measurements that do not depend on another variable or control are one-dimensional (1D) data. The easiest manner to process a list of straight measurements is to calculate their average or mean. Their standard deviation is a measure of how precise or close the measurements are to each other, where the smaller the standard deviation, the better the precision. This page will compute the average and standard deviation for your list of data entered. The average and sample standard deviation are as follows, respectively,
$$\bar{x} = \frac{1}{N} \sum_{i=1}^{N} x_i$$ and $$s = \sqrt{ \frac{1}{N-1} \sum_{i=1}^{N}(x_i-\bar{x})^2 }$$
where N is the count or number of measurements and \(x_i\) is an individual measurement.
Measurements that are taken as a primary variable or control changes or is adjusted are two-dimensional (2D) data. Like, when the temperature changes over months or seasons. Or, when the pressure changes as the temperature is increases in a sealed test tube. These dependent (y) versus independent (x) meansurements are usually plotted in a 2D graph and if a trend is recognized, the data is fit to some sort of mathematical expression.
More complex relationships are plotted on contour, mesh, multidimensional plots, etc., kind of plots.
"""
reference: https://iquanta.org/instruct/python ::: Statistics 1: Average, Average/Mean and Standard Deviation ::: Stephen Lukacs, Ph.D. ©2021-12-12
"""
<page_scripts>
<style>
input[type="text"] { height: 40px; padding: 0px 4px; border-radius: 5px; }
input[type="text"][id="measurements"] { width: 603px; }
input[type="text"][id="sf"] { width: 42px; }
input[type="submit"] { height: 40px; padding: 6px 30px; border-radius: 10px; }
</style>
<script type="text/python">
import browser.timer
from browser import document
from browser.html import B, U, BR, DIV, P, SPAN, SUP
from datetime import datetime
from math import sqrt
from math import log10 as log, floor, ceil
def float_to_mantissa_exponential(f, sig_figs=None):
exponential = int(floor(log(abs(f)))) if (f != 0.) else 0
mantissa = f/(10**exponential)
if sig_figs:
return (mantissa, exponential, ('{:.'+str(sig_figs-1)+'f}x10<sup>{}</sup>').format(mantissa, exponential))
else:
return (mantissa, exponential)
def show_result(event):
btn = event.target
itime = datetime.now()
lst, sstr = [ ], document['measurements'].value.replace(' ', "")
for l in sstr.split(","):
try:
n = float(l)
except:
n = None
if (n is not None):
lst.append(n)
average = sum(lst)/len(lst)
stddev = sqrt(1/(len(lst)-1) * sum([(l-average)**2 for l in lst]))
sf = int(document['sf'].value)
a = float_to_mantissa_exponential(average, sf)
a = ('{:.'+str(sf-1)+'f}').format(average) if (-3 <= a[1] <= +3) else a[2]
s = float_to_mantissa_exponential(stddev, sf)
s = ('{:.'+str(sf-1)+'f}').format(stddev) if (-3 <= s[1] <= +3) else s[2]
document['results'].clear()
document['results'] <= B(f'average, x = {a}, sample standard deviation, s = {s}, and count, N = {len(lst)}, for the list: "{document["measurements"].value}".')
ftime = datetime.now()
document['time_span'].text = f"{(ftime - itime).total_seconds()}s"
return
def update_time():
now = datetime.now().strftime("%A, %B %d, %Y @ <b>%H:%M:%S</b>")
document['clock'].innerHTML = now
return now
#initialization...
print(f'Statistics 1: Average ___ iquanta.org/instruct/python ___ client-side sjlukacs implementation')
browser.timer.set_interval(update_time, 200)
document['return'].bind('click', show_result)
</script>
</page_scripts>
<header>
<h3 style="text-align:left;"><span id="clock"></span> | <span id="time_span"></span> .. .</h3>
List of Measurements: <input type="text" id="measurements" value="2.43, 1.23, 7.53, 5.39" /> (separated by commas)
Sig.Figs.: <input type="text" id="sf" value="5" />
<input type="submit" id="return" name="return" value="Refresh"/> <span id="msg"></span>
</header>
<body>
<span id="results"></span>
<p>Data comes in many forms. Straight measurements that do not depend on another variable or control are one-dimensional (1D) data. The easiest manner to process a list of straight measurements is to calculate their average or mean. Their standard deviation is a measure of how precise or close the measurements are to each other, where the smaller the standard deviation, the better the precision. This page will compute the average and standard deviation for your list of data entered. The average and sample standard deviation are as follows, respectively,</p>
<p>$$\bar{x} = \frac{1}{N} \sum_{i=1}^{N} x_i$$ and $$s = \sqrt{ \frac{1}{N-1} \sum_{i=1}^{N}(x_i-\bar{x})^2 }$$</p>
<p>where N is the count or number of measurements and \(x_i\) is an individual measurement.</p>
<p>Measurements that are taken as a primary variable or control changes or is adjusted are two-dimensional (2D) data. Like, when the temperature changes over months or seasons. Or, when the pressure changes as the temperature is increases in a sealed test tube. These dependent (y) versus independent (x) meansurements are usually plotted in a 2D graph and if a trend is recognized, the data is fit to some sort of mathematical expression.</p>
<p>More complex relationships are plotted on contour, mesh, multidimensional plots, etc., kind of plots.</p>
</body>