dt:10
# make this an external chunk that can be included in any file options(width = 70) opts_chunk$set(message = F, error = F, warning = F, comment = NA, fig.align = 'center', dpi = 100, tidy = F, cache = T, cache.path = '.cache/', fig.path = 'assets/fig/') options(xtable.type = 'html') knit_hooks$set(inline = function(x) { if(is.numeric(x)) { round(x, getOption('digits')) } else { paste(as.character(x), collapse = ', ') } }) knit_hooks$set(plot = knitr:::hook_plot_html)
Distributions * rbeta, rbinom, rcauchy, rchisq, rexp, rf, rgamma, rgeom, rhyper, rlogis, rlnorm, rnbinom, rnorm, rpois, rt, runif, rweibull
Densities
Sampling * sample(,replace=TRUE),sample(replace=FALSE)
--- dt:20
Normal
args(rnorm) heights = rnorm(10,mean=188,sd=3) heights
--- dt:30
Binomial
args(rbinom) coinFlips = rbinom(10,size=10,prob=0.5) coinFlips
Normal Distribution: $N(\mu,\sigma)$ * $X \sim N(0,1)$
xvals = seq(-10,10,length=100) plot(xvals,dnorm(xvals,0,1),type="l",col="blue",lwd=3,ylab="density",xlab="X value")
Normal
args(dnorm) x = seq(from=-5,to=5,length=10) normalDensity = dnorm(x,mean=0,sd=1) round(normalDensity,2)
Binomial distribution: $Bin(n,p)$ * $X \sim Bin(10,0.5)$
xvals = 0:10 plot(xvals,dbinom(xvals,10,0.5),type="h",col="blue",lwd=3,ylab="probability",xlab="X value")
Binomial
args(dbinom) x = seq(0,10,by=1) binomialDensity = dbinom(x,size=10,prob=0.5) round(binomialDensity,2)
args(sample) heights = rnorm(10,mean=188,sd=3) heights sample(heights,size=10,replace=TRUE)
heights sample(heights,size=10,replace=FALSE)
heights probs = c(0.4,0.3,0.2,0.1,0,0,0,0,0,0) sum(probs) sample(heights,size=10,replace=TRUE,prob=probs)
Setting a seed ensures reproducible results from random processes in R
set.seed(12345) rnorm(5,mean=0,sd=1) set.seed(12345) rnorm(5,mean=0,sd=1)
More on distributions in R
http://cran.r-project.org/web/views/Distributions.html
Computing for Data Analysis
<section class="video" id="video"> <video id='player' controls style='width:200px;height:150px;'> <source src="assets/media/simulations.mp4" type="video/mp4" /> </video> </section>
--- &popcorn
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.