Matlab合成分析检验子函数

该子函数根据Dr. Jianping Li的fortran函数改编
function [fh,fl,dh,dl,dhl,tn,ta,ta95] = hcfx(n,x,f,coefh,coefl)
% For a time series f(n), computing:
% (1) mean in the high index years of x(n)
% (2) mean in the low index years of x(n)
% (3) composite difference between the mean of f(n) in high
% index years of x(n) and its climatology average
% (4) composite difference between the mean of f(n) in low
% index years of x(n) and its climate average
% (5) composite difference between the means of f(n) in high
% and low index years of x(n)
% input: n,x(n),f(n),coefh,coefl
% n: the length of time series
% x: control variable (index),eg:降水指数
% f: given series,eg:风场
% coefh: control parameter for high index (i.e., high index years are
% those in which x(i) > coefh)
% coefl: control parameter for low index (i.e., low index years are
% those in which x(i) < coefl)
% output: fh,fl,dh,dl,dhl,tn(5)
% fh: the mean of f in high index years of x(n)
% fl: the mean of f in low index years of x(n)
% dh: composite difference between the mean of f in high index years of x(n)
% and its climate mean (i.e., high index years minus cliamte mean).
% dl: composite difference between the mean of f in low index years of x(n)
% and its climate mean (i.e., low index years minus cliamte mean).
% dhl: composite difference between the means of f in high and low index years
% of x(n) (i.e., high minus low index years)
% tn(i,j): tn only equals 2., -2., 1., -1. or 0. corresponding to significant difference or not.
% tn=2. indicates that the difference is positive and significant.
% tn=-2. indicates that the difference is negative and significant.
% tn=1. indicates that the difference is positive but not significant.
% tn=-1. indicates that the difference is negative but not significant.
% tn=0. indicates the difference is zero.
% tn(1,j)~tn(5,j) are corresponding to the 90%,95%,98%,99% and 99.9% confident levels.
% j=1: siginificant test for dh
% j=2: siginificant test for dl
% j=3: siginificant test for dhl
% Feburary 11, 2002 by Jianping Li.

nh=length(f(x>=coefh));
hn=f(x>=coefh);

nl=length(f(x<=coefl));
ln=f(x<=coefl);

fh=mean(f(x>=coefh));
fl=mean(f(x<=coefl));
avef=mean(f);
dh=fh-avef;
dl=fl-avef;
dhl=fh-fl;
[tn(:,1),ta(:,1),ta95(:,1)]=diff_t_test(nh,n,hn,f);
[tn(:,2),ta(:,2),ta95(:,2)]=diff_t_test(nl,n,ln,f);
[tn(:,3),ta(:,3),ta95(:,3)]=diff_t_test(nh,nl,hn,ln);
end
function [tn,ta,ta95] = diff_t_test(n,m,x,y)
% n,m两个样本的样本数,n特殊年,m所有年
% x,y两个样本的序列

nn=10000;
tn(1:5)=0;
ax=mean(x);
sx=std(x);
vx=sx.^2;
ay=mean(y);
sy=std(y);
vy=sy.^2;
sxy=(nvx+mvy)/(n+m-2);
sxy=sxy*(1./n+1./m);
sxy=sqrt(sxy);
% if sxy==0
dxy=ax-ay;
if(dxy>0)
sn=2;
tn(1:5)=1;
else
sn=-2;
tn(1:5)=-1;
end
ta=abs(dxy)/sxy;
nm=n+m-2;
[ft(:,1),ft(:,2),ft(:,3),ft(:,4),ft(:,5)]=t_table(nn);
ta95=ft(nm,2);
for i=1:5
if(ta>=ft(nm,i))
tn(i)=sn;
end
end
end

function [ft90,ft95,ft98,ft99,ft999]=t_table(n)
% t-distribution, i.e., student's distribution
% t table with two-tailed (right and left tails) probabilities
% P(|t|>=ta)=a
% where a (alpha) significance level and (1-a)*100% is confindence level.
% t90: t-distribution test at 90% confidence level.
% t95: t-distribution test at 95% confidence level.
% t98: t-distribution test at 98% confidence level.
% t99: t-distribution test at 99% confidence level.
% t999: t-distribution test at 99.9% confidence level.
% By Dr. Jianping Li, January 5, 2000.
% n=10000;
n90=[ 6314,2920,2353,2132,2015,1943,1895,1860,1833,1812,...,
1796,1782,1771,1761,1753,1746,1740,1734,1729,1725,...,
1721,1717,1714,1711,1708,1706,1703,1701,1699,1697];
n95=[12706,4303,3182,2776,2571,2447,2365,2306,2262,2228,...,
2201,2179,2160,2145,2131,2120,2110,2101,2093,2086,...,
2080,2074,2069,2064,2060,2056,2052,2048,2045,2042];
n98=[31821,6965,4541,3747,3365,3143,2998,2896,2821,2764,...,
2718,2681,2650,2624,2602,2583,2567,2552,2539,2528,...,
2518,2508,2500,2492,2485,2479,2473,2467,2462,2457];
n99=[63657,9925,5841,4604,4032,3707,3499,3355,3250,3169,...,
3106,3055,3012,2977,2947,2921,2898,2878,2861,2845,...,
2831,2819,2807,2797,2787,2779,2771,2763,2756,2750];
n999=[636619,31598,12941,8610,6859,5959,5405,5041,4781,...,
4587,4437,4318,4221,4140,4073,4015,3965,3922,3883,3850,...,
3819,3792,3767,3745,3725,3707,3690,3674,3659,3646];

ft90=n90/1000;
ft95=n95/1000;
ft98=n98/1000;
ft99=n99/1000;
ft999=n999/1000;

for i=31:40
fi=(i-30)/10;
ft90(i)=1.697-(1.697-1.684)fi;
ft95(i)=2.042-(2.042-2.021)
fi;
ft98(i)=2.457-(2.457-2.423)fi;
ft99(i)=2.750-(2.750-2.704)
fi;
ft999(i)=3.646-(3.646-3.551)fi;
end
for i=41:60
fi=(i-40)/20;
ft90(i)=1.684-(1.684-1.671)
fi;
ft95(i)=2.021-(2.021-2.000)fi;
ft98(i)=2.423-(2.423-2.390)
fi;
ft99(i)=2.704-(2.704-2.660)fi;
ft999(i)=3.551-(3.551-3.460)
fi;
end
for i=61:120
fi=(i-60)/60;
ft90(i)=1.671-(1.671-1.658)fi;
ft95(i)=2.000-(2.000-1.980)
fi;
ft98(i)=2.390-(2.390-2.358)fi;
ft99(i)=2.660-(2.660-2.617)
fi;
ft999(i)=3.460-(3.460-3.373)fi;
end
for i=121:n
fi=(i-120)/(n-120);
ft90(i)=1.658-(1.658-1.645)
fi;
ft95(i)=1.980-(1.980-1.960)fi;
ft98(i)=2.358-(2.358-2.326)
fi;
ft99(i)=2.617-(2.617-2.576)fi;
ft999(i)=3.373-(3.373-2.291)
fi;
end
end

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容

  • 八年级下册 Unit1 What’s the matter? 【重点单词】 matter [ˈmætə] ...
    浑江257李明芳阅读 835评论 0 0
  • 我的图书馆 留言交流 2000个最常用的英语单词 2016-05-15酴羰骀璺 2000个最常用的英语单词 (英语...
    Mr_Wang92阅读 635评论 0 0
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 6,032评论 0 4
  • 公元:2019年11月28日19时42分农历:二零一九年 十一月 初三日 戌时干支:己亥乙亥己巳甲戌当月节气:立冬...
    石放阅读 6,870评论 0 2