```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## (a)
```{r}
NoU<-read.csv("http://stat.umn.edu/~wuxxx725/data/Getting2NoUS2019.csv", header = T)
names(NoU)
social.Fr <- NoU$social.networks.hrs[NoU$year == "Freshman"]
```

```{r}
hist(social.Fr, xlim=c(0, 10), breaks=20, main="Histogram of hours per day spent on social media for Freshmen", xlab="Hours per day")
```

## (b)
```{r}
boxplot(social.Fr, ylim=c(0, 10))
```

## (c)
```{r}
qqnorm(social.Fr)
qqline(social.Fr)
```

## (d)
CLT.

## (e)
```{r}
mu = mean(social.Fr)
mu
```

## (f)
```{r}
sigma = sd(social.Fr)  # sd of population
n = length(social.Fr)  # sample size
se = sigma/sqrt(n)  # se of sample mean
se
```

$moe = multiplier*se$, strictly speaking, t-multiplier t($1-e/2$ ,df=n-1), error rate $e=1-\alpha$, $\alpha$ is confidence level.
When sample size n is large enough, say, n>30, we can use multiplier $z = qnorm(1-e/2)$ to approximate t-multiplier.(They're about the same) 
## (g)
```{r}
e = 0.02
t = qt(1-e/2, n-1)
moe = se*t
moe
```

## (h)
```{r}
c(mu-moe, mu+moe)
```

## (i)
Yes.

## (j)
```{r}
t.test(social.Fr, conf.level = 0.98, alternative="two.sided")
```

## (k)
```{r}
social.Sr<- NoU$social.networks.hrs[NoU$year == "Senior"]
boxplot(social.Fr, social.Sr, names=c("Freshmen", "Senior"))
```
```{r}
sd(social.Fr)
sd(social.Sr)
```


## (l)
```{r}
t.test(x=social.Fr, y=social.Sr, conf.level=0.98, alternative="two.sided", var.equal=TRUE)
# t.test(x=social.Fr, y=social.Sr, conf.level=0.98, alternative="two.sided", var.equal=F)  # using an approximate test called Welch t-test when variance of two samples are unequal.
```

