Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Hypothesis Testing Basics | Section
Applying Statistical Methods
Avsnitt 1. Kapitel 5
single

single

bookHypothesis Testing Basics

Svep för att visa menyn

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
Uppgift

Svep för att börja koda

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.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 5
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt