2 title: "Week 3 R lecture"
3 subtitle: "Statistics and statistical programming \nNorthwestern University \nMTS 525"
9 ```{r setup, include=FALSE}
10 knitr::opts_chunk$set(echo = TRUE)
13 This week, we'll focus on one more way to manage date-time objects and some ways to generate distributions.
17 First, something I meant to include in last week's materials. The `as.Date()` function provides an alternative to `as.POSIX()` that is far more memorable and readable, but far less precise. Note that it truncates the time of day and the timezone from the ouput
20 m <- "2019-02-21 04:35:00"
23 a.good.time <- as.Date(m, format="%Y-%m-%d %H:%M:%S", tz="CDT")
28 ## Distribution functions
29 distribution functions: lets focus on *unif(): the key is on page 222 of Verzani
30 The “d” functions return the p.d.f. of the distribution
31 dunif(x=1, min=0, max=3) # 1/3 of the area is the to the left 1
32 The “p” functions return the c.d.f. of the distribution.
33 dunif(q=2, min=0, max=3) #1/(b-a) is 2/3
34 The “q” functions return the quantiles.
35 qunif(p=0.5, min=0, max=3) # half way between 0 and 3
37 The “r” functions return random samples from a distribution.
38 runif(n=1, min=0, max=3) # a random value in [0,3]
40 ## Doing simple simulations with random data
46 In case you don't believe the central limit theorem, let's put together a quick simulation to illustrate it in R.
48 Write a function to repeatedly take the mean of a sample.
50 Experiment by changing the size of the sample
53 ## Quantile quantile plots
56 ## Binomial and factorial functions