This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coin.power <- function(a, p, n){ | |
c <- qnorm(1 - a/2) | |
mu <- sqrt(n) * (2 * p - 1) | |
sigma <- sqrt(4 * p * (1 - p)) | |
less.than <- pnorm( -c, mean = mu, sd = sigma) | |
greater.than <- 1 - pnorm(c, mean = mu, sd = sigma) | |
power <- less.than + greater.than | |
return(power) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group <- c('treatment', 'control', 'refused') | |
n.children <- 1000 * c(200, 200, 340) | |
n.polio <- c(57, 142, 157) | |
rate <- n.polio/n.children | |
polio.data <- data.frame(group, n.children, n.polio, rate) | |
polio.data | |
treatment <- subset(polio.data, group == 'treatment') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pnorm(10, mean = 12, sd = 2) | |
pnorm(250, mean = 300, sd = 10) | |
n <- 950:961 | |
width <- 2 * qnorm(1 - 0.01/2) * 6/sqrt(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% I learned how to make these flowcharts by looking at some very helpful examples online: | |
% | |
% http://www.texample.net/tikz/examples/simple-flow-chart/ | |
% http://www.texample.net/tikz/examples/borrowers-and-lenders/ | |
% http://www.texample.net/tikz/examples/entity-relationship-diagram/ | |
% | |
% For a long list of tikz examples, see http://www.texample.net/tikz/examples/ | |
\documentclass{beamer} | |
\usepackage{amssymb, amsmath, amsthm} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ones <- rep(1, 10) | |
ones | |
cumsum(ones) | |
cumsum(1:10) | |
n <- 10000 | |
sims <- rnorm(n, mean = 0, sd = 10) | |
running.mean <- cumsum(sims)/(1:n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Function to draw a single Chi-squared random variable with degrees of freedom equal to df | |
my.rchisq <- function(df){ | |
#Draw df independent standard normals | |
normal.sims <- rnorm(df) | |
#Square them and sum the result | |
chi.sims <- sum(normal.sims^2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- seq(from = -5, to = 5, by = 0.01) | |
y1 <- dnorm(x) | |
y2 <- dt(x, df = 1) | |
y <- cbind(y1, y2) | |
matplot(x, y, lty = 1, type = 'l', ylab = 'f(x)') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- seq(from = -1, to = 1, by = 0.5) | |
y <- x^2 | |
plot(x, y) | |
x <- seq(from = -1, to = 1, by = 0.1) | |
y <- x^2 | |
plot(x, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This function simulates n independent, identically distributed Bernoulli Random Variables | |
rbern <- function(n, p){ | |
sims <- sample(0:1, size = n, replace = TRUE, prob = c(1-p, p)) | |
return(sims) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marbles <- c('red', 'blue', 'green') | |
sample(x = marbles, size = 2, replace = FALSE) | |
sample(x = 1:10, size = 5, replace = FALSE) | |