Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from statistics import mean, variance, stdev
- from math import sqrt, prod
- # mean(list) = média simples
- # variance(list) = variância
- # stdev(list) = desvio padrão
- # 1.
- # a.
- # 1021, 1016, 1012, 1011, 1014, 1018, 1022, 1027, 1008, 1015, 1013, 1013, 1017, 1019, 1007, 1003
- l = [1021, 1016, 1012, 1011, 1014, 1018, 1022, 1027, 1008, 1015, 1013, 1013, 1017, 1019, 1007, 1003]
- # Σx = sum(l) = 16236
- # n = len(l) = 16
- n = len(l)
- # µ = 16236/16 = 1014.75 = mean(l)
- # σ² = 34.3125 = variance(l)
- # σ = sqrt(σ²) = 5.8577 = stdev(l)
- """
- Z ~ N(0,1)
- Z = media(X) - µ / (σ/sqrt(n))
- P(-z_a/2 < Z < z_a/2) = 1 - a
- P(-z_a/2 < media(X) - µ / (σ/sqrt(n)) < z_a/2) = 1 - a
- P((σ/sqrt(n)) * -z_a/2 < media(X) - µ < (σ/sqrt(n)) * z_a/2) = 1 - a
- P(- media(X) - z_a/2 * (σ/sqrt(n)) < -µ < - media(X) + z_a/2 * (σ/sqrt(n))) = 1 - a
- P(media(X) + (σ/sqrt(n)) * z_a/2 > µ > media(X) - (σ/sqrt(n)) * z_a/2) = 1 - a
- P(media(X) - (σ/sqrt(n)) * z_a/2 < µ < media(X) + (σ/sqrt(n)) * z_a/2) = 1 - a
- IC(µ; 1-a): media(X) ± z_a/2 * σ/sqrt(n)
- """
- """
- t Student
- T = media(X) - µ / (s/sqrt(n))
- P(media(X) - (s/sqrt(n)) * t_a/2 < µ < media(X) + (s/sqrt(n)) * t_a/2) = 1 - a
- IC(θ; 1−a): media(X) ± t_a/2 * s/sqrt(n)
- onde s = desvio padrao da amostra
- """
- a = 0.05
- # v = n-1 = 15
- v = n-1
- ## Da tabela normal:
- ## a/2 = 0.025
- ## Area entre 0 e z_a/2 = 0.5 - 0.025 = 0.475
- ##area_a = 0.5 - a/2
- ## quantil de z_a/2 (olhando pela tabela) = z_.975 = 1.96
- # limites de t_a/2 (olhando pela tabela) = t_.v(a)
- # t_.v005 = 2.132
- t_v005 = 2.132
- # IC(µ; 0.95):
- IC1 = mean(l) + t_v005 * stdev(l) / sqrt(n)
- IC2 = mean(l) - t_v005 * stdev(l) / sqrt(n)
- # b.
- a2 = 0.01
- ## Da tabela normal:
- ## a/2 = 0.005
- ## Area entre 0 e z_a/2 = 0.5 - 0.005 = 0.495
- ##area_a2 = 0.5 - a2/2
- ## quantil de z_a/2 = z_.995 = 3.27
- # limites de t_a/2 = t_.v(a)
- # t_.v001_2 = 2.947
- t_v001 = 2.947
- # IC(µ; 0.99):
- IC1b = mean(l) + t_v001 * stdev(l) / sqrt(len(l))
- IC2b = mean(l) - t_v001 * stdev(l) / sqrt(len(l))
- print(IC1, IC2, IC1b, IC2b)
- # Intervalo normal:
- # 1017.620273 1011.879727 1019.53866975 1009.96133025
- # Intervalo Student:
- # 1017.872147 1011.627853 1019.06565109 1010.43434891
- # 2.
- # 1011, 1015, 1017, 1015, 1021, 1021, 1010, 1007, 1022, 1018, 1016, 1015, 1020, 1022, 1025, 1030
- l2 = [1011, 1015, 1017, 1015, 1021, 1021, 1010, 1007, 1022, 1018, 1016, 1015, 1020, 1022, 1025, 1030]
- ns = [len(l), len(l2)]
- ls = [l, l2]
- # Scombined = ( variance(l) * (len(l) - 1) + variance(l2) * (len(l2) - 1) ) / ( (len(l2) - 1) + (len(l) - 1) )
- Scombined = 0
- vcombined = 0
- for it in ls:
- Scombined += variance(it) * (len(it) - 1)
- vcombined += (len(it) - 1)
- if vcombined != 0:
- Scombined /= vcombined
- # Sdiff = sqrt(Scombined * (1/len(l) + 1/len(l2))
- Sdiff = sqrt(Scombined * sum(ns) / prod(ns))
- # print("v = ", vcombined)
- # v = 30
- t_vcombined005 = 2.042
- # IC(µ₁-µ₂; 1-a): media(X₁) - media(X₂) ± t_a/2 * Sdiff
- ICdiff1 = mean(l) - mean(l2) + t_vcombined005 * Sdiff
- ICdiff2 = mean(l) - mean(l2) - t_vcombined005 * Sdiff
- print(ICdiff1, ICdiff2)
- # 1.0954854815341086 -7.220485481534109
- # 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.
- # 3.
- # 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement