seed_value <- 19710822 set.seed(seed_value) options(width = 72) opts_chunk$set(fig.width=4, fig.height=4, fig.align='center', fig.show='hold', out.width='0.3\\linewidth') x <- 0:10 dbinom(x, size = 10, prob = 0.5) barplot(dbinom(x, size = 10, prob = 0.5), names.arg = x) 1 - pbinom(7, size = 10, prob = 0.5) barplot(pbinom(x, 10, 0.5), names.arg = x) sum(dbinom(8:10, 10, 0.5)) rbinom(50, 10, 0.5) hist(rbinom(1000000, 10, 0.5), breaks = seq(-0.5, 10.5, by = 1)) x <- 0:10; barplot(dbinom(x, 10, 0.2), names.arg = x) x <- 0:10; barplot(dbinom(x, 100, 0.02), names.arg = x) 1 - pbinom(10, 100, 0.02) x <- 0:10 par(mfrow = c(1, 4)) barplot(dbinom(x, 10, 0.2), names.arg = x) barplot(dbinom(x, 100, 0.02), names.arg = x) barplot(dbinom(x, 1000, 0.002), names.arg = x) barplot(dbinom(x, 10000, 0.0002), names.arg = x) par(mfrow = c(1, 4)) n <- 10; barplot(dbinom(x, n, 2/n), names.arg = x, ylim = c(0, 0.35), main = paste("n = ", n)) n <- 100; barplot(dbinom(x, n, 2/n), names.arg = x, ylim = c(0, 0.35), main = paste("n = ", n)) n <- 1000; barplot(dbinom(x, n, 2/n), names.arg = x, ylim = c(0, 0.35), main = paste("n = ", n)) n <- 10000; barplot(dbinom(x, n, 2/n), names.arg = x, ylim = c(0, 0.35), main = paste("n = ", n)) par(mfrow = c(1, 4)) for (n in c(10, 100, 1000, 10000)) { barplot(dbinom(x, n, 2/n), names.arg = x, ylim = c(0, 0.35), main = paste("n = ", n)) } par(mfrow = c(1, 1)) dpois(0, 4) 1 - ppois(6, 4) rpois(50, 0.25) x <- 0:20 barplot(dgeom(x, 0.25), names.arg = x) barplot(pgeom(x, 0.25), names.arg = x) rgeom(10, 0.25) qgeom(0.95, 0.25) + 1 x <- 0:15; cbind(x, y = 0.75 ^ x) curve(dunif(x, 0, 10), -0.3, 10.3, ylim = c(-0.005, 0.105)) curve(dexp(x, rate = 10), 0, 0.5) curve(pexp(x, rate = 10), 0, 0.5) curve(dnorm(x, mean = 0, sd = 1), -4, 4) curve(dnorm(x, 0, 1), -4, 4) lines(c(-1.96, -1.96), c(0, dnorm(-1.96))) lines(c(+1.96, +1.96), c(0, dnorm(+1.96))) x <- seq(-4, 4, 0.01) y <- dnorm(x) plot(x, y, type = "l") polygon(c(-1.96, x[x >= -1.96 & x <= 1.96], 1.96), c( 0, y[x >= -1.96 & x <= 1.96], 0), col = "red") pnorm(1.96) - pnorm(-1.96) ## qnorm(0.5); qnorm(0.025); qnorm(0.975) x <- rnorm(100) ks.test(x, "pnorm", mean = mean(x), sd = sd(x)) x <- rexp(100) ks.test(x, "pnorm", mean = mean(x), sd = sd(x)) ks.test(rnorm(20, mean = 0.1), "pnorm") ks.test(rnorm(100000, mean = 0.1), "pnorm") x <- rnorm(100) (p <- ((1:100) - 0.5) / 100) # wrap an assignment in () to print q <- qnorm(p) plot(q) q[1] q[20] plot(q, sort(x)) qqnorm(x); qqline(x)