Advertisement
KDOXG

l10

Nov 22nd, 2022 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.51 KB | None | 0 0
  1. from statistics import mean, variance, stdev
  2. from math import sqrt, prod
  3. # mean(list) = média simples
  4. # variance(list) = variância
  5. # stdev(list) = desvio padrão
  6.  
  7. # 1.
  8. # a.
  9. # 1021, 1016, 1012, 1011, 1014, 1018, 1022, 1027, 1008, 1015, 1013, 1013, 1017, 1019, 1007, 1003
  10. l = [1021, 1016, 1012, 1011, 1014, 1018, 1022, 1027, 1008, 1015, 1013, 1013, 1017, 1019, 1007, 1003]
  11. # Σx = sum(l) = 16236
  12. # n = len(l) = 16
  13. n = len(l)
  14.  
  15. # µ = 16236/16 = 1014.75 = mean(l)
  16. # σ² = 34.3125 = variance(l)
  17. # σ = sqrt(σ²) = 5.8577 = stdev(l)
  18.  
  19. """
  20. Z ~ N(0,1)
  21. Z = media(X) - µ / (σ/sqrt(n))
  22.  
  23. P(-z_a/2 < Z < z_a/2) = 1 - a
  24. P(-z_a/2 < media(X) - µ / (σ/sqrt(n)) < z_a/2) = 1 - a
  25. P((σ/sqrt(n)) * -z_a/2 < media(X) - µ < (σ/sqrt(n)) * z_a/2) = 1 - a
  26. P(- media(X) - z_a/2 * (σ/sqrt(n)) < -µ < - media(X) + z_a/2 * (σ/sqrt(n))) = 1 - a
  27. P(media(X) + (σ/sqrt(n)) * z_a/2 > µ > media(X) - (σ/sqrt(n)) * z_a/2) = 1 - a
  28. P(media(X) - (σ/sqrt(n)) * z_a/2 < µ < media(X) + (σ/sqrt(n)) * z_a/2) = 1 - a
  29.  
  30. IC(µ; 1-a): media(X) ± z_a/2 * σ/sqrt(n)
  31. """
  32. """
  33. t Student
  34. T = media(X) - µ / (s/sqrt(n))
  35.  
  36. P(media(X) - (s/sqrt(n)) * t_a/2 < µ < media(X) + (s/sqrt(n)) * t_a/2) = 1 - a
  37.  
  38. IC(θ; 1−a): media(X) ± t_a/2 * s/sqrt(n)
  39. onde s = desvio padrao da amostra
  40. """
  41.  
  42. a = 0.05
  43. # v = n-1 = 15
  44. v = n-1
  45. ## Da tabela normal:
  46. ## a/2 = 0.025
  47. ## Area entre 0 e z_a/2 = 0.5 - 0.025 = 0.475
  48. ##area_a = 0.5 - a/2
  49. ## quantil de z_a/2 (olhando pela tabela) = z_.975 = 1.96
  50. # limites de t_a/2 (olhando pela tabela) = t_.v(a)
  51. # t_.v005 = 2.132
  52. t_v005 = 2.132
  53.  
  54. # IC(µ; 0.95):
  55. IC1 = mean(l) + t_v005 * stdev(l) / sqrt(n)
  56. IC2 = mean(l) - t_v005 * stdev(l) / sqrt(n)
  57.  
  58. # b.
  59.  
  60. a2 = 0.01
  61. ## Da tabela normal:
  62. ## a/2 = 0.005
  63. ## Area entre 0 e z_a/2 = 0.5 - 0.005 = 0.495
  64. ##area_a2 = 0.5 - a2/2
  65. ## quantil de z_a/2 = z_.995 = 3.27
  66. # limites de t_a/2 = t_.v(a)
  67. # t_.v001_2 = 2.947
  68. t_v001 = 2.947
  69.  
  70. # IC(µ; 0.99):
  71. IC1b = mean(l) + t_v001 * stdev(l) / sqrt(len(l))
  72. IC2b = mean(l) - t_v001 * stdev(l) / sqrt(len(l))
  73.  
  74. print(IC1, IC2, IC1b, IC2b)
  75. # Intervalo normal:
  76. # 1017.620273 1011.879727 1019.53866975 1009.96133025
  77. # Intervalo Student:
  78. # 1017.872147 1011.627853 1019.06565109 1010.43434891
  79.  
  80. # 2.
  81. # 1011, 1015, 1017, 1015, 1021, 1021, 1010, 1007, 1022, 1018, 1016, 1015, 1020, 1022, 1025, 1030
  82.  
  83. l2 = [1011, 1015, 1017, 1015, 1021, 1021, 1010, 1007, 1022, 1018, 1016, 1015, 1020, 1022, 1025, 1030]
  84.  
  85. ns = [len(l), len(l2)]
  86. ls = [l, l2]
  87.  
  88. # Scombined = ( variance(l) * (len(l) - 1) + variance(l2) * (len(l2) - 1) ) / ( (len(l2) - 1) + (len(l) - 1) )
  89. Scombined = 0
  90. vcombined = 0
  91. for it in ls:
  92.     Scombined += variance(it) * (len(it) - 1)
  93.     vcombined += (len(it) - 1)
  94.  
  95. if vcombined != 0:
  96.     Scombined /= vcombined
  97.  
  98. # Sdiff = sqrt(Scombined * (1/len(l) + 1/len(l2))
  99. Sdiff = sqrt(Scombined * sum(ns) / prod(ns))
  100.  
  101. # print("v = ", vcombined)
  102. # v = 30
  103. t_vcombined005 = 2.042
  104.  
  105. # IC(µ₁-µ₂; 1-a): media(X₁) - media(X₂) ± t_a/2 * Sdiff
  106. ICdiff1 = mean(l) - mean(l2) + t_vcombined005 * Sdiff
  107. ICdiff2 = mean(l) - mean(l2) - t_vcombined005 * Sdiff
  108.  
  109. print(ICdiff1, ICdiff2)
  110. # 1.0954854815341086 -7.220485481534109
  111.  
  112. # Ao nivel de 95%, o intervalo da diferença contém o valor 0. Com isso, o volume médio fornecido pelas duas máquinas não diferem significativamente. Logo, pode-se afirmar que as máquinas fornecem o mesmo volume médio.
  113.  
  114. # 3.
  115. # As pressupções que devem ser válidas são, as variáveis terem distribuição normal, as variâncias das populações são iguais e as amostras retiradas são independentes.
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement