Accept or Reject an Experiment?

Stephen Lukacs (2) iquanta.org/instruct/python
Enter the dataset to be tested below...

What is the accepted or true value?


, or, just Upload to run the demonstration.

Understanding Student's t Test

The Student's t test was first proposed by William Sealy Gosse, a.k.a., Student, in 1908. He proposed that any one-dimensional set of measurements can be compared to an accepted or true set of measurements based on their statistical closeness. The Student's t test uses statistical analysis to determine if the current experimental measurements match up with the previously accepted or true experimental measurement. If accepted, then the experiment shows no bias and is thus comparable and valid to the previous experiments. If rejected, then the experiment is not comparable and should be redesigned, rerun, or disregarded altogether.

It is a three step process. First, calculate the Student's t value using the equation: $$t = \frac{\mid accepted - \bar{x} \mid}{ \sigma/\sqrt{n} }$$ where the accepted is the previously accepted or true measurements to be tested against, \(\bar{x}\), \(\sigma\), and n are the average or mean, the standard deviation, and the count of the dataset, respectively, being compared and tested.

Second, look up the Student's critical value for the count of datapoints, n, and the confidence or certainty level, CL, required in the below table. And finally, third, if the above t value is less than or equal to the critical value, then the datapoint must be accepted, in which the experiment at that confidence show no bias and its result is not significantly different than the accepted or true value. If the t value is greater than the critical value, then you should reject and disregard the experiment, that bias is detected, and the results of the experiment are significantly different from the accepted or true experiment.

. .. Student's Critical Values .. .

n50%CL80%CL90%CL95%CL98%CL99%CL99.5%CL99.9%CL
21.000003.077686.3137512.7062031.8205263.65674127.32134636.61925
30.816501.885622.919994.302656.964569.9248414.0890531.59905
40.764891.637742.353363.182454.540705.840917.4533212.92398
50.740701.533212.131852.776453.746954.604095.597578.61030
60.726691.475882.015052.570583.364934.032144.773346.86883
70.717561.439761.943182.446913.142673.707434.316835.95882
80.711141.414921.894582.364622.997953.499484.029345.40788
90.706391.396821.859552.306002.896463.355393.832525.04131
100.702721.383031.833112.262162.821443.249843.689664.78091
110.699811.372181.812462.228142.763773.169273.581414.58689
120.697451.363431.795882.200992.718083.105813.496614.43698
130.695481.356221.782292.178812.681003.054543.428444.31779
140.693831.350171.770932.160372.650313.012283.372474.22083
150.692421.345031.761312.144792.624492.976843.325704.14045
160.691201.340611.753052.131452.602482.946713.286044.07277
170.690131.336761.745882.119912.583492.920783.251994.01500
180.689201.333381.739612.109822.566932.898233.222453.96513
190.688361.330391.734062.100922.552382.878443.196573.92165
200.687621.327731.729132.093022.539482.860933.173723.88341
210.686951.325341.724722.085962.527982.845343.153403.84952
220.686351.323191.720742.079612.517652.831363.135213.81928
230.685811.321241.717142.073872.508322.818763.118823.79213
240.685311.319461.713872.068662.499872.807343.104003.76763
250.684851.317841.710882.063902.492162.796943.090513.74540
lecture by Stephen Lukacs, Ph.D., ©2011 - 2023; updated: March 7, 2023. all data confirmed via lecture_data_analysis.nb.
"""
reference: https://iquanta.org/instruct/python ::: Statistics 4: Student's t Test ::: Stephen Lukacs, Ph.D. ©2023-02-14
"""
from py4web import URL, request
from yatl.helpers import *
from iquanta.mcp import is_str_float, str_to_float
from iquanta.chmpy import Ttest, students

BR, B = TAG['br/'], TAG['b']
#demo_data = "0.1190\n0.09847\n0.09852"
#demo_accepted = "0.1"
demo_data = "6.18\n6.28\n4.85\n6.49"
demo_accepted = "4.85"

rtn = FORM(_action=None, _method="post")
if ('txtfile' in request.forms):
    txt, data = request.forms['txtfile'], [ ]
    for l in txt.strip().split('\n'):
        if is_str_float(l.strip()):
           data.append(str_to_float(l.strip()))
    #rtn.append(CAT(data, BR()))
if ('accepted' in request.forms):
    if is_str_float(request.forms['accepted']):
        accepted = str_to_float(accepted)

rtn.append(STYLE("input[type=text] { width: 70px; text-align: center; border-radius: 7px; } textarea { margin: 0px; width: 295px; height: 200px; border-radius: 5px; } p { margin: 2px 0px; padding: 8px; border-radius: 10px; border: 2px solid silver; }"))
rtn.append(CAT(DIV("Enter the dataset to be tested below...", BR(), TEXTAREA(txtfile if ('txtfile' in locals()) else demo_data, _name="txtfile"), _style="float:left;"), DIV(BR(), "What is the accepted or true value?", BR(), INPUT(_type="text", _name="accepted", _value=accepted if ('accepted' in locals()) else demo_accepted, _style="width: 130px;"), *[BR()]*2, INPUT(_type="submit", _value="Upload"), ", or, just Upload to run the demonstration.", _style="float:left; margin: 5px;"), DIV(_style="float:none;clear:both;")))

if ('data' in locals()) and ('accepted' in locals()):
    CIs = (50, 80, 90, 95, 99, 99.5, 99.9,)
    Ttests = [ Ttest(data, accepted, ci) for ci in CIs ]
    t = Ttests[0]
    p = P()
    #p.append(CAT(str(t), BR()))
    p.append(CAT(B(XML(f'With x&#772; = {t[1]:.4g} and &sigma; = {t[2]:.4g}, the dataset can be rejected '), BR(), f'unless you want to be {"only" if (t[4] < 50.) else "at least"} {t[4]:.2f}%, or higher, confident in its acceptance, or:', BR(), _style="font-size:18pt; font-weight:bold;")))
    for i, (ci, t) in enumerate(zip(CIs, Ttests), 1):
        #p.append(CAT(XML(t), BR()*2,))
        if t[7]:
            p.append(SPAN(XML(f'<b>at {ci}% confidence</b> the dataset <b>must be accepted</b>, bias not detected, and results comparable to the accepted.<br/>'), _style="font-size:14pt;"))
        else:
            p.append(SPAN(XML(f'<b>at {ci}% confidence</b> the dataset <b>should be rejected</b>, bias detected, and results significantly different than the accepted.<br/>'), _style="font-size:14pt;"))
    rtn.append(p)
dv = DIV(H3("Understanding Student's t Test"), "The Student's t test was first proposed by William Sealy Gosse, a.k.a., Student, in 1908.  He proposed that any one-dimensional set of measurements can be compared to an accepted or true set of measurements based on their statistical closeness.  The Student's t test uses statistical analysis to determine if the current experimental measurements match up with the previously accepted or true experimental measurement.  If accepted, then the experiment shows no bias and is thus comparable and valid to the previous experiments.  If rejected, then the experiment is not comparable and should be redesigned, rerun, or disregarded altogether.", *[BR()]*2, r"It is a three step process.  First, calculate the Student's t value using the equation: $$t = \frac{\mid accepted - \bar{x} \mid}{ \sigma/\sqrt{n} }$$ where the accepted is the previously accepted or true measurements to be tested against, \(\bar{x}\), \(\sigma\), and n are the average or mean, the standard deviation, and the count of the dataset, respectively, being compared and tested.", *[BR()]*2, "Second, look up the Student's critical value for the count of datapoints, n, and the confidence or certainty level, CL, required in the below table.  And finally, third, if the above t value is less than or equal to the critical value, then the datapoint must be accepted, in which the experiment at that confidence show no bias and its result is not significantly different than the accepted or true value.  If the t value is greater than the critical value, then you should reject and disregard the experiment, that bias is detected, and the results of the experiment are significantly different from the accepted or true experiment.", *[BR()]*2, _style="")
s = students()
st = s.find('table#students')[0]
st['_style'] = "margin: auto;"
dv.append(CAT(s.find('style')[0], H4(". .. Student's Critical Values .. ."), st))
dv.append(CAT("lecture by Stephen Lukacs, Ph.D., ©2011 - 2023; updated: March 7, 2023.  all data confirmed via ", A("lecture_data_analysis.nb", _href=URL('static', "pdf/lecture_data_analysis8.pdf"), _target="data_analysis"), "."))
rtn.append(dv)