原文:http://blog.sina.com.cn/s/blog_7054a1960102vy7x.html
累積分布函數(shù)cdf (Cumulative Distribution Function)
背景知識:http://www.lifelaf.com/blog/?p=746
語法
y = cdf('name',x,A,B)
y = cdf('name',x,A,B,C)
y = cdf(pd,x)
y = cdf(___,'upper')
描述
y = cdf('name',x,A)?計算某種分布(由'name'定義衷掷,如'Normal'正態(tài), 'Poisson'泊松, 'T' t分布…)下,x值處的累計分布基显,A,B,C等為'name'函數(shù)的參數(shù)
y = cdf(pd,x)?直接計算概率分布函數(shù)pd(probability distribution)?脱衙,在x處的累計分布侥猬,實際上,這里的pd?已被'name', A定義好捐韩,舉栗如下:
%?定義一個正態(tài)分布函數(shù)pd,?均值mu = 0,?標準差sigma = 1.
mu = 0;
sigma = 1;
pd = makedist('Normal',mu,sigma);
%?定義x值
x = [-2,-1,0,1,2];
%?計算x值處的累計分布
y = cdf(pd,x)
y =
?0.0228?0.1587?0.5000?0.8413?0.9772
用第一種語句表達相同內(nèi)容為:
y2 = cdf('Normal',x,mu,sigma)?%正態(tài)分布退唠,x值處,均值為0荤胁,標準差為1
y2 =
?0.0228?0.1587?0.5000?0.8413?0.9772
http://nl.mathworks.com/help/stats/cdf.html
t分布累積分布函數(shù)tcdf (Student'stcumulative distribution function)
%?事實上就是y = cdf('T',x,A)函數(shù)
語法
p = tcdf(x,nu)
p = tcdf(x,nu,'upper')
描述
計算t分布在x值處的累積分布瞧预,nu是t分布的自由度
再舉個栗子
mu = 1;?% Population mean
sigma = 2;% Population standard deviation
n = 100;?% Sample size
x = normrnd(mu,sigma,n,1);% Random sample from population
xbar = mean(x);% Sample mean
s = std(x);?% Sample standard deviation
t = (xbar - mu)/(s/sqrt(n)) %?這里t分布出現(xiàn)了,正態(tài)分布總體與樣本均值的差符合t分布
t =
?1.0589
p = 1-tcdf(t,n-1)?% Probability of larger t-statistic
p =
?0.1461
該p值(即t函數(shù)的累積分布就是t檢驗在相同x值處的概率ptest)
[h,ptest] = ttest(x,mu,0.05,'right')
h =
?0
ptest =
?0.1461
http://nl.mathworks.com/help/stats/tcdf.html
概率密度函數(shù)pdf (Probability density functions)
搞懂了累積分布函數(shù)cdf仅政,這個就沒什么需要多說了
語法
y = pdf('name',x,A)
y = pdf('name',x,A,B)
y = pdf('name',x,A,B,C)
y = pdf(pd,x)
舉例
%?定義一個正態(tài)分布函數(shù)pd,?均值mu = 0,?標準差sigma = 1.
mu = 0;
sigma = 1;
pd = makedist('Normal',mu,sigma);
%?定義x值
x = [-2 -1 0 1 2];
%?計算x值處的概率密度(cdf是累計分布)
y = pdf (pd,x)
y =
0.0540?0.2420?0.3989?0.2420?0.0540
同樣垢油,另一種表達
y = pdf(pd,x)
y =
?0.0540?0.2420?0.3989?0.2420?0.0540
http://nl.mathworks.com/help/stats/pdf.html
t分布概率密度函數(shù)tpdf(Student's t probability density function)
語法
y = tpdf(x,nu)
舉例
tpdf(0,1:6)
ans =
?0.3183?0.3536?0.3676?0.3750?0.3796?0.3827
http://nl.mathworks.com/help/stats/tpdf.html
相反,還可以通過p求t分布的t值
tinv (Student's t inverse cumulative distribution function)
語法
x = tinv(p,nu)
舉例
% the 99th percentile of the Student's t distribution for one to six degrees of freedom
percentile = tinv(0.99,1:6)
percentile =
?31.8205?6.9646?4.5407?3.7469?3.3649?3.1427
http://nl.mathworks.com/help/stats/tinv.html
有一個問題圆丹,Matlab有一個inv矩陣求逆函數(shù)滩愁,不知與tinv什么關系,莫非tinv是在t分布下調(diào)用了inv計算程序辫封?但p并不等是t的逆矩陣啊(即t*p = E)跋跬鳌?求解答
inv是矩陣求逆的意思倦微。具體用法A=inv(B)妻味,其中B是輸入的可逆矩陣,輸出A就是B的逆矩陣璃诀,逆矩陣滿足性質(zhì) AB=BA=E (E是單位陣)弧可。如果輸入的是不可逆矩陣會彈出警告,并返回inf。
調(diào)用舉例:
>> inv([1 0;0 0])
警告: 矩陣為奇異工作精度棕诵。
ans =
Inf Inf
Inf Inf
>> inv(rand(2))
ans =
-13.0929 5.2640
12.0501 -3.3159
另附官方英文解釋(輸入doc inv也可以自己查看):
Y = inv(X) returns theinverse of the square matrix X. A warning messageis printed if X is badly scaled or nearly singular.
In practice, it is seldom necessary to form the explicit inverseof a matrix. A frequent misuse of inv arises whensolving the system of linear equations Ax = b.One way to solve this is with x = inv(A)*b.A better way, from both an execution time and numerical accuracy standpoint,is to use the matrix division operator x = A\b.This produces the solution using Gaussian elimination, without formingthe inverse. See mldivide (\)for further information.