2024-06-02

title: “Hypothesis Testing” output: ioslides_presentation

Introduction

Hypothesis testing is a statistical method used to make inferences about population parameters based on sample data. It involves making a hypothesis about the population parameter, collecting sample data, and then using statistical tests to determine the likelihood of the observed results given the hypothesis.

Example

Suppose we want to test whether the mean weight of apples in a certain orchard is different from 150 grams. We collect a random sample of apples from the orchard and measure their weights. Our null hypothesis is that the mean weight of apples in the orchard is 150 grams, while the alternative hypothesis is that it is different from 150 grams. Hypothesis Formulation

Null Hypothesis (H0): The mean weight of apples in the orchard is 150 grams. Alternative Hypothesis (H1): The mean weight of apples in the orchard is different from 150 grams.

T-test

# Generate sample data (weights of apples)
set.seed(123)
apple_weights <- rnorm(50, mean = 155, sd = 10)

# Perform t-test
t_test_result <- t.test(apple_weights, mu = 150)

# Print the result
t_test_result
## 
##  One Sample t-test
## 
## data:  apple_weights
## t = 4.0814, df = 49, p-value = 0.0001646
## alternative hypothesis: true mean is not equal to 150
## 95 percent confidence interval:
##  152.7127 157.9753
## sample estimates:
## mean of x 
##   155.344

Conclusion

Based on the results of the t-test, we can determine whether to reject or fail to reject the null hypothesis. If the p-value is less than the significance level (e.g., 0.05), we reject the null hypothesis and conclude that there is sufficient evidence to suggest that the mean weight of apples in the orchard is different from 150 grams. Otherwise, we fail to reject the null hypothesis.

3D scatterplot plotly

# Generate data for a 3D scatter plot
x <- rnorm(100)
y <- rnorm(100)
z <- rnorm(100)

# Create a 3D scatter plot
plot_ly(x = x, y = y, z = z, type = "scatter3d", mode = "markers")

ScatterPlot ggplot

# Generate data for a ggplot scatter plot
data <- data.frame(x = rnorm(100), y = rnorm(100))

# Create a ggplot scatter plot
ggplot(data, aes(x = x, y = y)) + 
  geom_point() + 
  labs(title = "Scatter Plot", x = "X-axis", y = "Y-axis")

Histogram ggplot

# Generate data for a ggplot histogram
data <- data.frame(values = rnorm(100))

# Create a ggplot histogram
ggplot(data, aes(x = values)) + 
  geom_histogram(binwidth = 0.5, fill = "blue", color = "black") + 
  labs(title = "Histogram", x = "Values", y = "Frequency")

References