Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Hypothesis Testing Basics | Section
Applying Statistical Methods
Sección 1. Capítulo 5
single

single

bookHypothesis Testing Basics

Desliza para mostrar el menú

Hypothesis testing is a fundamental concept in statistics that allows you to make inferences about a population based on sample data. The process begins with formulating two competing statements: the null hypothesis (H0) and the alternative hypothesis (H1 or Ha). The null hypothesis usually states that there is no effect or no difference, while the alternative hypothesis represents what you aim to support – typically that there is a significant effect or difference.

The typical steps in hypothesis testing are as follows:

  1. State the null and alternative hypotheses;
  2. Choose a significance level (commonly denoted as alpha, such as 0.05);
  3. Select the appropriate statistical test based on your data and hypothesis;
  4. Calculate the test statistic and the corresponding p-value;
  5. Compare the p-value to the significance level to decide whether to reject or fail to reject the null hypothesis.

A p-value is the probability of obtaining a result at least as extreme as the one observed, assuming the null hypothesis is true. If the p-value is less than the chosen significance level (alpha), you reject the null hypothesis in favor of the alternative.

It is important to understand the two types of errors in hypothesis testing. A Type I error occurs when you reject the null hypothesis when it is actually true (a "false positive"). The probability of making a Type I error is the significance level (alpha). A Type II error occurs when you fail to reject the null hypothesis when the alternative hypothesis is true (a "false negative"). The probability of a Type II error is denoted by beta.

Selecting the right significance level depends on the context and consequences of making errors. Common choices are 0.05 or 0.01, but stricter or more lenient levels may be justified depending on the application.

12345678910111213141516171819202122
import numpy as np from scipy import stats # Suppose you have a sample of exam scores sample_scores = np.array([82, 85, 88, 90, 79, 93, 87, 84, 91, 89]) # You want to test if the average score is significantly different from 85 # Null hypothesis (H0): The population mean = 85 # Alternative hypothesis (H1): The population mean ≠ 85 # Perform a one-sample t-test t_statistic, p_value = stats.ttest_1samp(sample_scores, popmean=85) print("T-statistic:", t_statistic) print("P-value:", p_value) # Interpret the result at alpha = 0.05 alpha = 0.05 if p_value < alpha: print("Reject the null hypothesis: There is a significant difference from 85.") else: print("Fail to reject the null hypothesis: No significant difference from 85.")
copy
Tarea

Desliza para comenzar a programar

You will perform a hypothesis test on a sample dataset in the global scope to determine whether the sample mean is significantly different from a hypothesized population mean.

  • Use the scipy.stats.ttest_1samp function to compare the data array to the hypothesized mean (mu).
  • Assign the resulting t-statistic and p-value to the variables t_statistic and p_val, respectively.
  • Using an if/else statement, compare p_val to the significance level (alpha).
  • If p_val is strictly less than alpha, assign the string "Reject the null hypothesis" to the variable test_result.
  • Otherwise, assign the string "Fail to reject the null hypothesis" to the variable test_result.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 5
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt