flick <- read.delim('https://raw.githubusercontent.com/IowaBiostat/data-sets/main/flicker/flicker.txt')

model1 <- lm(flick$Flicker ~ flick$Color)
anova(model1)

model1 <- lm(flick$Flicker ~ flick$Color) # Full model
model0 <- lm(flick$Flicker ~ 1) # Model with just the intercept (reduced model)

RSS_1 <- sum(model1$residuals^2)
RSS_0 <- sum(model0$residuals^2)

# formula used in class to find explained variability: 
(RSS_0-RSS_1)/RSS_0

summary(model1)

boxplot(flick$Flicker~flick$Color, col=c("blue", "brown", "green"),
                                         xlab = "Eye Color",
                                         ylab = "Flicker Frequency")

fit <- aov(flick$Flicker~flick$Color)

TukeyHSD(fit)

pairwise.t.test(flick$Flicker, flick$Color, p.adj = "bonf")

pairwise.t.test(flick$Flicker, flick$Color, p.adj = "none")

table<- rbind(c(17,130), c(218,428))

colnames(table)<- c("Y", "N")

rownames(table)<- c("Helmet", "No Helmet")

print(table)

log(3.89) + c(1.96, -1.96) * sqrt(1/130+1/428+1/17+1/218)

exp(c(0.8272548, 1.8895635)) 

table2<- rbind(c(43.5,103.5), c(191.2,454.8))

colnames(table2)<- c("Y", "N")

rownames(table2)<- c("Helmet", "No Helmet")

print(table2)

(17-43.5)^2/43.5 + (218-191.2)^2/191.2 + (130-103.5)^2/103.5 + (428-454.8)^2/454.8   
