<jupyter_start><jupyter_text>Intervalos de confiança<jupyter_code>import numpy as np
from scipy.stats import norm
from scipy import stats
import seaborn
# Rol
dados = np.array([
    126. , 129.5, 133. , 133. , 136.5, 136.5, 140. , 140. , 140. ,
    140. , 143.5, 143.5, 143.5, 143.5, 143.5, 143.5, 147. , 147. ,
    147. , 147. , 147. , 147. , 147. , 150.5, 150.5, 150.5, 150.5,
    150.5, 150.5, 150.5, 150.5, 154. , 154. , 154. , 154. , 154. ,
    154. , 154. , 154. , 154. , 157.5, 157.5, 157.5, 157.5, 157.5,
    157.5, 157.5, 157.5, 157.5, 157.5, 161. , 161. , 161. , 161. ,
    161. , 161. , 161. , 161. , 161. , 161. , 164.5, 164.5, 164.5,
    164.5, 164.5, 164.5, 164.5, 164.5, 164.5, 168. , 168. , 168. ,
    168. , 168. , 168. , 168. , 168. , 171.5, 171.5, 171.5, 171.5,
    171.5, 171.5, 171.5, 175. , 175. , 175. , 175. , 175. , 175. ,
    178.5, 178.5, 178.5, 178.5, 182. , 182. , 185.5, 185.5, 189. , 192.5
])
n = len(dados)
media = np.mean(dados)
desvio_padrao = np.std(dados)
n, media, desvio_padrao
# Confiança de 95%
alpha = 0.05/2
1-alpha
z = norm.ppf(1-alpha)
z
limite_inferior = media - z * (desvio_padrao/math.sqrt(n))
limite_superior = media + z * (desvio_padrao/math.sqrt(n))
limite_inferior, limite_superior
# Margem de erro
margem_erro = media-limite_inferior
margem_erro
sns.histplot(dados, kde=True)<jupyter_output><empty_output><jupyter_text>Scipy<jupyter_code># Calcular o erro padrão
stats.sem(dados), desvio_padrao/math.sqrt(n-1)
# Calcular os intervalos
intervalos = norm.interval(0.95, media, stats.sem(dados))
intervalos
# Margem de erro
margem_erro2 = media-intervalos[0]
margem_erro2
# Deininfo outros intervalos de confiança
intervalos1 = norm.interval(0.99, media, stats.sem(dados))
intervalos2 = norm.interval(0.80, media, stats.sem(dados))
intervalos1, intervalos2<jupyter_output><empty_output><jupyter_text>Exercício<jupyter_code>import numpy as np
from scipy.stats import norm
from scipy import stats
import seaborn as sns
import math
# Rol
salarios = np.array([
    82.1191, 72.8014, 79.1266, 71.3552, 59.192 , 79.1952, 56.518 ,
    70.3752, 73.5364, 61.0407, 64.3902, 66.4076, 63.5215, 71.9936,
    60.1489, 78.5932, 76.0459, 67.7726, 64.6149, 80.1948, 76.7998,
    76.1831, 80.7065, 62.4953, 57.204 , 62.5408, 80.0982, 63.287 ,
    66.5826, 79.3674
])
n = len(salarios)
media = np.mean(salarios)
desvio_padrao = np.std(salarios)
n, media, desvio_padrao
# Calcular o erro padrão
stats.sem(dados), desvio_padrao/math.sqrt(n-1)
# Calcular os intervalos
intervalos = norm.interval(0.95, media, stats.sem(dados))

# Margem de erro
margem_erro2 = media-intervalos[0]
intervalos, margem_erro2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16497557309282224, 'fraction_numerical': 0.20969560315670802, 'mean_word_length': 3.473949579831933, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '350716', 'license': 'MIT', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1196, 'n_words': 269, 'path': '8_intervalo_confianca/intervalo_confianca.ipynb', 'repo_name': 'AlissonRaphael/statistics_for_data_science_and_machine_learning', 'size': '2661'}