1. 程式人生 > >[整理] 利用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, ...)