[ncl-talk] Question about regressing a time series and a gridded data using regCoef_n

Dennis Shea shea at ucar.edu
Thu Jun 22 07:56:52 MDT 2017


[SNIP]
 dimsst = dimsizes(sst)
 ntim   = dimsst(0)
 nlat   = dimsst(1)
 mlon   = dimsst(2)

;****************************************************
;Calculate Regression coefficient via regCoef_n
;****************************************************

 rc = regCoef_n(data,sst,0,0)
 printVarSummary(rc)       ;(nlat,mlon)
                           ;[1D arrays]: nptxy,rstd,yintercept,tval

;;Variable: rc
;;Type: float
;;Total Size: 259200 bytes
;;            64800 values
;;Number of Dimensions: 2
;;Dimensions and sizes: [180] x [360]
;;Coordinates:
;;Number Of Attributes: 5
;;  _FillValue :        -1e+30
;;  nptxy :     <ARRAY of 64800 elements>
;;  rstd :      <ARRAY of 64800 elements>
;;  yintercept :        <ARRAY of 64800 elements>
;;  tval :      <ARRAY of 64800 elements>

;****************************************************
;Assign coordinates
;****************************************************
 rc!0 = "lat"
 rc!1 = "lon"
 rc&lat = sst&lat
 rc&lon = sst&lon

;****************************************************
;Test for significance
;****************************************************
 df   = onedtond(rc at nptxy-2, (/nlat,mlon/))   ; degrees of freedom
 tval = onedtond(rc at tval   , (/nlat,mlon/))   ; t-statistic
[SNIP]


The latter is what Will was suggesting.

On Thu, Jun 22, 2017 at 4:28 AM, Lyndon Mark Olaguera <
olagueralyndonmark429 at gmail.com> wrote:

> Dear Sir Will and NCL experts,
>
> I still get the same error *(fatal:where: dimension sizes  of parameter 0
> and parameter 2 do not match)*. I am not sure if I am implementing this
> correctly.
>
> I changed this part in my code based on the suggestion suggestion:
>
> ;****************************************************
> ;Test for significance
> ;****************************************************
>  df = rc at nptxy-2                 ; degrees of freedom
>  tval = rc at tval                  ; t-statistic
>  b = tval                        ; b must be same size as tval (and df)
>  b = 0.5
>  prob = betainc(df/(df+tval^2),df/2.0,b)
>  printVarSummary(prob);dim=1 size=64800
>
> * prob_test =onedtond(prob,(/2,64800/))*
> * printVarSummary(prob_test)*
>
>  rc95 = where(prob_test.lt.0.95,rc at _FillValue,rc)
>  copy_VarCoords(rc, rc95)
>  printVarSummary(rc95)
>
>
> I'll appreciate any suggestion on how I can do this correctly.
>
> Sincerely,
>
> *Lyndz*
>
> On Thu, Jun 22, 2017 at 3:34 PM, Will Hobbs <will.hobbs at utas.edu.au>
> wrote:
>
>> Change the dimensions of ‘prob’ so that it matches the dimensions of rc.
>>
>>
>>
>> You can do this using the onedtond() function; you’ll find a complete
>> description of this function on the NCL web page.
>>
>>
>>
>> Will
>>
>>
>>
>> *From: *<ncl-talk-bounces at ucar.edu> on behalf of Lyndon Mark Olaguera <
>> olagueralyndonmark429 at gmail.com>
>> *Date: *Thursday, 22 June 2017 at 4:28 PM
>> *To: *"ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
>> *Subject: *[ncl-talk] Question about regressing a time series and a
>> gridded data using regCoef_n
>>
>>
>>
>> Dear NCL experts,
>>
>>
>>
>> I am trying to calculate the linear regression coefficient between a
>> single time series and a gridded sst using the regCoef_n in ncl. I am using
>> ncl v.6.4.
>>
>>
>>
>> Attached is my script and the text file that I am regressing. Here is the
>> link to the sst data:
>>
>>
>>
>> [Link to the data]
>>
>> https://drive.google.com/file/d/0B9faET7Bc2o8TjNSWnd1ODREcVU
>> /view?usp=sharing
>>
>>
>>
>> What I wanted to do:
>>
>>
>>
>> 1. I want to extract and plot significant coefficients (above 95%
>> confidence level), so I have this line in the script:
>>
>>
>>
>>  df = rc at nptxy-2 ; degrees of freedom
>>
>>  tval = rc at tval ; t-statistic
>>
>>  b = tval ; b must be same size as tval (and df)
>>
>>  b = 0.5
>>
>> * prob = betainc(df/(df+tval^2),df/2.0,b) *
>>
>> * rc95 = where(prob.lt.0.95,rc at _FillValue,rc)*
>>
>>
>>
>> I encountered an error after this:
>>
>>
>>
>> *fatal:where: condition variable (parameter 0) dimension mismatch with
>> parameter 2*
>>
>>
>>
>> I understand that the *"prob"* variable has only one dimension and the "
>> *rc"* has 2 dimensions (lat & lon).
>>
>>
>>
>> Is it possible to assign coordinates to "prob" similar to "rc" other than
>> the copyVarCoords?
>>
>>
>>
>>
>>
>> I'll appreciate any suggestions on how to do this correctly.
>>
>>
>>
>>
>>
>> Sincerely,
>>
>>
>>
>> Lyndz
>>
>>
>>
>> University of Tasmania Electronic Communications Policy (December, 2014).
>> This email is confidential, and is for the intended recipient only.
>> Access, disclosure, copying, distribution, or reliance on any of it by
>> anyone outside the intended recipient organisation is prohibited and may be
>> a criminal offence. Please delete if obtained in error and email
>> confirmation to the sender. The views expressed in this email are not
>> necessarily the views of the University of Tasmania, unless clearly
>> intended otherwise.
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170622/dc77f664/attachment.html 


More information about the ncl-talk mailing list