# R code for lab 12 

diarrhea <- read.delim("http://myweb.uiowa.edu/pbreheny/161/data/diarrhea.txt")
attach(diarrhea)

head(diarrhea)

# Section 2:
boxplot(Stool~Group, col = "grey", main = "Effect of bismuth salicylate")

require(lattice)
histogram(~Stool|Group)

# section 3

(n1 <- sum(Group=="Treatment"))
(n2 <- sum(Group == "Control"))

(x1 <- mean(Stool[Group == "Treatment"]))
(x2 <- mean(Stool[Group == "Control"]))

(s1 <- sd(Stool[Group == "Treatment"]))
(s2 <- sd(Stool[Group == "Control"]))

(sdp <- sqrt(((n1 - 1) * s1 ^ 2 + (n2 - 1) * s2 ^ 2)/ (n1 + n2 -2)))


# Student's t-test
t.test(Stool~Group, var.equal = TRUE)

# Welch's t-test
t.test(Stool~Group)

detach(diarrhea)
######## PRACTICE PROBLEM ############

infantheart <- read.delim("http://myweb.uiowa.edu/pbreheny/161/data/infantheart.txt")
head(infantheart)
attach(infantheart)

## Sample size in each group
sum(Treatment == "Circulatory arrest")
sum(Treatment == "Low-flow bypass")

# Do parts a) through e) from the lab

