天天看点

[整理] 利用R生成随机分布的…

原文地址:[整理] 利用R生成随机分布的方法 作者:周庭锐教授 [整理] 利用R生成随机分布的方法 文/周庭锐

夜里复习各种统计分布的模拟、拟合、验证的R编程,顺手整理一下。 (不懂怎么一回事,刚刚贴上了,然后一转眼就消失了。新浪博客里闹鬼?)

d: density p: distribution function q: quantile function r: random deviates

rexp

The Exponential Distribution       dexp(x, rate = 1, log = FALSE)       pexp(q, rate = 1, lower.tail = TRUE, log.p = FALSE)       qexp(p, rate = 1, lower.tail = TRUE, log.p = FALSE)       rexp(n, rate = 1)

rf

The F Distribution       df(x, df1, df2, ncp, log = FALSE)       pf(q, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE)       qf(p, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE)       rf(n, df1, df2, ncp)

rgamma

The Gamma Distribution       dgamma(x, shape, rate = 1, scale = 1/rate, log = FALSE)       pgamma(q, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE)       qgamma(p, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE)       rgamma(n, shape, rate = 1, scale = 1/rate)

rgeom

The Geometric Distribution       dgeom(x, prob, log = FALSE)       pgeom(q, prob, lower.tail = TRUE, log.p = FALSE)       qgeom(p, prob, lower.tail = TRUE, log.p = FALSE)       rgeom(n, prob)

rhyper

The Hypergeometric Distribution       dhyper(x, m, n, k, log = FALSE)       phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE)       qhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE)       rhyper(nn, m, n, k)

rlnorm

The Log Normal Distribution       dlnorm(x, meanlog = 0, sdlog = 1, log = FALSE)       plnorm(q, meanlog = 0, sdlog = 1, lower.tail = TRUE, log.p = FALSE)       qlnorm(p, meanlog = 0, sdlog = 1, lower.tail = TRUE, log.p = FALSE)       rlnorm(n, meanlog = 0, sdlog = 1)

rlogis

The Logistic Distribution       dlogis(x, location = 0, scale = 1, log = FALSE)       plogis(q, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)       qlogis(p, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)       rlogis(n, location = 0, scale = 1)

rmultinom

The Multinomial Distribution       rmultinom(n, size, prob)       dmultinom(x, size = NULL, prob, log = FALSE)

rnbinom

The Negative Binomial Distribution       dnbinom(x, size, prob, mu, log = FALSE)       pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE)       qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE)       rnbinom(n, size, prob, mu)

rnorm

The Normal Distribution       dnorm(x, mean = 0, sd = 1, log = FALSE)       pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)       qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)       rnorm(n, mean = 0, sd = 1)

rpois

The Poisson Distribution       dpois(x, lambda, log = FALSE)       ppois(q, lambda, lower.tail = TRUE, log.p = FALSE)       qpois(p, lambda, lower.tail = TRUE, log.p = FALSE)       rpois(n, lambda)

rsignrank

Distribution of the Wilcoxon Signed Rank Statistic       dsignrank(x, n, log = FALSE)       psignrank(q, n, lower.tail = TRUE, log.p = FALSE)       qsignrank(p, n, lower.tail = TRUE, log.p = FALSE)       rsignrank(nn, n)

rt

The Student t Distribution       dt(x, df, ncp, log = FALSE)       pt(q, df, ncp, lower.tail = TRUE, log.p = FALSE)       qt(p, df, ncp, lower.tail = TRUE, log.p = FALSE)       rt(n, df, ncp)

runif

The Uniform Distribution       dunif(x, min=0, max=1, log = FALSE)       punif(q, min=0, max=1, lower.tail = TRUE, log.p = FALSE)       qunif(p, min=0, max=1, lower.tail = TRUE, log.p = FALSE)       runif(n, min=0, max=1)

rweibull

The Weibull Distribution       dweibull(x, shape, scale = 1, log = FALSE)       pweibull(q, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)       qweibull(p, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)       rweibull(n, shape, scale = 1)

rwilcox

Distribution of the Wilcoxon Rank Sum Statistic       dwilcox(x, m, n, log = FALSE)       pwilcox(q, m, n, lower.tail = TRUE, log.p = FALSE)       qwilcox(p, m, n, lower.tail = TRUE, log.p = FALSE)       rwilcox(nn, m, n)

sample

The Discrete Uniform Distribution       sample(x, size, replace = FALSE, prob = NULL)       sample.int(n, size = n, replace = FALSE, prob = NULL)

拟合:

连续型变量: 大样本:Kolmogorov-Smirnov检验       ks.test(x, y, ...,               alternative = c("two.sided", "less", "greater"),               exact = NULL) 小样本:Shapiro-Wilk检验       shapiro.test(x)

离散型变量:方差齐次性检验       fligner.test(x, ...)             ## Default S3 method:       fligner.test(x, g, ...)             ## S3 method for class 'formula'       fligner.test(formula, data, subset, na.action, ...) 或       mood.test(x, ...)             ## Default S3 method:       mood.test(x, y,                 alternative = c("two.sided", "less", "greater"), ...)             ## S3 method for class 'formula'       mood.test(formula, data, subset, na.action, ...)

继续阅读