python mk趋势检验_求问!MK趋势检验和突变检验!

本文提供了一段使用Matlab实现的Mann-Kendall趋势检测代码,适用于时间序列数据的趋势分析。该方法通过计算Mann-Kendall统计量及Sen's Slope来评估数据随时间的变化趋势,并给出趋势的置信区间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

分享一段用matlab进行MK趋势的代码给你,希望你能用上

%α=0.05

% Time Series Trend Detection Tests

%

% [ z, sl, lcl, ucl ] = trend( y, dt )

%

% where z = Mann-Kendall Statistic

% sl = Sen's Slope Estimate

% lcl = Lower Confidence Limit of sl

% ucl = Upper Confidence Limit of sl

% y = Time Series of Data

% dt = Time Interval of Data

%

%

%--------------------------------------------------

%

function [ z, sl, lcl, ucl ] = trend( y, dt )

%

n = length( y );

%--------------------------------------------------

% Mann-Kendall Test for N > 40

%

disp( 'Mann-Kendall Test:' );

if n < 41,

disp( 'WARNING - sould be more than 40 points' );

end;

% calculate statistic

s = 0;

for k = 1:n-1,

for j = k+1:n,

s = s + sign( y(j) - y(k) );

end;

end;

% variance ( assuming no tied groups )

v = ( n * ( n - 1 ) * ( 2 * n + 5 ) ) / 18;

% test statistic

if s == 0,

z = 0;

elseif s > 0,

z = ( s - 1 ) / sqrt( v );

else,

z = ( s + 1 ) / sqrt( v );

end;

% should calculate Normal value here

nor = 1.96;

% results

disp( [ ' n = ' num2str( n ) ] );

disp( [ ' Mean Value = ' num2str( mean( y ) ) ] );

disp( [ ' Z statistic = ' num2str( z ) ] );

if abs( z ) < nor,

disp( ' No significant trend' );

z = 0;

elseif z > 0,

disp( ' Upward trend detected' );

else,

disp( ' Downward trend detected' );

end;

%----------------------------------------------------

%

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值