爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 29422|回复: 47

[作图] 回归分析的显著性检验问题

[复制链接]

新浪微博达人勋

发表于 2015-3-27 22:32:34 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
我用regCoef对nino3指数与sst做了相关,并用betainc检验(官网的解释是t检验的一种:The returned probability is two-tailed. The ttest uses the incomplete beta function (betainc) to calculate the probability. Example 2 at betainc illustrates how to get the one-tailed probability. There is also a link where you can get one and two-tailed probabilities via the WWW.
因为对betainc 这个函数不是很理解,所以图画出来怪怪的,也不知道怎么改~(比如:Example 2 - The betainc can be used as a p-Value calculator for the Student t-test. Let's say a calculation has been made where the degrees-of-freedom (df=20) and a Student-t value of 2.08 has been determined. A probability level may be determined via:
  df   = 20   tval = 2.08    prob = betainc( df/(df+tval^2), df/2.0, 0.5)   print ("prob="+prob)这里的0.5是默认还是……?



想显示通过95%显著性检验的地方,应该如何修改程序呢?




load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;************************************************
begin
time=45
nx=360
ny=180
missing_value=-1.0E+30
lat = fspan(-89.5,89.5,180)
lon = fspan(-179.5,179.5,360)
lat@units = "degrees_north"
lon@units = "degrees_east"

x=fbindirread("winter.grd",0,(/time/),"float")
x!0="time"

y=fbindirread("djf.grd",0,(/time,ny,nx/),"float")
y!0="time"
y!1="lat"
y!2="lon"
y&lat=lat
y&lon=lon
printVarSummary(y)   


rc = regCoef(x, y(lat|:,lon|:,time|:) )   
rc!0   = "lat"    ; name dimensions
rc!1   = "lon"
rc&lat = y&lat   ; assign coordinate values to named dimensions
rc&lon = y&lon
printVarSummary(rc)           ; variable overview

tval = onedtond(rc@tval , dimsizes(rc))   ;t-statistic
df   = onedtond(rc@nptxy, dimsizes(rc)) - 2  ;自由度
b = tval    ; b must be same size as tval (and df)
b = 0.5
prob = betainc(df/(df+tval^2),df/2.0,b)       ; prob(nlat,nlon)
;print(prob)
prob!0   = "lat"    ; name dimensions
prob!1   = "lon"
prob&lat = y&lat   ; assign coordinate values to named dimensions
prob&lon = y&lon

rc@long_name   = "regression coefficient"
prob@long_name = "probability"


wks = gsn_open_wks("x11","regression")
gsn_define_colormap(wks,"BlWhRe")
res = True
res@gsnDraw = False
res@gsnFrame = False
res@cnInfoLabelOn = False
res@cnFillOn = True
res@cnLineLabelsOn = False
res@gsnSpreadColors = True
res@lbLabelBarOn = False
res@tiMainString = ""
res@gsnRightString = ""
res@cnLevelSelectionMode = "ManualLevels"
res@cnMinLevelValF = -2.
res@cnMaxLevelValF = 2.
res@cnLevelSpacingF = 0.2
res@mpCenterLonF = 180
plot1 = gsn_csm_contour_map_ce(wks,rc,res)

res2 = res
res2@gsnDraw         = False                      ; do not draw  
res2@gsnFrame        = False                      ; do not advance frame
res2@gsnMaximize           = True
res2@cnMonoFillPattern = False

res2@cnLevelSelectionMode = "ExplicitLevels"
res2@cnLevels = (/b/)     ;; set to significance level
res2@cnFillPatterns = (/3/)   
res2@gsnLeftString = ""
plot3 = gsn_csm_contour(wks,prob,res2)

overlay(plot1,plot3)

end


密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-3-30 10:39:21 | 显示全部楼层
其实是不是直接画tval  而不是概率prob。因为tval就是每个格点的t检验值,我们可以查T分布表(自由度、0.05)而确定临界tval ,进而画图。
plot2 = gsn_csm_contour(wks,tval,res2)
opt = True
opt@gsnShadeFillType = "pattern"      ; pattern fill  
opt@gsnShadeLow = 17
opt@gsnShadeHigh = 17                        ; use pattern #17       
opt@gsnLeftString       = "  "
opt@gsnRightString       = "  "
opt@cnLinesOn             = False            ; turn off contour lines
opt@cnLineLabelsOn        = False            ; turn off contour line labels
plot2 = gsn_contour_shade(plot2,-2.0,2.0,opt)  
  overlay(plot1,plot2)
  draw(plot1)
  frame(wks)

end

你觉得这样可行?
密码修改失败请联系微信:mofangbao
回复 支持 3 反对 0

使用道具 举报

新浪微博达人勋

发表于 2015-4-26 10:28:47 | 显示全部楼层
我觉得那个函数是没有T检验分布表,不知道T检验值的时候使用的。
df   = 20
  tval = 2.08  
  prob = betainc( df/(df+tval^2), df/2.0, 0.5)
  print ("prob="+prob)
就如这个例子,算出的概率值是0.05,也就是我们通常说的95%的信度检验。刚好自由度20,0.05置信区间对应的t检验值tval就是2.08(查t分布表可得) 。

     也是个人的一些见解,希望大家讨论讨论,把这个问题解决掉。
密码修改失败请联系微信:mofangbao
回复 支持 2 反对 0

使用道具 举报

新浪微博达人勋

发表于 2015-4-26 11:30:22 | 显示全部楼层
听雨轩 发表于 2015-4-26 10:28
我觉得那个函数是没有T检验分布表,不知道T检验值的时候使用的。
df   = 20
  tval = 2.08  

谢谢解答
我的理解是,那么也可以直接画prob的值,然后shade小于0.05值的范围,这个范围就是通过95%显著性t检验的区域了,这样就可以免去查询不同自由度对应的临界t检验值了
不知道理解的是否正确

PS:prob = betainc(df/(df+tval^2),df/2.0,b) 这里的b的值为什么是 0.5
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

发表于 2015-3-28 10:01:12 | 显示全部楼层
我每次都是算相关系数作检验用的,进来学习学习
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-3-31 19:20:49 | 显示全部楼层
听雨轩 发表于 2015-3-30 10:39
其实是不是直接画tval  而不是概率prob。因为tval就是每个格点的t检验值,我们可以查T分布表(自由度、0.05 ...

{:lol:}可行~~ 谢啦~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-6 22:07:36 | 显示全部楼层
学习学习!!!!!
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2015-4-8 21:34:25 | 显示全部楼层
好               
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-25 23:28:30 | 显示全部楼层
听雨轩 发表于 2015-3-30 10:39
其实是不是直接画tval  而不是概率prob。因为tval就是每个格点的t检验值,我们可以查T分布表(自由度、0.05 ...

如果是直接使用回归变量的属性中t统计量值比较其自由度和0.05查t检验表来确定显著性的格点的话

那么prob = betainc(df/(df+tval^2),df/2.0,b) 这个函数就没有使用到的,看官网的例子里是计算

betainc这个函数,还是没明白这里的回归是怎么检验的,谢谢
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-26 11:19:33 | 显示全部楼层
用rtest这个函数来检验貌似更简单吧。
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表