Statistics
summin/maxlengthmeanmedianvarsample variancesd(sample standard deviation)rafalib::popsd(population standard deviation)cov(x, y)covariancecor(x, y)correlation (default Pearson)
Regression
lm(y ~ x)Create a linear modelsummarySummary the model
Generation
1:10integer range from[1, 10]seq(from = 1, to = 9, by = 2)1 3 5 7 9rep(42, 10)repeat 42 for 10 timesrep(1:3, times = 3)1 2 3 1 2 3 1 2 3
Probability Distributions in R
Main: probability distributions in R
Overview
Type Distribution R Suffix Comments Continuous Normal -norm()Lognormal -lnorm()Normally distributed in a log scale Uniform -unif()Discrete Binomial -binom()Multinomial -multinom()Similar to binomial but when there are more than 2 outcomes Poisson -pois()Prefix:
Link to original
- PDF or PMF (
d-) e.g.dnorm(x)- CDF
( p-) e.g.pnorm(x)- the quantile function (
q-)- The random deviate function (
-r)
Monte-Carlo Methods
set.seedset a seed for PRNGsample(x, size, replace = TRUE/FALSE, prob = NULL)takes samples of the specified size with or without replacement.replicatereplicate an experimentntimes
Examples
Sample from 1-10 for 5 times without replacement
sample(x = 1:10, size = 5)
# 3 4 9 5 6Randomly throw a die 5 times:
sample(1:6, 5, replace = T)Do 1000 simulations of the sample sum of flipping a coin 10 times
simulation_result = replicate(1000, sum(sample(c(0, 1), 10, replace = T)))Plot
See ggplot2