测试MATLAB的广义极值分布函数GEV

nRows   = 1000;  nColumn= 250; 
data = trnd(8, nRows , nColumn);    %1000行250列,自由度为5的student t的随机数
maxSeries = max(data );                   % 250 列最大值,也就是所谓的极值
paras=gevfit(maxSeries);                  %根据极值参数,参数为形状参数k≠0,尺度参数sigma(σ),位置参数mu(?)
k=paras(1); sigma=paras(2); mu=paras(3); 
histogram(maxSeries,2:20);            %绘制极大值x的频数分布图,指定x轴指定范围在2-20年内,否则无法匹配高度
x= linspace(2,20,100);                      %产生1000个[2,20]的数据列
%1.根据指定的x序列值,计算GEV分布的概率值(GEV的3参数已知)
y_pdf= nColumn*gevpdf(x, k,sigma,mu );
line(x,y_pdf);                                      %这是概率分布曲线,如下图所示 
%2.根据指定的x序列值,计算GEV分布的累计概率值(GEV的3参数已知)
y_cdf= gevcdf(x,  k,sigma,mu );
%或用 y_cdf=cdf('gev', x,k,sigma,mu ); %name也可以用''Generalized Extreme Value''
line(x,y_cdf); 
%3.根据指定的概率值(或者分位数),获取对应的变量值
gevinv(0.5,k,sigma,mu);
%4.其余的函数有随机数和统计
R = gevrnd(k,sigma,mu)                                     %创建符合指定参数的随机数
[MeanVale,Variation] = gevstat(k,sigma,mu);  %计算均值和变异

ps:当k<0时,GEV是PⅢ极值分布;K>0时,是PⅡ极值分布;

%% 测试正态分布
x=-5:0.1:5;
mu=0; std=0.5;
%1.根据均值和标准差获得x的概率
y=normpdf(x,mu,std);%或y=pdf('norm',x,0,1);
hold on
plot(x,y)
%2.根据均值和标准差获得x的累积概率
y=cdf('norm',x,mu,std);%或y=pdf('norm',x,0,1);
hold on
plot(x,y)
%3.给定一个学生成绩求参数,分位数等
clc;clear
load('score')
[mu,std]=normfit(scores); 
histogram(scores,20:100)%这里的范围是20-100,下面画概率密度时一定要20-100
x=20:0.1:100;
y=normpdf(x,mu,std)*118;%概率密度.后者用:y=pdf('norm',x,mu,std)*500; 
line(x,y)
y=normcdf(x,mu,std);    %累积概率密度
line(x,y)
y=norminv(0.5,mu,std)  ;%分位数查找对应的变量值,比如中等50%分位数
%或用 y=icdf('norm',0.5,mu,std);

%% 4.验证拟合的优度
scores=sort(scores,'ascend');%对原始数据进行排序
scores(:,2)=[1:118]/119;    %计算原始数据的频数
scores(:,3)=norminv(scores(:,2),mu,std);%根据频数,计算在拟合曲线中的预测值
x=scores(:,1);
y=scores(:,3);
plot(x)
hold on
plot(y,'-')
legend('x','y')

[r1,p]=corr(scores,y_predict,'type','Pearson');  
[r2,p]=corr(scores,y_predict,'type','Kendall');
[r3,p]=corr(scores,y_predict,'type','Spearman');
line(1:118,y_predict)
histogram(y_predict,10)
histogram(scores,10)
line(1:118,scores)

  • 2
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值