osaaso commited on
Commit
30be5e9
·
verified ·
1 Parent(s): 8d42ebc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -5
app.py CHANGED
@@ -20,8 +20,28 @@ def ui_student(g1, g2, alt):
20
  def ui_paired(g1, g2, alt):
21
  return mcp_tools.paired_t_test(g1, g2, alt)
22
 
23
- def ui_one_sample(g, mu, alt):
24
- return mcp_tools.one_sample_t_test(g, mu, alt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def ui_anova(groups):
27
  return mcp_tools.one_way_anova(groups)
@@ -175,7 +195,13 @@ with gr.Blocks(title="Stat3001 — Statistical Tests") as demo:
175
 
176
  g_os = gr.Textbox(label="Sample (comma-separated numbers)")
177
  mu_os = gr.Number(label="Population mean")
178
- alt_os = gr.Radio(["two-sided", "less", "greater"], value="two-sided", label="Alternative hypothesis")
 
 
 
 
 
 
179
  example_one_sample = "5,6,7,8,9"
180
  load_example_one = gr.Button("Load example")
181
  load_example_one.click(lambda: example_one_sample, None, [g_os])
@@ -183,8 +209,9 @@ with gr.Blocks(title="Stat3001 — Statistical Tests") as demo:
183
  out_os = gr.JSON(label="Results")
184
  download_os = gr.DownloadButton("Download results")
185
 
186
- run_os.click(ui_one_sample, inputs=[g_os, mu_os, alt_os], outputs=[out_os])
187
-
 
188
  run_os.click(
189
  lambda r: save_json_to_file(r, "one_sample_results.json"),
190
  inputs=[out_os],
 
20
  def ui_paired(g1, g2, alt):
21
  return mcp_tools.paired_t_test(g1, g2, alt)
22
 
23
+ #def ui_one_sample(g, mu, alt):
24
+ # return mcp_tools.one_sample_t_test(g, mu, alt)
25
+
26
+ def one_sample_t_test(g, population_mean, alternative):
27
+ import numpy as np
28
+ import pingouin as pg
29
+
30
+ g = np.array(g, dtype=float)
31
+ adjusted = g - population_mean
32
+
33
+ result = pg.ttest(adjusted, y=None, alternative=alternative)
34
+
35
+ return {
36
+ "T": float(result["T"].iloc[0]),
37
+ "dof": int(result["dof"].iloc[0]),
38
+ "alternative": alternative,
39
+ "p_val": float(result["p-val"].iloc[0]),
40
+ "CI95": [float(result["CI95%"].iloc[0][0]), float(result["CI95%"].iloc[0][1])],
41
+ "cohen_d": float(result["cohen-d"].iloc[0]),
42
+ "power": float(result["power"].iloc[0]),
43
+ "BF10": str(result["BF10"].iloc[0])
44
+ }
45
 
46
  def ui_anova(groups):
47
  return mcp_tools.one_way_anova(groups)
 
195
 
196
  g_os = gr.Textbox(label="Sample (comma-separated numbers)")
197
  mu_os = gr.Number(label="Population mean")
198
+ #alt_os = gr.Radio(["two-sided", "less", "greater"], value="two-sided", label="Alternative hypothesis")
199
+ alt_one = gr.Radio(
200
+ ["two-sided", "less", "greater"],
201
+ value="two-sided",
202
+ label="Alternative hypothesis"
203
+ )
204
+
205
  example_one_sample = "5,6,7,8,9"
206
  load_example_one = gr.Button("Load example")
207
  load_example_one.click(lambda: example_one_sample, None, [g_os])
 
209
  out_os = gr.JSON(label="Results")
210
  download_os = gr.DownloadButton("Download results")
211
 
212
+ #run_os.click(ui_one_sample, inputs=[g_os, mu_os, alt_os], outputs=[out_os])
213
+ run_one.click(ui_one_sample, inputs=[g_os, mu_os, alt_one], outputs=[out_os])
214
+
215
  run_os.click(
216
  lambda r: save_json_to_file(r, "one_sample_results.json"),
217
  inputs=[out_os],