- 积分
- 1968
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-5-11
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
说明:正文贴出matlab计算皮尔逊相关系数及t检验(95%)的子函数,以便查阅;
附件中包含相关系数、t检验(99%,95%,90%)M文件,自行取用;
如有疏漏,欢迎批评指正~
Part 1: 注:此处参考了http://bbs.06climate.com/forum.php?mod=viewthread&tid=6500,对原文作者表示感谢!@zya5704191
function coeff = myPearson(X , Y)
% 本函数实现了皮尔逊相关系数的计算操作
% 皮尔逊相关系数计算公式(P18)及无偏相关系数矫正公式(P19)参见《现代气候统计诊断与预测技术》-魏凤英
%
% 输入:
% X:输入的数值序列
% Y:输入的数值序列
%
% 输出:
% coeff:两个输入数值序列X,Y的相关系数
%
if length(X) ~= length(Y)
error('两个数值数列的维数不相等');
return;
end
fenzi = sum((X-sum(X)/length(X)).*(Y-sum(Y)/length(Y)));
fenmu = sqrt(sum((X-sum(X)/length(X)).^2))*sqrt(sum((Y-sum(Y)/length(Y)).^2));
coef = fenzi / fenmu;
if length(X)>30
coeff = coef;
elseif length(X)>4 && length(X)<30
coeff = coef*(1+(1-coef^2)/(2*(length(X)-4))); %计算无偏相关系数加以矫正
else
coeff = coef;
fprintf('数据长度小于5 %8.4f\n',coeff);
end
end %函数myPearson结束
Part 2:
function ttest = myttest005(X , Y)
% 本函数实现了皮尔逊相关系数的t检验(α=0.05)操作
% t检验公式(P31)及t分布表(P288)参见《现代气候统计诊断与预测技术》-魏凤英
%
% 输入:
% X:输入的皮尔逊相关系数r
% Y:输入的样本量n
%
% 输出:
% ttest:通过统计检验的相关系数
%
if Y <= 2
error('计算相关系数的样本量不够');
return;
end
if X == NaN
ttest = X;
return;
end
Z = Y-2;
tvalue = sqrt(Z)*abs(X)/sqrt(1-X.^2); %用abs(X)可做正or负相关的t检验
if Z == 1
tnorm = 12.71;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 2
tnorm = 4.30;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 3
tnorm = 3.18;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 4
tnorm = 2.78;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 5
tnorm = 2.57;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 6
tnorm = 2.45;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 7
tnorm = 2.37;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 8
tnorm = 2.31;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 9
tnorm = 2.26;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 10
tnorm = 2.23;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 11
tnorm = 2.20;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 12
tnorm = 2.18;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 13
tnorm = 2.16;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 14
tnorm = 2.15;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 15
tnorm = 2.13;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 16
tnorm = 2.12;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 17
tnorm = 2.11;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 18
tnorm = 2.10;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 19
tnorm = 2.09;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 20
tnorm = 2.09;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 21
tnorm = 2.08;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 22
tnorm = 2.07;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 23
tnorm = 2.07;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 24
tnorm = 2.06;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 25
tnorm = 2.06;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 26
tnorm = 2.06;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 27
tnorm = 2.05;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 28
tnorm = 2.05;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 29
tnorm = 2.04;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z == 30
tnorm = 2.04;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z > 30 && Z < 40
tnorm = 2.03;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z >= 40 && Z < 50
tnorm = 2.02;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z >= 50 && Z < 60
tnorm = 2.01;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z >= 60 && Z < 80
tnorm = 2.00;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z >= 80 && Z < 100
tnorm = 1.99;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
elseif Z >= 100 && Z <= 120
tnorm = 1.98;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
else
tnorm = 1.96;
if tvalue > tnorm
ttest = X;
else
ttest = NaN;
end
end
end %函数myttest005结束
|
评分
-
查看全部评分
|