```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Class Schedule
- **STAT 385** - Statistics Programming Methods
- **STAT 400** - Statistics and Probability I
# Using R
```{r}
x <- 1:10
sd(x)
```
```{r}
dpois(x = 3, lambda = 5)
```
```{r}
set.seed(385)
std_norm <- rnorm(n = 100)
mean(std_norm)
```
# Simulation Study
```{r}
# function that simulates sample means and variance from a poisson distribution
# for various sample sizes and true lambdas
sim_mean_var = function(sample_size = 50, true_lambda = 2) {
sim_sample = rpois(n = sample_size, lambda = true_lambda)
c(mean(sim_sample), var(sim_sample))
}
# generate sample means and variances
set.seed(42)
results = replicate(10000, sim_mean_var())
sample_means = results[1, ]
sample_variances = results[2, ]
```
```{r echo = FALSE}
# plot results of simulation study
plot(density(sample_means), xlim = range(sample_variances), lwd = 3,
main = "Sampling Distributions of Sample Mean and Variance: Poisson ",
xlab = " ", col = "dodgerblue")
lines(density(sample_variances), lwd = 3, lty = 2, col = "darkorange")
legend("topright", c("mean", "variance"), lty = c(1, 2), lwd = 3,
col = c("dodgerblue", "darkorange"))
abline(v = 2, col = "darkgrey", lty = 3)
```
# Objects and Functions
> “To understand computations in R, two slogans are helpful:
>
> - Everything that exists is an object.
> - Everything that happens is a function call."
>
> --- John Chambers