0% found this document useful (0 votes)
4 views

R Formula and Review Sheet

The document provides a comprehensive R formula and review sheet focusing on statistical distributions, including both continuous and discrete types, with corresponding R functions for each. It also includes examples of frequency tables, bar charts, and plots for visualizing data distributions. The content is updated as of October 21, 2024.

Uploaded by

Abhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

R Formula and Review Sheet

The document provides a comprehensive R formula and review sheet focusing on statistical distributions, including both continuous and discrete types, with corresponding R functions for each. It also includes examples of frequency tables, bar charts, and plots for visualizing data distributions. The content is updated as of October 21, 2024.

Uploaded by

Abhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ACTEX Learning

R Formula & Review Sheet


(updated 10/21/2024)

DISTRIBUTIONS
Functions related to distributions belong to the (automatically loaded) stats package and have the form:
d<distribution>(x, <parameters>) returns the value of the PDF (f (x) or P (X = x)
p<distribution>(x, <parameters>) returns the value of the CDF (F (x)) or P (X ≤ x))
p<distribution>(x, <parameters>, lower=FALSE) returns 1 − F (x) or P (X > x)
q<distribution>(p, <parameters>) returns the min value of x for which P (X ≤ x) ≥ p (p-th quantile)
q<distribution>(p, <parameters>, lower=FALSE) returns the min value of x for which P (X > x) ≥ p
r<distribution>(n, <parameters>) returns an iid random sample of size n from the distribution

Continuous Distributions:
The parameters for Continuous Distributions are:
(a) Uniform Distribution (U (a, b)) unif(<>,a,b), dunif(<>, a, b), punif(<>, a, b), …
(b) Exponential Distribution (Exp(λ)) exp(<>, lambda)
(c) Gamma Distribution (Gamma(α, λ)) gamma(<>, alpha, lambda)
(d) Chi-square Distribution (χ2df ) chisq(<>,df)
(e) Beta Distribution (Beta(α, β)) beta(<>,alpha,beta)
(f) Normal Distribution (N (µ, σ )) 2
norm(<>,mu,sigma)
(g) Log-normal Distribution (Lognormal(µ, σ 2 )) lnorm(<>,mu,sigma)
(h) Standard Normal Distribution (N(0,1)) norm(<>)
(i) Student’s t-distribution (t(ν) ) t(<>, nu)
(j) F-Distribution (F (d1 , d2 )) f(<>, d1, d2)

Discrete Distributions:
The parameters for Discrete Distributions are:
(a) Binomial Distribution (Bin(n, p)) binom(<>, n, p)
(b) Poisson Distribution (P(λ)) pois(<>, lambda)
(c) Geometric Distribution (Geom(p)) geom(<>, p)
(d) Negative Binomial Distribution (NB(k, p)) nbinom(<>, k, p)
(e) Hypergeometric Distribution (HG(N, K, n)) hyper(<>, N, K, n)
(f) Uniform Distribution:
R does not provide built-in functions to deal with the discrete uniform distribution. Here are some alternatives:

x <- seq(a, b, i) # generates a sequence a, a+i, a+2i, ... a+ki <= b


length(x[x<=t]) / length(x) # yields P[X<=t]
length(x[x>=p | x>=q]) / length(x) # yields P[X>=p or X>=q]
length(x[x>=p & x>=q]) / length(x[x >= q]) # yields P[X=>p | X>=q] (conditional probability)

Copyright © ArchiMedia Advantage Inc.


www.ACTEXLearning.com Need Help? Email [email protected] All Rights Reserved
ACTEX Learning R Formula & Review Sheet 2

TABLES AND PLOTS

1. Frequency Table:
Example: Frequency table for an iid sample X with Xi ∼ Bin(100, 0.2). The bottom row is the number of occurrences of
the corresponding value in the top row in the sample.

table(rbinom(100, 100, 0.1))

##
## 4 5 6 7 8 9 10 11 12 13 14 15 16 19
## 3 2 5 13 7 12 11 13 13 12 5 1 1 2

2. Bar chart:
Example: Bar chart for the PDF of Bin(50, 0.4):
x <- 0:50
barplot(dbinom(x, 50, 0.4), names = x)
0.06
0.00

0 4 8 13 18 23 28 33 38 43 48

3. Plots:
Example: Plot of the PDF of N (10, 22 ):

x <- seq(0, 30, 0.01)


plot(x, dnorm(x, 10, 2), # x and y
type = "l", # type (p = points, l = lines, o = both overlaid)
main = "Normal Distribution Graph", # plot title
xlab = "x-values", ylab = "probabilities", # axis labels
xlim = c(0,30), ylim = c(0,0.25), # axis limits
col = "red", lwd = 2, # color and line width
lty = 2) # line type (1 = solid, 2 = dashed, 3 = dotted)

Normal Distribution Graph


probabilities

0.15
0.00

0 5 10 15 20 25 30

x−values

Copyright © ArchiMedia Advantage Inc.


www.ACTEXLearning.com Need Help? Email [email protected] All Rights Reserved

You might also like