# Install and load tidyverse
if (!require("tidyverse"))
  install.packages("tidyverse")
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidyverse)

# Read the data
# NOTE: You may edit the URL to load a different dataset

mydata <- read.csv("https://raw.githubusercontent.com/drkblake/Data/main/WhiteBlackHispanic.csv")
head(mydata,10)
##    Minutes   Precinct
## 1      4.0 Precinct 8
## 2      7.5 Precinct 8
## 3     10.5 Precinct 8
## 4      3.0 Precinct 8
## 5     10.1 Precinct 8
## 6      9.3 Precinct 8
## 7      9.6 Precinct 8
## 8     15.0 Precinct 8
## 9      2.6 Precinct 8
## 10    15.8 Precinct 8
# Specify the DV and IV
# NOTE: You may edit the FGP and Team variable names
mydata$DV <- mydata$Minutes
mydata$IV <- mydata$Precinct

# Graph the group distributions and averages
averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Calculate and show the group counts, means, standard
# deviations, minimums, and maximums
group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE))
## # A tibble: 3 × 6
##   IV          count  mean    sd   min   max
##   <chr>       <int> <dbl> <dbl> <dbl> <dbl>
## 1 Precinct 18   149 13.7   4.47   0.7  23.4
## 2 Precinct 3    164 15.2   8.32  -4.7  36  
## 3 Precinct 8    132  9.15  4.48  -2.9  18.3
options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 49.407, num df = 2.00, denom df = 288.58, p-value <
## 0.00000000000000022
# If the ANOVA detects significant difference, run
# this post-hoc procedure to learn which
# group pairs differed significantly.

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                             diff        lwr       upr     p adj
## Precinct 3-Precinct 18  1.530009 -0.1137634  3.173781 0.0741826
## Precinct 8-Precinct 18 -4.535235 -6.2712665 -2.799203 0.0000000
## Precinct 8-Precinct 3  -6.065244 -7.7635718 -4.366916 0.0000000
# Install and load tidyverse
if (!require("tidyverse"))
  install.packages("tidyverse")
library(tidyverse)

# Read the data
# NOTE: You may edit the URL to load a different dataset
mydata <- read.csv("https://raw.githubusercontent.com/drkblake/Data/main/RichPoor.csv")

# Specify the DV and IV
# NOTE: You may edit the FGP and Team variable names
mydata$DV <- mydata$Minutes
mydata$IV <- mydata$Precinct

# Graph the group distributions and averages
averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Calculate and show the group counts, means, standard
# deviations, minimums, and maximums
group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE))
## # A tibble: 2 × 6
##   IV          count  mean    sd   min   max
##   <chr>       <int> <dbl> <dbl> <dbl> <dbl>
## 1 Precinct 12   159 14.3   7.05  -4.6  34.6
## 2 Precinct 8    132  9.15  4.48  -2.9  18.3
options(scipen = 999)
t.test(mydata$DV ~ mydata$IV,
       var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  mydata$DV by mydata$IV
## t = 7.5258, df = 271.55, p-value = 0.0000000000007732
## alternative hypothesis: true difference in means between group Precinct 12 and group Precinct 8 is not equal to 0
## 95 percent confidence interval:
##  3.787442 6.471049
## sample estimates:
## mean in group Precinct 12  mean in group Precinct 8 
##                  14.27925                   9.15000
# Install and load tidyverse
if (!require("tidyverse"))
  install.packages("tidyverse")
library(tidyverse)

# Read the data
# NOTE: You may edit the URL to load a different dataset

mydata <- read.csv("https://raw.githubusercontent.com/drkblake/Data/main/Weekly18and23.csv")
head(mydata,10)
##    Week Minutes_2018 Minutes_2023
## 1     1          9.8          6.2
## 2     2         -6.9         10.2
## 3     3          4.8         21.8
## 4     4         20.3         19.4
## 5     5         13.1         -1.6
## 6     6         11.4         20.2
## 7     7         16.0          4.0
## 8     8         10.0         16.6
## 9     9         11.0          6.0
## 10   10          6.5         18.2
# Specify the two variables involved
# NOTE: You may edit the FGPLastSeason and FGPThisSeason variable names
mydata$V1 <- mydata$Minutes_2018
mydata$V2 <- mydata$Minutes_2023

# Look at the distribution of the pair differences
mydata$PairDifferences <- mydata$V2 - mydata$V1

ggplot(mydata, aes(x = PairDifferences)) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(aes(xintercept = mean(PairDifferences)))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Get descriptive statistics for pair differences
mydata %>%
  select(PairDifferences) %>%
  summarise(
    count = n(),
    mean = mean(PairDifferences, na.rm = TRUE),
    sd = sd(PairDifferences, na.rm = TRUE),
    min = min(PairDifferences, na.rm = TRUE),
    max = max(PairDifferences, na.rm = TRUE))
##   count mean       sd   min  max
## 1    52 4.75 9.017206 -15.3 26.8
mydata %>%
  select(V1, V2) %>%
  summarise_all(list(Mean = mean, SD = sd))
##    V1_Mean  V2_Mean    V1_SD    V2_SD
## 1 8.763462 13.51346 5.951867 5.998203
options(scipen = 999)
t.test(mydata$V2, mydata$V1,
       paired = TRUE)
## 
##  Paired t-test
## 
## data:  mydata$V2 and mydata$V1
## t = 3.7986, df = 51, p-value = 0.0003888
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  2.239594 7.260406
## sample estimates:
## mean difference 
##            4.75