1
0

adding a bunch of new files around week 4

This commit is contained in:
aaronshaw
2019-04-16 21:29:27 -05:00
parent bd9eba025b
commit f21e8d1868
5 changed files with 2090 additions and 0 deletions

View File

@@ -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