统计分布

先查看各命令展开的示例,再按需展开其他选项及 R 实现。改写代码前,请阅读适用条件及差异说明。

betaden

计算贝塔分布密度

Stata

display betaden(2,3,0.4)

R 包:stats

stats::dbeta(0.4, shape1=2, shape2=3)

binomial

计算二项分布含边界下尾概率

Stata

display binomial(10,3,0.4)

R 包:stats

stats::pbinom(3, size=10, prob=0.4)

binomialp

计算二项分布概率质量

Stata

display binomialp(10,3,0.4)

R 包:stats

stats::dbinom(3, size=10, prob=0.4)

binomialtail

计算二项分布含边界上尾概率

Stata

display binomialtail(10,3,0.4)

R 包:stats

stats::pbinom(2, size=10, prob=0.4, lower.tail=FALSE)

Stata上尾概率包含k;R的lower.tail=FALSE不包含其q参数值,因此应使用k-1。

binormal

计算相关二元正态概率

Stata

display binormal(0,0,0.4)

R 包:mvtnorm

as.numeric(mvtnorm::pmvnorm(upper=c(0,0),corr=matrix(c(1,0.4,0.4,1),2)))

与 Stata 有差异 用mvtnorm数值积分计算二元正态概率。积分容差及数值舍入不同于Stata分布函数。

cauchy

计算柯西分布累积概率

Stata

display cauchy(1,2,3)

R 包:stats

stats::pcauchy(3, location=1, scale=2)

cauchyden

计算柯西分布密度

Stata

display cauchyden(1,2,3)

R 包:stats

stats::dcauchy(3, location=1, scale=2)

cauchytail

计算柯西分布上尾概率

Stata

display cauchytail(1,2,3)

R 包:stats

stats::pcauchy(3, location=1, scale=2, lower.tail=FALSE)

chi2

计算卡方分布累积概率

Stata

display chi2(4,3)

R 包:stats

stats::pchisq(3, df=4)

chi2den

计算卡方分布密度

Stata

display chi2den(4,3)

R 包:stats

stats::dchisq(3, df=4)

chi2tail

计算卡方分布上尾概率

Stata

display chi2tail(4,3)

R 包:stats

stats::pchisq(3, df=4, lower.tail=FALSE)

corr2data

生成样本矩精确符合指定值的伪数据

Stata

corr2data x y, n(100)

R 包:MASS

stats::setNames(as.data.frame(MASS::mvrnorm(n=100,mu=c(0,0),Sigma=diag(2),empirical=TRUE)),c("x","y"))

与 Stata 有差异 empirical=TRUE强制样本均值和协方差符合设定;此类伪数据不是独立随机抽样。

drawnorm

联合生成独立标准正态变量列

Stata

drawnorm x y, n(100)

R 包:MASS

stats::setNames(as.data.frame(MASS::mvrnorm(n=100,mu=c(0,0),Sigma=diag(2))),c("x","y"))

与 Stata 有差异 随机序列不同;R返回包含所生成变量列的数据框。

exponential

计算指数分布累积概率

Stata

display exponential(2,3)

R 包:stats

stats::pexp(3, rate=1/2)

exponentialden

计算指数分布密度

Stata

display exponentialden(2,3)

R 包:stats

stats::dexp(3, rate=1/2)

exponentialtail

计算指数分布上尾概率

Stata

display exponentialtail(2,3)

R 包:stats

stats::pexp(3, rate=1/2, lower.tail=FALSE)

F

计算F分布累积概率

Stata

display F(4,10,2)

R 包:stats

stats::pf(2, df1=4, df2=10)

Fden

计算F分布密度

Stata

display Fden(4,10,2)

R 包:stats

stats::df(2, df1=4, df2=10)

Ftail

计算F分布上尾概率

Stata

display Ftail(4,10,2)

R 包:stats

stats::pf(2, df1=4, df2=10, lower.tail=FALSE)

gammaden

计算伽马分布密度

Stata

display gammaden(3,1,0,2)

R 包:stats

stats::dgamma(2, shape=3)

计算带位置参数的伽马密度

Stata

display gammaden(3,2,1,5)

R 包:stats

stats::dgamma(5-1, shape=3, scale=2)

gammap

计算伽马分布累积概率

Stata

display gammap(3,2)

R 包:stats

stats::pgamma(2, shape=3)

gammaptail

计算伽马分布上尾概率

Stata

display gammaptail(3,2)

R 包:stats

stats::pgamma(2, shape=3, lower.tail=FALSE)

hypergeometric

计算超几何分布含边界下尾概率

Stata

display hypergeometric(20,8,5,3)

R 包:stats

stats::phyper(3, m=8, n=12, k=5)

hypergeometricp

计算超几何分布概率质量

Stata

display hypergeometricp(20,8,5,3)

R 包:stats

stats::dhyper(3, m=8, n=12, k=5)

ibeta

计算贝塔分布累积概率

Stata

display ibeta(2,3,0.4)

R 包:stats

stats::pbeta(0.4, shape1=2, shape2=3)

ibetatail

计算贝塔分布上尾概率

Stata

display ibetatail(2,3,0.4)

R 包:stats

stats::pbeta(0.4, shape1=2, shape2=3, lower.tail=FALSE)

invbinomial

由二项累积概率反求成功概率

Stata

display invbinomial(10,3,0.5)

R 包:stats

stats::qbeta(0.5, shape1=4, shape2=7, lower.tail=FALSE)

这些Stata逆函数反求的是分布参数,而非离散结果的分位数。

invbinomialtail

由二项含边界上尾反求成功概率

Stata

display invbinomialtail(10,3,0.5)

R 包:stats

stats::qbeta(0.5, shape1=3, shape2=8)

这些Stata逆函数反求的是分布参数,而非离散结果的分位数。

invcauchy

计算柯西分布第90百分位数

Stata

display invcauchy(1,2,0.9)

R 包:stats

stats::qcauchy(0.9, location=1, scale=2)

invcauchytail

计算柯西分布上尾临界值

Stata

display invcauchytail(1,2,0.9)

R 包:stats

stats::qcauchy(0.9, location=1, scale=2, lower.tail=FALSE)

invchi2

计算卡方分布第90百分位数

Stata

display invchi2(4,0.9)

R 包:stats

stats::qchisq(0.9, df=4)

invchi2tail

计算卡方分布上尾临界值

Stata

display invchi2tail(4,0.9)

R 包:stats

stats::qchisq(0.9, df=4, lower.tail=FALSE)

invexponential

计算指数分布第90百分位数

Stata

display invexponential(2,0.9)

R 包:stats

stats::qexp(0.9, rate=1/2)

invexponentialtail

计算指数分布上尾临界值

Stata

display invexponentialtail(2,0.9)

R 包:stats

stats::qexp(0.9, rate=1/2, lower.tail=FALSE)

invF

计算F分布第90百分位数

Stata

display invF(4,10,0.9)

R 包:stats

stats::qf(0.9, df1=4, df2=10)

invFtail

计算F分布上尾临界值

Stata

display invFtail(4,10,0.9)

R 包:stats

stats::qf(0.9, df1=4, df2=10, lower.tail=FALSE)

invgammap

计算伽马分布第90百分位数

Stata

display invgammap(3,0.9)

R 包:stats

stats::qgamma(0.9, shape=3)

invgammaptail

计算伽马分布上尾临界值

Stata

display invgammaptail(3,0.9)

R 包:stats

stats::qgamma(0.9, shape=3, lower.tail=FALSE)

invibeta

计算贝塔分布第90百分位数

Stata

display invibeta(2,3,0.9)

R 包:stats

stats::qbeta(0.9, shape1=2, shape2=3)

invibetatail

计算贝塔分布上尾临界值

Stata

display invibetatail(2,3,0.9)

R 包:stats

stats::qbeta(0.9, shape1=2, shape2=3, lower.tail=FALSE)

invlogistic

把概率转换为对数优势

Stata

display invlogistic(0.8)

R 包:stats

stats::qlogis(0.8)

计算逻辑斯蒂分布第90百分位数

Stata

display invlogistic(1,2,0.9)

R 包:stats

stats::qlogis(0.9, location=1, scale=2)

invlogistictail

计算逻辑斯蒂分布上尾临界值

Stata

display invlogistictail(1,2,0.9)

R 包:stats

stats::qlogis(0.9, location=1, scale=2, lower.tail=FALSE)

invnbinomial

由负二项累积概率反求成功概率

Stata

display invnbinomial(4,3,0.5)

R 包:stats

stats::qbeta(0.5, shape1=4, shape2=4)

这些Stata逆函数反求的是分布参数,而非离散结果的分位数。

invnbinomialtail

由负二项含边界上尾反求成功概率

Stata

display invnbinomialtail(4,3,0.5)

R 包:stats

stats::qbeta(0.5, shape1=4, shape2=3, lower.tail=FALSE)

这些Stata逆函数反求的是分布参数,而非离散结果的分位数。

invnchi2

计算非中心卡方分布临界值

Stata

display invnchi2(4,2,0.9)

R 包:stats

stats::qchisq(0.9, df=4, ncp=2)

invnchi2tail

计算非中心卡方分布上尾临界值

Stata

display invnchi2tail(4,2,0.9)

R 包:stats

stats::qchisq(0.9, df=4, ncp=2, lower.tail=FALSE)

invnF

计算非中心F分布临界值

Stata

display invnF(4,20,2,0.9)

R 包:stats

stats::qf(0.9, df1=4, df2=20, ncp=2)

invnFtail

计算非中心F分布上尾临界值

Stata

display invnFtail(4,20,2,0.9)

R 包:stats

stats::qf(0.9, df1=4, df2=20, ncp=2, lower.tail=FALSE)

invnibeta

计算非中心贝塔分布临界值

Stata

display invnibeta(2,3,2,0.9)

R 包:stats

stats::qbeta(0.9, shape1=2, shape2=3, ncp=2)

invnormal

计算标准正态分布第90百分位数

Stata

display invnormal(0.9)

R 包:stats

stats::qnorm(0.9)

invnt

计算非中心t分布临界值

Stata

display invnt(20,2,0.9)

R 包:stats

stats::qt(0.9, df=20, ncp=2)

invnttail

计算非中心t分布上尾临界值

Stata

display invnttail(20,2,0.9)

R 包:stats

stats::qt(0.9, df=20, ncp=2, lower.tail=FALSE)

invpoisson

由泊松累积概率反求均值

Stata

display invpoisson(3,0.5)

R 包:stats

stats::qgamma(0.5, shape=4, lower.tail=FALSE)

这些Stata逆函数反求的是分布参数,而非离散结果的分位数。

invpoissontail

由泊松含边界上尾反求均值

Stata

display invpoissontail(3,0.5)

R 包:stats

stats::qgamma(0.5, shape=3)

这些Stata逆函数反求的是分布参数,而非离散结果的分位数。

invt

计算Student t分布第90百分位数

Stata

display invt(10,0.9)

R 包:stats

stats::qt(0.9, df=10)

invttail

计算Student t分布上尾临界值

Stata

display invttail(10,0.9)

R 包:stats

stats::qt(0.9, df=10, lower.tail=FALSE)

invtukeyprob

计算Tukey多重比较临界值

Stata

display invtukeyprob(4,20,0.95)

R 包:stats

stats::qtukey(0.95, nmeans=4, df=20)

与 Stata 有差异 采用qtukey的学生化极差分位数。R与Stata使用不同数值近似;已测试输入相差约2.5e-8,因此应按数值容差比较而非要求完全相等。

invweibull

计算威布尔分布第90百分位数

Stata

display invweibull(2,3,0.9)

R 包:stats

stats::qweibull(0.9, shape=2, scale=3)

invweibullph

计算比例风险威布尔分位数

Stata

display invweibullph(2,0.5,0.9)

R 包:stats

stats::qweibull(0.9, shape=2, scale=0.5^(-1/2))

invweibullphtail

计算比例风险威布尔上尾分位数

Stata

display invweibullphtail(2,0.5,0.1)

R 包:stats

stats::qweibull(0.1, shape=2, scale=0.5^(-1/2), lower.tail=FALSE)

invweibulltail

计算威布尔分布上尾临界值

Stata

display invweibulltail(2,3,0.9)

R 包:stats

stats::qweibull(0.9, shape=2, scale=3, lower.tail=FALSE)

lncauchyden

计算柯西分布对数密度

Stata

display lncauchyden(1,2,3)

R 包:stats

stats::dcauchy(3, location=1, scale=2, log=TRUE)

lnigammaden

计算逆伽马分布对数密度

Stata

display lnigammaden(3,2,4)

R 包:stats

stats::dgamma(1/4,shape=3,rate=2,log=TRUE)-2*log(4)

与 Stata 有差异 使用倒数gamma变量变换及其对数Jacobian。须统一Stata的形状和尺度参数化;数值尾部下溢行为可能不同。

lnmvnormalden

计算多变量正态对数密度

Stata

matrix M = (0,0)
matrix V = I(2)
matrix X = (1,2)
display lnmvnormalden(M,V,X)

R 包:mvtnorm

mvtnorm::dmvnorm(x=c(1,2),mean=c(0,0),sigma=diag(2),log=TRUE)

与 Stata 有差异 固定示例:均值M=(0,0),协方差V=I(2),求值向量X=(1,2)。

lnnormal

稳定计算正态分布极端对数概率

Stata

display lnnormal(-8)

R 包:stats

stats::pnorm(-8, log.p=TRUE)

lnnormalden

计算指定均值和标准差的正态对数密度

Stata

display lnnormalden(3,1,2)

R 包:stats

stats::dnorm(3, mean=1, sd=2, log=TRUE)

logistic

把对数优势转换为概率

Stata

display logistic(0.7)

R 包:stats

stats::plogis(0.7)
另有 1 个示例及替代实现

计算逻辑斯蒂分布累积概率

Stata

display logistic(1,2,3)

R 包:stats

stats::plogis(3, location=1, scale=2)

logisticden

计算逻辑斯蒂分布密度

Stata

display logisticden(1,2,3)

R 包:stats

stats::dlogis(3, location=1, scale=2)

logistictail

计算逻辑斯蒂分布上尾概率

Stata

display logistictail(1,2,3)

R 包:stats

stats::plogis(3, location=1, scale=2, lower.tail=FALSE)

nbetaden

计算非中心贝塔分布密度

Stata

display nbetaden(2,3,2,0.4)

R 包:stats

stats::dbeta(0.4, shape1=2, shape2=3, ncp=2)

nbinomial

计算负二项分布含边界下尾概率

Stata

display nbinomial(4,3,0.6)

R 包:stats

stats::pnbinom(3, size=4, prob=0.6)

nbinomialp

计算负二项分布概率质量

Stata

display nbinomialp(4,3,0.6)

R 包:stats

stats::dnbinom(3, size=4, prob=0.6)

nbinomialtail

计算负二项分布含边界上尾概率

Stata

display nbinomialtail(4,3,0.6)

R 包:stats

stats::pnbinom(2, size=4, prob=0.6, lower.tail=FALSE)

Stata上尾概率包含k;R的lower.tail=FALSE不包含其q参数值,因此应使用k-1。

nchi2

计算非中心卡方分布累积概率

Stata

display nchi2(4,2,3)

R 包:stats

stats::pchisq(3, df=4, ncp=2)

nchi2den

计算非中心卡方分布密度

Stata

display nchi2den(4,2,3)

R 包:stats

stats::dchisq(3, df=4, ncp=2)

nchi2tail

计算非中心卡方分布上尾概率

Stata

display nchi2tail(4,2,3)

R 包:stats

stats::pchisq(3, df=4, ncp=2, lower.tail=FALSE)

nF

计算非中心F分布累积概率

Stata

display nF(4,20,2,1.5)

R 包:stats

stats::pf(1.5, df1=4, df2=20, ncp=2)

nFden

计算非中心F分布密度

Stata

display nFden(4,20,2,1.5)

R 包:stats

stats::df(1.5, df1=4, df2=20, ncp=2)

nFtail

计算非中心F分布上尾概率

Stata

display nFtail(4,20,2,1.5)

R 包:stats

stats::pf(1.5, df1=4, df2=20, ncp=2, lower.tail=FALSE)

nibeta

计算非中心贝塔分布累积概率

Stata

display nibeta(2,3,2,0.4)

R 包:stats

stats::pbeta(0.4, shape1=2, shape2=3, ncp=2)

normal

计算标准正态分布累积概率

Stata

display normal(0.7)

R 包:stats

stats::pnorm(0.7)

normalden

计算标准正态分布密度

Stata

display normalden(0.7)

R 包:stats

stats::dnorm(0.7)

计算指定均值和标准差的正态密度

Stata

display normalden(3,1,2)

R 包:stats

stats::dnorm(3, mean=1, sd=2)

npnchi2

由非中心卡方概率反求非中心参数

Stata

display npnchi2(4,8,0.5)

R 包:stats

stats::uniroot(function(ncp) stats::pchisq(8,df=4,ncp=ncp)-0.5,c(0,50),tol=1e-10)$root

与 Stata 有差异 在所示非中心参数区间内数值反解非中心卡方CDF。其他输入可能需要更宽区间;Stata使用自身的定义域验证和反解。

npnF

由非中心F概率反求非中心参数

Stata

display npnF(4,20,2,0.5)

R 包:stats

stats::uniroot(function(ncp) stats::pf(2,df1=4,df2=20,ncp=ncp)-0.5,c(0,50),tol=1e-10)$root

与 Stata 有差异 在所示区间内数值反解非中心F的CDF。其他输入可能需要不同区间;求解容差不同于Stata。

npnt

由非中心t概率反求非中心参数

Stata

display npnt(20,2,0.5)

R 包:stats

stats::uniroot(function(ncp) stats::pt(2,df=20,ncp=ncp)-0.5,c(0,4),tol=1e-10)$root

与 Stata 有差异 在所示区间内数值反解非中心t的CDF。负值或更大的非中心参数需要不同边界;求解容差不同于Stata。

nt

计算非中心t分布累积概率

Stata

display nt(20,2,1.5)

R 包:stats

stats::pt(1.5, df=20, ncp=2)

nttail

计算非中心t分布上尾概率

Stata

display nttail(20,2,1.5)

R 包:stats

stats::pt(1.5, df=20, ncp=2, lower.tail=FALSE)

poisson

计算泊松分布含边界下尾概率

Stata

display poisson(2,3)

R 包:stats

stats::ppois(3, lambda=2)

poissonp

计算泊松分布概率质量

Stata

display poissonp(2,3)

R 包:stats

stats::dpois(3, lambda=2)

poissontail

计算泊松分布含边界上尾概率

Stata

display poissontail(2,3)

R 包:stats

stats::ppois(2, lambda=2, lower.tail=FALSE)

Stata上尾概率包含k;R的lower.tail=FALSE不包含其q参数值,因此应使用k-1。

rbeta

模拟贝塔随机变量

Stata

generate draw = rbeta(2,3)

R 包:stats

stats::rbeta(1000,2,3)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rbinomial

模拟二项随机变量

Stata

generate draw = rbinomial(10,0.4)

R 包:stats

stats::rbinom(1000,10,0.4)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rcauchy

模拟柯西随机变量

Stata

generate draw = rcauchy(1,2)

R 包:stats

stats::rcauchy(1000,1,2)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rchi2

模拟卡方随机变量

Stata

generate draw = rchi2(4)

R 包:stats

stats::rchisq(1000,4)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rexponential

模拟指数随机变量

Stata

generate draw = rexponential(2)

R 包:stats

stats::rexp(1000,rate=1/2)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rgamma

模拟伽马随机变量

Stata

generate draw = rgamma(3,2)

R 包:stats

stats::rgamma(1000,shape=3,scale=2)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rhypergeometric

模拟超几何随机变量

Stata

generate draw = rhypergeometric(20,8,5)

R 包:stats

stats::rhyper(1000,m=8,n=12,k=5)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rlogistic

模拟逻辑斯蒂随机变量

Stata

generate draw = rlogistic(1,2)

R 包:stats

stats::rlogis(1000,location=1,scale=2)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rnbinomial

模拟负二项随机变量

Stata

generate draw = rnbinomial(4,0.6)

R 包:stats

stats::rnbinom(1000,size=4,prob=0.6)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rpoisson

模拟泊松随机变量

Stata

generate draw = rpoisson(2)

R 包:stats

stats::rpois(1000,lambda=2)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rt

模拟t随机变量

Stata

generate draw = rt(20)

R 包:stats

stats::rt(1000,df=20)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

rweibull

模拟威布尔随机变量

Stata

generate draw = rweibull(2,3)

R 包:stats

stats::rweibull(1000,shape=2,scale=3)

与 Stata 有差异 相同种子不会使Stata和R生成相同的随机序列。

t

计算Student t分布累积概率

Stata

display t(10,1.2)

R 包:stats

stats::pt(1.2, df=10)

tden

计算Student t分布密度

Stata

display tden(10,1.2)

R 包:stats

stats::dt(1.2, df=10)

ttail

计算Student t分布上尾概率

Stata

display ttail(10,1.2)

R 包:stats

stats::pt(1.2, df=10, lower.tail=FALSE)

tukeyprob

计算学生化极差累积概率

Stata

display tukeyprob(4,20,3)

R 包:stats

stats::ptukey(3, nmeans=4, df=20)

weibull

计算带位置参数的威布尔累积概率

Stata

display weibull(2,3,1,5)

R 包:stats

stats::pweibull(5-1, shape=2, scale=3)

计算威布尔分布累积概率

Stata

display weibull(2,3,4)

R 包:stats

stats::pweibull(4, shape=2, scale=3)

weibullden

计算威布尔分布密度

Stata

display weibullden(2,3,4)

R 包:stats

stats::dweibull(4, shape=2, scale=3)

weibullph

使用比例风险威布尔参数化

Stata

display weibullph(2,0.5,3)

R 包:stats

stats::pweibull(3, shape=2, scale=0.5^(-1/2))

weibullphden

计算比例风险威布尔密度

Stata

display weibullphden(2,0.5,3)

R 包:stats

stats::dweibull(3, shape=2, scale=0.5^(-1/2))

weibullphtail

计算比例风险威布尔生存概率

Stata

display weibullphtail(2,0.5,3)

R 包:stats

stats::pweibull(3, shape=2, scale=0.5^(-1/2), lower.tail=FALSE)

weibulltail

计算威布尔分布上尾概率

Stata

display weibulltail(2,3,4)

R 包:stats

stats::pweibull(4, shape=2, scale=3, lower.tail=FALSE)