Advertisement
Danila_lipatov

confidence interval

May 27th, 2023 (edited)
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. import numpy as np
  2. from scipy.stats import chi2
  3.  
  4. def confidence_interval_variance(data, confidence_level):
  5.     n = len(data)
  6.     dof = n - 1
  7.     alpha = 1 - confidence_level
  8.    
  9.     sample_variance = np.var(data, ddof=1)
  10.     lower_bound = (n - 1) * sample_variance / chi2.ppf(1 - alpha/2, dof)
  11.     upper_bound = (n - 1) * sample_variance / chi2.ppf(alpha/2, dof)
  12.    
  13.     return lower_bound, upper_bound
  14.  
  15. # Пример использования
  16. data = [2, 4, 6, 8, 10]  
  17. confidence_level = 0.95  
  18.  
  19. lower, upper = confidence_interval_variance(data, confidence_level)
  20. print(f"Доверительный интервал дисперсии: [{lower}, {upper}]")
  21.  
  22. from scipy.stats import f_oneway
  23.  
  24. def test_equal_variances(data1, data2):
  25.     statistic, p_value = f_oneway(data1, data2)
  26.     return statistic, p_value
  27.  
  28. # Пример использования
  29. data1 = [2, 4, 6, 8, 10]  
  30. data2 = [1, 3, 5, 7, 9]  
  31.  
  32. statistic, p_value = test_equal_variances(data1, data2)
  33. print(f"Статистика теста: {statistic}")
  34. print(f"p-значение: {p_value}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement