2024-06-07

Introduction to Statistical Hypothesis Testing

What is Hypothesis Testing?

Hypothesis Testing is a statistical method used to make decisions or inferences about population parameters based on sample data. It involves comparing a null hypothesis (\(H_0\)) with an alternative hypothesis (\(H_1\)).

Key Concepts:

Null Hypothesis \(H_0\): A statement of no effect or no difference, to be tested and possibly rejected.

Alternative Hypothesis \(H_1\): A statement that contradicts the null hypothesis, representing the effect or difference we expect.

Significance Level \(\alpha\): A threshold set by the researcher (commonly 0.05) to determine whether to reject the null hypothesis.

Question: I have long theorized that short movies are, on average, higher rated than feature length films. This may be due to short films requiring less “buy-in” from an audience in terms of their time, which causes people to be more generous with their ratings. However, I cannot prove short films are better rated on average. Even should I select a sample of short films and compare it with the mean of all movies, it may be the case that my sample is simply lucky or unlucky. How can I prove that luck is a non-factor when presenting my conclusions?

Our \(H_0\) is: “Short films are equally rated when compared to feature length films”

Our \(H_1\) is: “Short films are not equally rated when compared to feature length films”

The gameplan:

\(Z = {\bar{x} - \mu_0 \over \sigma / \sqrt{n}}\)

Where \(\bar{x} =\) the mean of our population data

\(\mu_0 =\) the mean of our sample data

\(\sigma\) = the standard deviation of our population data

\(n\) = the number of items in our sample

In this slide we can see that the distribution of movie ratings follows a normal distribution. The mean of the data is 5.93 and the standard deviation is 1.55

This slide is a graph of a random sample of 100 short films from the same data set. Our mean is 6.294.

\(Z = {\bar{x} - \mu_0 \over \sigma / \sqrt{n}}\)

Where

\(\bar{x} =\) 5.93

\(\mu_0 =\) 6.294

\(\sigma\) = 1.55

\(n\) = 100

\(Z =\) 2.3483871

Now that we have our \(Z\) value, let’s select an \(\alpha\).

Typically this number is 5%, or .05, if the \(Z\) value in our data exceeds the Z-score of our \(\alpha\) we can reject the null, The Z score of .05 is 1.645. Since our \(Z\) value (2.3483871) exceeds that of our \(\alpha\) we can reject the null hypothesis and conclude short movies are higher rated on average than feature films.

For fun, let’s visualize the average ratings of various movie ratings, budget and length.

For your convinience, the R code for this presentation is included in the following slides

library(tinytex)
library(plotly)
library(ggplot2)
library(dplyr)
library(ggplot2movies)

First Graph

g <-  ggplot(data = movies, aes(x = rating)) + geom_histogram(aes(y=after_stat(density)),binwidth = .2, color="black", fill="red") 
g=g + geom_vline(aes(xintercept=mean(rating)), color="blue", linetype="dashed")+annotate("text", x=5.6, y=.32, label=round(mean(movies$rating),digits=2), angle=90)
g+geom_density(alpha=0,lwd=1.2)

Second Graph

my_movies=sample_n(filter(movies, movies$Short=="1"), 100)
g <-  ggplot(data = my_movies, aes(x = rating)) + geom_histogram(aes(y=after_stat(density)),binwidth = .2, color="black", fill="red") 
g=g + geom_vline(aes(xintercept=mean(rating)), color="blue", linetype="dashed")+annotate("text", x=6.3, y=.32, label=round(mean(my_movies$rating),digits=2), angle=90)
g+geom_density(alpha=0,lwd=1.2)

shortmovies=count(my_movies)

Third Graph

my_movies=sample_n(filter(movies,length<200, budget>10000000, budget<100000000), 1000)
myX = my_movies$budget
myY = my_movies$length
myZ =my_movies$rating
plot_ly(x=myX, y=myY,z=myZ,
        type="scatter3d", mode="markers",color=myZ
        )