## -----------------------------------------------------------------------------
# n is not specified 
power.t.test(delta = 6,
             power = .99, 
             sd = 4,
             type = "paired")


## -----------------------------------------------------------------------------
power.t.test(delta = 6,
             n = 20, 
             sd = 4, 
             type = "paired")


## -----------------------------------------------------------------------------
power.t.test(delta = 3,
             n = 15,
             sd = 5, 
             type = "paired")


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

t.test(lipids$TRG, mu = 120)


## -----------------------------------------------------------------------------
anorexia_alltreat <- read.delim("https://raw.githubusercontent.com/IowaBiostat/data-sets/main/anorexia/anorexia.txt")
# We need to index to just get the weights for those who received family treatment.
anorexia <- anorexia_alltreat[anorexia_alltreat$Treat == "FT",]


## -----------------------------------------------------------------------------
# create a new column
anorexia$diff <- anorexia$Postwt-anorexia$Prewt


## -----------------------------------------------------------------------------
SE <- sd(anorexia$diff)/sqrt(17)

t <- (mean(anorexia$diff) - 0) / SE

2*(1-pt(t, df=16))


## -----------------------------------------------------------------------------
## Test for Post - Prior
t.test(anorexia$Postwt, anorexia$Prewt, paired = TRUE)

