Null hypothesis 1: There is no significant difference in the distribution of human trafficking cases among the states. This implies that the occurrence of human trafficking cases is uniform across all states, with no state having a notably higher or lower prevalence. An alpha level of 0.05 is chosen for this hypothesis test, which is a common choice in statistical analyses. This signifies a 5% chance of rejecting the null hypothesis when it is actually true, providing a balance between making accurate conclusions and avoiding Type I errors. The power level is set at 0.80, indicating an 80% probability of detecting a true difference if one exists. This level is commonly chosen in research to strike a balance between sensitivity and practicality. The minimum effect size, in this case, could be set as a 10% difference in the average number of cases among states.

Null hypothesis 2: There is no significant difference in the distribution of human trafficking cases across states based on population group descriptions. This means that the composition of human trafficking cases across various population groups is consistent and does not vary significantly from different population groups. An alpha level of 0.05 is again chosen for this hypothesis test, maintaining consistency with the first hypothesis and ensuring a similar threshold for rejecting the null hypothesis. A power level of 0.80 is also used, indicating an 80% probability of detecting a true difference in case compositions among different population groups across states. The minimum effect size here could be defined as a 5% difference in the proportion of cases attributed to specific population groups. This smaller effect size is chosen due to the potentially nuanced differences in population group distributions, where even subtle variations could be of interest to researchers, policymakers, or social advocates.

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.2.3
library(ggrepel)
library(effsize)
## Warning: package 'effsize' was built under R version 4.2.3
library(pwrss)
## Warning: package 'pwrss' was built under R version 4.2.3
## 
## Attaching package: 'pwrss'
## 
## The following object is masked from 'package:stats':
## 
##     power.t.test
htd <- read.csv("C:\\Users\\moore\\OneDrive\\Desktop\\Fall 2023\\Intro to statistics\\project\\Statistics Project\\Statistics Project\\htd.csv")
state_count <- htd |>
  group_by(STATE_ABBR) |>
  summarise(total_count_cases = sum(count_of_cases_per_state)) |>
  arrange(STATE_ABBR)
state_count
## # A tibble: 50 × 2
##    STATE_ABBR total_count_cases
##    <chr>                  <int>
##  1 AK                       225
##  2 AL                       144
##  3 AR                       324
##  4 AZ                      1764
##  5 CO                     12321
##  6 CT                      2116
##  7 DE                       576
##  8 FL                     27556
##  9 FS                         9
## 10 GA                     18769
## # … with 40 more rows
observed_diff <- (state_count$total_count_cases[2] -
                  state_count$total_count_cases[1])
paste("Observed Difference: ", observed_diff)
## [1] "Observed Difference:  -81"
bootstrap <- function (x, func=mean, n_iter=10^4) {
  # empty vector to be filled with values from each iteration
  func_values <- c(NULL)
  
  # we simulate sampling `n_iter` times
  for (i in 1:n_iter) {
    # pull the sample (e.g., a vector or data frame)
    x_sample <- sample_n(x, size = length(x), replace = TRUE)
    
    # add on this iteration's value to the collection
    func_values <- c(func_values, func(x_sample))
  }
  
  return(func_values)
}
diff_in_avg <- function (x_data) {
  state_count <- x_data |>
    group_by(STATE_ABBR) |>
    summarise(total_count_cases = sum(count_of_cases_per_state)) |>
    arrange(STATE_ABBR)
  
  # difference = revenue_with - revenue_without
  diff <- (state_count$total_count_cases[2] -
           state_count$total_count_cases[1])
  
  return(diff)
}

diffs_in_avgs <- bootstrap(htd, diff_in_avg, n_iter = 100)
ggplot() +
  geom_function(xlim = c(min(diffs_in_avgs) - 50, max(diffs_in_avgs) + 50), 
                fun = function(x) dnorm(x, mean = mean(diffs_in_avgs), 
                                        sd = sd(diffs_in_avgs))) +
  geom_vline(mapping = aes(xintercept = observed_diff,
                           color = paste("observed: ", round(observed_diff)))) +
  labs(title = "Bootstrapped Sampling Distribution of Count Differences",
       x = "Difference in Counts Calculated",
       y = "Probability Density",
       color = "") +
  scale_x_continuous(breaks = seq(min(diffs_in_avgs), max(diffs_in_avgs), 100)) +
  theme_minimal()

This distribution visualization shows that on average the next state has 90 fewer counts which also rejects the null hypothesis. The probability density displays that there is a 0.0015 likelihood of obsrving a difference in counts around -90 on the bootstrapped samples.

chisq.test(state_count$total_count_cases)
## 
##  Chi-squared test for given probabilities
## 
## data:  state_count$total_count_cases
## X-squared = 5389996, df = 49, p-value < 2.2e-16

the p-value suggests that the observed differences in case counts among states are so significant that the probability of observing such differences (or more extreme differences) purely by chance, assuming no real effect (null hypothesis), is practically zero.

threshold <- median(state_count$total_count_cases)

# Categorize states as larger or smaller based on the threshold
larger_states <- state_count$total_count_cases > threshold
smaller_states <- state_count$total_count_cases <= threshold

# Create a 2x2 contingency table
contingency_table <- matrix(c(sum(larger_states), sum(smaller_states),
                              sum(larger_states == FALSE), sum(smaller_states == FALSE)),
                            nrow = 2, byrow = TRUE)
fisher.test(contingency_table)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  contingency_table
## p-value = 1
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##  0.4245475 2.3554488
## sample estimates:
## odds ratio 
##          1

Given the high p-value of 1, I fail to reject the null hypothesis. This means there is no statistically significant difference in human trafficking case counts between states defined as larger and smaller based on your chosen threshold (median count). The data does not provide sufficient evidence to support the claim that there is a difference in human trafficking case counts between these groups.

total_pop_count <- htd |>
  group_by(POPULATION_GROUP_DESC) |>
  summarise(total_count_per_pop = sum(count_of_cases_per_group)) |>
  arrange(POPULATION_GROUP_DESC)
observed_diff_pop <- (total_pop_count$total_count_per_pop[2] -
                  total_pop_count$total_count_per_pop[1])
paste("Observed Difference: ", observed_diff_pop)
## [1] "Observed Difference:  5920"
diff_in_pop <- function (x_data) {
  total_pop_count <- x_data |>
    group_by(POPULATION_GROUP_DESC) |>
    summarise(total_count_per_pop = sum(count_of_cases_per_group)) |>
    arrange(POPULATION_GROUP_DESC)
  
  # difference = revenue_with - revenue_without
  diff <- (total_pop_count$total_count_per_pop[2] -
           total_pop_count$total_count_per_pop[1])
  
  return(diff)
}

diffs_in_pops <- bootstrap(htd, diff_in_pop, n_iter = 100)
ggplot(data = data.frame(diffs_in_pops)) +
  geom_histogram(aes(x = diffs_in_pops), 
                 bins = 30, 
                 fill = "skyblue", 
                 color = "black",
                 alpha = 0.7) +
  geom_vline(mapping = aes(xintercept = observed_diff_pop,
                           color = paste("observed: ", round(observed_diff_pop))), 
             linetype = "dashed") +
  labs(title = "Bootstrapped Sampling Distribution of Count Differences",
       x = "Difference in Counts Calculated",
       y = "Frequency",
       color = "") +
  scale_x_continuous(breaks = seq(min(diffs_in_pops), max(diffs_in_pops), 100)) +
  theme_minimal()

chisq.test(total_pop_count$total_count_per_pop)
## 
##  Chi-squared test for given probabilities
## 
## data:  total_pop_count$total_count_per_pop
## X-squared = 1103944, df = 19, p-value < 2.2e-16
cities <- total_pop_count$total_count_per_pop[2:10]
msa_counties <- total_pop_count$total_count_per_pop[11:15]
contingency_table <- matrix(c(sum(cities), sum(msa_counties),
                              length(cities), length(msa_counties)),
                            nrow = 2, byrow = TRUE)
fisher.test(contingency_table)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  contingency_table
## p-value = 0.2102
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##  0.5141256 6.4895824
## sample estimates:
## odds ratio 
##   1.953004

This fishers test was to conduct an experiment on null hypothesis 2 that there is no signifcant difference among different population groups. Based on the test we fail to reject the null hypothesis and there is no significant evidence to indicate there is signifcant difference in human trafficking cases and population group counts between MSA counties and cities.