[ncl-talk] partial correlation

Saji Hameed saji.nh at gmail.com
Tue Oct 21 23:17:15 MDT 2014


Hi Erika,

Hopefully the following is helpful.  It returns both partial and part
correlations, but if you want
you can ask for only one of them to be returned using the optional argument
"opt"

e.g opt=True
      opt at partialcorrelation=True

saji
--

function mreg_part_corr(x1,x2,y,opt)
local opt
begin
  x1x2 = escorc(x1,x2)
  tol = sqrt(1-x1x2^2)

  nx1 = dimsizes(x1)
  X = new( (/3,nx1/), float)
  X(0,:) = 1.0
  X(1,:) = x1
  X(2,:) = x2

  beta = reg_multlin(y, X, False)
  dreg = beta(1)
  nreg = beta(2)

  Xstd = dim_stddev(X)
  Ystd = stddev(y)
  XstdYstd = Xstd/Ystd
  B = beta*XstdYstd
  B(0) = 0.0
  part_corr_x1 = B(1)*tol
  part_corr_x2 = B(2)*tol
  partial_corr_x1 = part_corr_x1/sqrt((1-(escorc(y,x2))^2))
  partial_corr_x2 = part_corr_x2/sqrt((1-(escorc(y,x1))^2))
  if opt .and. isatt(opt,"part_correlation")
    if opt at part_correlation
    return((/part_corr_x1, part_corr_x2/))
    end if
end if
  if opt .and. isatt(opt,"partal_correlation")
    if opt at partial_correlation
      return((/partial_corr_x1, partial_corr_x2/))
    end if
  end if
  res=(/partial_corr_x1,partial_corr_x2,part_corr_x1,part_corr_x2/)
  return(res)
end


On Tue, Oct 21, 2014 at 3:13 AM, Erika Folova <e.folova at gmail.com> wrote:

> Hallo NCL users,
>
> Anyone try to compute the partial correlation, e.g.,  between a and b
> excluding the effect of c ?
> Thank you
>
> Erika,
>
> _______________________________________________
> ncl-talk mailing list
> 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/20141022/c290f893/attachment.html 


More information about the ncl-talk mailing list