NCL回归系数及显著性检验打点
之前做回归以后,再做显著性检验的时候出现诸多问题,最主要的问题是显著性检验后的区域明显错误。实际上,(我做的是一元回归)应该在回归系数大的地方容易通过检验,回归系数小的地方通不过检验,且我认为通过检验的区域应该不会与回归系数等值线交叉。
经过排查,我发现regCoef给的tval(也就是t参数)并不准确,与我自己构建的t参数并不相同,这就是我一直画不对的原因,因此我用自己的回归系数r,构建了t参数,t参数的公式如下:(还好我的气象统计方法课件还留着,嘻嘻)
自己构建的t参数的分布就和回归系数很相似了,再通过NCL内置的不完全的beta函数计算:
其中df是自由度(regCoef输出的参数中有,若原有数据n个,则df为n-2)b是固定值0.5(但是b应该和tval,df一样是一个矩阵)。这样可以得到prob的分布,最后将prob小于0.05的部分打上点即可。出图如下:
最后放我画图的代码:
rc=regCoef(year,number_space)
rc=rc*10
rc!0="lat"
rc!1="lon"
rc&lat=olat
rc&lon=olon
tval = onedtond([email protected],dimsizes(rc))
df = onedtond([email protected],dimsizes(rc))-2
b = tval
b = 0.5
tval1=new((/41,64/),"float")
do i=0,40
do j=0,63
tval1(i,j)=rc(i,j)*sqrt(54)/sqrt(1-rc(i,j)^2)
;经过我多次实验,发现regcoef自带的tval不太对,我自己用自己算的才对,
;t检验量=rc*sqrt(df)/sqrt(1-rc^2)
end do
end do
prob = betainc(df/(df+tval1^2),df/2.0,b)
prob!0 = "lat"
prob!1 = "lon"
prob&lat = olat
prob&lon = olon
prob=where(prob.gt.1,1,prob)
; **********************************************
wks=gsn_open_wks("png","test")
gsn_define_colormap(wks,"MPL_YlOrBr")
res=True
[email protected]=False
[email protected]=False
[email protected]=False ;如果设置为真,则循环点被加入数据,如果数据不是循环的,就设置为假就可以。
[email protected]=True;画填充图
[email protected]=False;不画等值线
[email protected]=False;不要等值线上的标签
bres=res
res0=res
[email protected] = "ExplicitLevels"
[email protected] = (/0.1/)
[email protected]=False;取消默认填充形状
[email protected]=False;取消默认填充密度
[email protected]= (/17,-1/) ; the patterns
[email protected]=(/"black","white"/)
[email protected] =False
[email protected] = False
[email protected] = (/0.3/) ;数值越大越稀疏
[email protected]=""
[email protected]=1.0
; ******************************************************
[email protected] = "Ncarg4_1";网上的那个代码里没有这句,害我折腾了好久才明白
[email protected]="Earth..4" ;中国地图包含在这个叫Earth..4的地图库里
[email protected]=True
[email protected]=(/"China:states","Taiwan"/)
[email protected]=2.0 ;这两行是为了加粗边界和国界线
[email protected]=2.0
[email protected] = "Ncarg4_1"
[email protected] = True ;使能填充覆盖
[email protected] = (/"China:states","Taiwan"/)
[email protected]=0
[email protected]=0
[email protected]=38.0
[email protected]=55.0
[email protected]=119.0
[email protected]=135.0
[email protected]=""
[email protected]="PreDraw";先画填充
plot1=gsn_csm_contour_map(wks,rc,bres)
plot2=gsn_csm_contour(wks,prob,res0)
overlay(plot1,plot2)
draw(plot1)
frame(wks)
还是不太熟悉NCL,仍需加强学习。