您好,欢迎访问三七文档
clc,clear;%%读取数据excelFile='xx';%文件路径myData=xlsread(excelFile);%读取数据timeSeries=myData(:,1);%时间序列数据dataSeries=myData(:,2);%dataCount=length(dataSeries);%%设置步长与检验值step=10;%步长v=step+step-2;%计算自由度ttest=2.878;%查表得t检验值,修改len1=step;len2=step;x=timeSeries(step:dataCount-step);fori=step:dataCount-stepn1=dataSeries(i-step+1:i);n2=dataSeries(i+1:i+step);mean1=mean(n1);mean2=mean(n2);c=(len1+len2)/(len1*len2);var1=1/len1*sum((n1-mean1).^2);var2=1/len2*sum((n2-mean2).^2);delta1=len1*var1+len2*var2;delta=delta1/(len1+len2-2);t(i-step+1)=(mean1-mean2)/sqrt(delta*c);end%%制图figure(1);plot(x,t,'r-','linewidth',1.5);xlabel('t(year)','FontName','TimesNewRoman','FontSize',12);ylabel('统计量','FontName','TimesNewRoman','Fontsize',12);axis([min(x),max(x),-4,4]);holdonplot(x,0*ones(i-step+1,1),'-.','linewidth',1);plot(x,ttest*ones(i-step+1,1),':','linewidth',1);%更改数字plot(x,-ttest*ones(i-step+1,1),':','linewidth',1);%更改数字legend('t统计量','0.01显著水平');
本文标题:滑动T检验程序
链接地址:https://www.777doc.com/doc-5649761 .html