matlab实现mk突变检验的代码
时间: 2023-04-08 11:00:23 浏览: 127
我可以回答这个问题。以下是 Matlab 实现 MK 突变检验的代码:
function [z,p,trend,h] = mktest(x,alpha)
% MKTEST Mann-Kendall test for monotonic trend
%
% [z,p,trend,h] = mktest(x,alpha)
%
% x - data vector
% alpha - significance level (default = 0.05)
%
% z - test statistic
% p - p-value
% trend - trend (1 = upward, -1 = downward, 0 = no trend)
% h - 1 if null hypothesis rejected, 0 otherwise
%
% Reference:
% Hirsch, R.M., Slack, J.R., and Smith, R.A. (1982) Techniques of Trend
% Analysis for Monthly Water Quality Data. Water Resources Research,
% 18(1), 107-121.
if nargin < 2
alpha = 0.05;
end
n = length(x);
s = 0;
for i = 1:n-1
for j = i+1:n
s = s + sign(x(j)-x(i));
end
end
var_s = n*(n-1)*(2*n+5)/18;
if s > 0
z = (s-1)/sqrt(var_s);
else
z = (s+1)/sqrt(var_s);
end
p = 2*(1-normcdf(abs(z),0,1));
h = (p < alpha);
if h
if z > 0
trend = 1;
else
trend = -1;
end
else
trend = 0;
end
end
希望对你有帮助。
阅读全文