中文函数名 | 调用名称 | 形式一 | 形式二 | 形式三 | 形式四 |
---|---|---|---|---|---|
最大值(最小值) | max(min) | M = max(A)M = max([23 42 37 18 52]) | M = max(A,[],dim,nanflag)A=[ -0.5 3.9 NaN 0.3]M = max(A,[],'includenan') | [M,I] = max(A,[],___,'linear');A = [1 2 3; 4 5 6][M,I] = max(A,[],2,'linear') | C = max(A,B,nanflag)A = rand(3,2);B = 0.5;C = max(A,B) |
和(积) | sum(prod) | S = sum(A) S = sum(1:10) | S = sum(A,dim) S = sum(rand(3,4),2) | S = sum(A,vecdim) S= sum( rand(4,3,3),[1 2]) | S = sum(A,vecdim,nanflag) |
累计和(累计积) | cumsum(comprod) | B = cumprod(A)B = cumprod(1:5) | B = cumprod(A,dim) B = cumprod(randn(5,3),2) | B = cumprod(A,direction) A = randi([3,10],3)B = cumprod(A,'reverse') | B = cumprod(A,nanflag) |
均值 | mean | M = mean(A) M = mean(randi([3,10],3)) | M = mean(A,dim)M = mean(randi([3,10],3),3) | M = mean(A,vecdim) | M = mean(___,nanflag) |
标准差 | std | S = std(A) S = std(randi([4,10],7)) | S = std(A,w,dim)S = std(randi([4,10],7),0,2) | S = std(A,w,vecdim) | S = std(___,nanflag) |
方差 | var | V = var(A,w) ;A=randi([4,10],3)var(A,[0.5 0.2 0.3]) | V = var(A,w,dim)A=randi([4,10],3)var(A,[0.5 0.2 0.3],2) | V = var(A,w,vecdim) | V = var(___,nanflag) |
协方差 | cov | C = cov(A)C = cov(randi([4,10],3) | C = cov(A,B)A = [3 6 4];B = [7 12 -9];cov(A,B) | C = cov(___,w) | C = cov(___,nanflag) |
相关系数 | corrcoef | R = corrcoef(A)A = [rand(6,1) rand(6,1)]; | R = corrcoef(A,B) A = randn(10,1);B = randn(10,1); | [R,P,RL,RU] = corrcoef(___) | ___ = corrcoef(___,Name,Value) |
排序 | sort | B = sort(A);A = [9 0 -7 -10 4 2] | B = sort(A,dim) B = sort(randi([4,10],3),2) | B = sort(___,direction);B = sort(randi([4,10],3),'descend') | [B,I] =sort(A,dim,Name,Value) |
中值 | median | M = median(A,'all') A=randi([4,10],3), | M = median(A,dim) M = median(randi([4,10],3),2) | M = median(A,vecdim) | M = median(A,vecdim,nanflag) |
百分位数 | prctile | Y = prctile(X,p) | Y = prctile(X,p,dim) | Y = prctile(X,p,vecdim) | Y = prctile(X,p,vecdim,'Method') |
条形图 | bar | bar(y) | bar(x,y) | bar(x,y,Name,Value) | b =bar(x,y,Name,Value) |
频数图 | histogram | histogram(X) | histogram(X,edges) | histogram(X,Name,Value) | h = histogram(X,Name,Value) |
[0,1]均匀分布 | rand | X = rand(n) | X = rand(x,y) | r = randi([10 50],1,5) | r = rand(1,4,'single') |
随机排列 | randperm | p = randperm(n) r = randperm(6) | p = randperm(n,k)r1 = randperm(8,4) | ||
随机数 | random | Y = random(gm) | Y = random(gm,n) | [Y,compIdx] = random(gm,n) | |
离散均匀随机 | unidrnd | r = unidrnd(n)r=unidrnd(1:10:100) | r =unidrnd(n,sz1,.,szN)R_array=unidrn(100,2,3) | r = unidrnd(n,sz)R_array = unidrnd(100,[2,3]) | |
均匀分布随机 | unifrnd | r = unifrnd(a,b)r = unifrnd(0,1) | r =unifrnd(a,b,sz1,...,szN)r1 = unifrnd(0,1:5) | r = unifrnd(a,b,sz)r2 = unifrnd(0,1,[2 3]) | |
正态分布随机 | normrnd | r = normrnd(0,1)r = normrnd(0,1) | r =normrn(mu,sigma,sz1,.szN) r = normrnd(3,10,4,3) | r = normrn(a,b,sz)r =normrnd(3,10,[1,5]) | |
二项分布随机 | binornd | r = binornd(n,p) r=binornd(10:10:60,1./[10:10:60]) | r =binornd(n,p,sz1,...,szN)r_array=binorn(100,0.2,2,3) | r = binornd(n,p,sz)binornd(100,0.2,[2 3]) | |
泊松分布随机 | poissrnd | r = poissrnd(lambda)r = poissrnd(10:2:20) | r = poissrnd(lambda,sz1,...,szN)r_array = poissrnd(20,3,4) | r = poissrnd(lambda,sz) r_array = poissrnd(30,[1 6]) | |
多维正态随机数 | mvnrnd | R = mvnrnd(mu,sigma)R = mvnrnd(rand(4,3),eye(3)) | R = mvnrnd(mu,sigma,n)R = mvnrnd( [2 3],[1 1.5; 1.5 3],100) | ||
概率函数 | y = pdf(gm,X) | pdf(gmdistribution([1 2;-3 -5],[1 1]),[0 0;1 2;3 3;5 3]) | |||
正态分布密度 | normpdf | y = normpdf(x) y = normpdf([-2,-1,0,1,2]) | y = normpdf(x,mu)y = normpdf([-2,-1,0,1,2],3) | y = normpdf(x,mu,sigma)y = normpdf([-2,-1,0,1,2],2,1) | |
累计概率函数 | cdf | y = cdf('name',x,A) | y = cdf('name',x,A,B) | y = cdf(pd,x) p = cdf(makedist('Normal'),[-3:0.1:3]) | |
正态分布函数 | normcdf | p = normcdf(x) p = normcdf([-1:0.1:1]) | p = normcdf(x,mu,sigma)p = normcdf([-1:0.1:1],2,0.5) | [p,pLo,pUp] = normcdf(x,mu,sigma,pCov) ;phat = mle(normrnd(5,2,1000,1))[~,pCov] = normlike([phat(1),phat(2)],normrnd(5,2,1000,1));[p,pLo,pUp] = normcdf(0,muHat,sigmaHat,pCov) | |
逆分布函数 | icdf | x = icdf('name',p,A) | x = icdf('name',p,A,B)x2 = icdf(pd,p,0,1) | x = icdf(pd,p);x = icdf(makedist('Normal','mu',0,'sigma',1),[0.1:0.1:0.9]) | |
正态分布下分位数 | norminv | x = norminv(p)x = norminv([0.1:0.1:0.9]) | x = norminv(p,mu,sigma)x = norminv([ 0.01:0.1:1],2,1) | [x,xLo,xUp] = norminv(p,mu,sigma,pCov,alpha)phat = mle(normrnd(5,2,[1000,1]));[~,pCov] = normlike([phat(1),phat(2)],normrnd(5,2,[1000,1]));[x,xLo,xUp] = norminv(0.5,muHat,sigmaHat,pCov,0.01) | |
T分布下分位数 | tinv | x = tinv(p,nu)x = tinv(0.95,50) | percentile = tinv(0.99,1:6) | ||
分布下分位数 | finv | X = finv(P,V1,V2) x = finv(0.95,5,10) | |||
参数估计 | mle | phat = mle(data,'distribution',dist) load carbigphat = mle(MPG,'distribution','burr') | phat = mle(data,'pdf',pdf,'start',start)x = ncx2rnd(8,3,1000,1);[phat,pci] =mle(x,'pdf',@(x,v,d)ncx2pdf(x,v,d),'start',[1,1]) | phat = mle(data,'pdf',pdf,'start',start,'cdf',cdf) load('readmissiontimes.mat');custpdf = @(data,lambda) lambda*exp(-lambda*data);custcdf = @(data,lambda) 1-exp(-lambda*data);phat=mle(ReadmissionTime,'pdf',custpdf,'cdf',custcdf,'start',0.05,'Censoring',Censored) | mle(data,'nloglf',nloglf,'start',start)load('readmissiontimes.mat');custnloglf = @(lambda,data,cens,freq) - length(data)*log(lambda)+nansum(lambda*data);phat=mle(ReadmissionTime,'nloglf',custnloglf,'start',0.05) |
正态参数估计 | normfit | [muHat,sigmaHat] = normfit(x)x= normrnd(0,1,[100,1]);[muHat,sigmaHat] = normfit(x); | [muHat,sigmaHat,muCI,sigmaCI] = normfit(x,alpha)x = normrnd(3,5,[1000,1]);[muHat,sigmaHat,muCI,sigmaCI] = normfit(x,0.01) | [___] = normfit(x,alpha,censoring,freq,options) | |
单总体T检验 | ttest | h = ttest(x) load stockreturnsx = stocks(:,3);[h,p,ci,stats] = ttest(x) | h = ttest(x,y,Name,Value) | h = ttest(x,m) | h = ttest(x,m,Name,Value) |
双总体T检验 | ttest2 | h = ttest2(x,y);load examgrades;x = grades(:,1);y = grades(:,2);[h,p,ci,stats] = ttest2(x,y) | h = ttest2(x,y,Name,Value) ;load examgradesx = grades(:,1);y = grades(:,2);[h,p] = ttest2(x,y,'Vartype','unequal') | ||
双分布秩检验 | ranksum | p = ranksum(x,y);x = unifrnd(0,1,10,1);y = unifrnd(0.25,1.25,15,1);p = ranksum(x,y) | [p,h,stats] = ranksum(x,y);load mileage[p,h,stats] = ranksum(mileage(:,1),mileage(:,2)) |
本期分享的这份大表格相当的复杂,整理起来费了点时间,但总算是对概率和统计回归的常用命令勾勒出大致框架。里面的有限函数开起来稍微有点陌生
就对过冷水而言里面的陌生函数都很多,平常用的多一点的就是max、sum、rand、sort这些处理矩阵的函数,存在即合理,这么多函数必然各自有其独特使用之处,过冷水总会一点点给大家找实际问题来演示函数的使用方法,请读者多多支持。
封面图片由mcmurryjulie在Pixabay上发布