X-Git-Url: https://code.communitydata.science/stats_class_2019.git/blobdiff_plain/bd9eba025b1137bb6497a56ad3f5634ff411058e..f21e8d18685e0ed07df48b7eb5050a616ee316dd:/r_lectures/w04-R_lecture.Rmd

diff --git a/r_lectures/w04-R_lecture.Rmd b/r_lectures/w04-R_lecture.Rmd
new file mode 100644
index 0000000..c7c84ff
--- /dev/null
+++ b/r_lectures/w04-R_lecture.Rmd
@@ -0,0 +1,59 @@
+---
+title: "Week 3 R lecture"
+subtitle: "Statistics and statistical programming  \nNorthwestern University  \nMTS 525"
+author: "Aaron Shaw"
+date: "April 18, 2019"
+output: html_document
+---
+
+```{r setup, include=FALSE}
+knitr::opts_chunk$set(echo = TRUE)
+```
+
+This week, we'll focus on one more way to manage date-time objects and some ways to generate distributions.
+
+## as.Date
+
+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
+
+```{r}
+m <- "2019-02-21 04:35:00"
+class(m)
+
+a.good.time <- as.Date(m, format="%Y-%m-%d %H:%M:%S", tz="CDT")
+class(a.good.time)
+a.good.time
+```
+
+## Distribution functions
+distribution functions: lets focus on *unif(): the key is on page 222 of Verzani
+The âdâ functions return the p.d.f. of the distribution
+dunif(x=1, min=0, max=3) # 1/3 of the area is the to the left 1
+The âpâ functions return the c.d.f. of the distribution.
+dunif(q=2, min=0, max=3) #1/(b-a) is 2/3
+The âqâ functions return the quantiles.
+qunif(p=0.5, min=0, max=3) # half way between 0 and 3
+
+The ârâ functions return random samples from a distribution.
+runif(n=1, min=0, max=3) # a random value in [0,3]
+
+## Doing simple simulations with random data
+runif()
+rnorm()
+
+## A quick simulation
+
+In case you don't believe the central limit theorem, let's put together a quick simulation to illustrate it in R.
+
+Write a function to repeatedly take the mean of a sample.
+
+Experiment by changing the size of the sample
+
+
+## Quantile quantile plots
+
+
+## Binomial and factorial functions
+Choose, factorial
+
+
