library(ggplot2)
cdc <- read.csv(url("http://stat511.cwick.co.nz/homeworks/cdc.csv"))
#' #1
#' ##a
cdc$wt_diff <- with(cdc, weight - wtdesire)
#' *(0 pts)*
#'
#' ##b
males = subset(cdc, gender == "m")
females = subset(cdc, gender == "f")
mean(males$weight)
sd(males$weight)
length(males$weight)
mean(males$wtdesire)
sd(males$wtdesire)
length(males$wtdesire)
mean(females$weight)
sd(females$weight)
length(females$weight)
mean(females$wtdesire)
sd(females$wtdesire)
length(females$wtdesire)
#'
#' *(2 pts)*
#'
#' ## c
qplot(wt_diff, data = females, geom = "histogram", binwidth = 1)
#' It appears about one quarter of females are happy with their weight (the difference
#' between weight and desired weight is zero). Of those that aren't most desire
#' to be lighter (the difference is positive). The majority of females fall between
#' wanting to weigh 10 pounds heavier and 50 pounds lighter. There seems to be
#' a tendancy for the difference to be a multiple of five, probably reflecting that
#' most people reported their weight and desired weight to the nearest five pounds. There are a few females reporting wanting to lose over 100 pounds.
#'
#' *(1pt plot, 1pt description)*
#'
#' ## d
# qplot(weight,data=cdc,geom="histogram", binwidth = 5) + facet_wrap(~gender,nrow=2)
qplot(weight,data=cdc,geom="histogram", binwidth = 1) + facet_wrap(~gender,nrow=2)
#' As to be expected on average males in this sample are heavier than females in
#' this sample. Apart from the different centers, both weight distributions have
#' similar spreads are similar shapes: unimodal and roughly symmetric. There seem to be unusually many females reporting
#' a weight of 150lbs and males reporting 160lbs.
#'
#' *(1pt plot, 1pt description)*
#'
#' # 2
t.test(females$wt_diff)
#' We have convincing evidence that the population mean
#' difference in weight and weight desired for females is
#' not equal to zero (paired t-test p-value < 2.2e-16)
#' We estimate that a female's weight is on average 17 lbs more
#' than her desired weight.
#' With 95% confidence we estimate that a female weight is on
#' average between 15 and 19 lbs greater than her desired weight.
#'
#' *Or equivalently worded in terms of desired weight loss or gain.*
#'
#' *(1 pt doing correct test, 3pts for summary)*