fork download
  1. import numpy as np
  2. import pandas as pd
  3. import scipy.stats as stats
  4.  
  5. # Set random seed so the results are exactly the same every time you run it
  6. np.random.seed(42)
  7.  
  8. # ==========================================
  9. # 1. GENERATE DATA (No external files needed)
  10. # ==========================================
  11. control_scores = np.random.normal(loc=70, scale=10, size=50)
  12. treatment_scores = np.random.normal(loc=76, scale=12, size=50)
  13.  
  14. df_groups = pd.DataFrame({
  15. 'Control': control_scores,
  16. 'Treatment': treatment_scores
  17. })
  18.  
  19. # ==========================================
  20. # 2. DESCRIPTIVE STATISTICS
  21. # ==========================================
  22. print("--- DESCRIPTIVE STATISTICS ---")
  23. print(df_groups.describe().round(2))
  24. print("\n")
  25.  
  26. # ==========================================
  27. # 3. INFERENTIAL STATISTICS (Independent T-Test)
  28. # ==========================================
  29. print("--- INFERENTIAL STATISTICS (T-Test) ---")
  30. t_stat, p_value = stats.ttest_ind(df_groups['Control'], df_groups['Treatment'])
  31.  
  32. # Replaced f-strings with .format() for Python 2.7 compatibility
  33. print("T-statistic: {:.4f}".format(t_stat))
  34. print("P-value: {:.4f}".format(p_value))
  35.  
  36. if p_value < 0.05:
  37. print("Conclusion: Reject the null hypothesis (Statistically significant).")
  38. else:
  39. print("Conclusion: Fail to reject the null hypothesis (No significant difference).")
  40. print("\n")
  41.  
  42. # ==========================================
  43. # 4. CORRELATION ANALYSIS
  44. # ==========================================
  45. print("--- CORRELATION ANALYSIS ---")
  46. hours_studied = np.random.uniform(low=1, high=10, size=100)
  47. final_scores = 50 + (3.5 * hours_studied) + np.random.normal(loc=0, scale=5, size=100)
  48.  
  49. corr_coeff, p_val_corr = stats.pearsonr(hours_studied, final_scores)
  50.  
  51. # Replaced f-strings with .format() for Python 2.7 compatibility
  52. print("Pearson Correlation Coefficient (r): {:.4f}".format(corr_coeff))
  53. print("P-value: {:.4e}".format(p_val_corr))
  54.  
  55. if corr_coeff > 0.7:
  56. print("Conclusion: Strong positive correlation.")
  57. elif corr_coeff > 0.3:
  58. print("Conclusion: Moderate positive correlation.")
  59. else:
  60. print("Conclusion: Weak or no correlation.")# your code goes here
Success #stdin #stdout 0.54s 84988KB
stdin
Standard input is empty
stdout
--- DESCRIPTIVE STATISTICS ---
       Control  Treatment
count    50.00      50.00
mean     67.75      76.21
std       9.34      10.49
min      50.40      44.56
25%      61.39      70.05
50%      67.66      76.55
75%      73.36      83.04
max      88.52      94.78


--- INFERENTIAL STATISTICS (T-Test) ---
T-statistic: -4.2634
P-value:     0.0000
Conclusion: Reject the null hypothesis (Statistically significant).


--- CORRELATION ANALYSIS ---
Pearson Correlation Coefficient (r): 0.8646
P-value: 4.6905e-31
Conclusion: Strong positive correlation.