Re: cumulative distribution functions

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 10 Aug 2006 16:58:05 -0600 (MDT)

>I'm trying to plot two cumulative distribution functions for two
>different data sets in one plot using cdfnor_p. However, if I try to
>plot this as two single functions, I get a complicated array of lines.
>Any suggestions? Am I misusing this function?
>
>Thanks-
>
>Allison
>
>
>;***********************************************
>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>;************************************************
>begin
>;************************************************
>; read in 2D data
>;************************************************
>
>irr25 = addfile("r25irr.nc","r")
>irr39 = addfile ("../cctm_RUN39/run39irr.nc","r")
>avoc1 = irr25->lAVOCnet
>avoc2 = irr39->lAVOCnet
>
>;************************************************
>; make data 1d
>;************************************************
>
>avoc11d = (ndtooned(avoc1))*1000.
>avoc21d = (ndtooned(avoc2))*1000.
>
>cdf1 = new(dimsizes(avoc11d),float)
>mean1 = new(dimsizes(avoc11d),float)
>sd1 = new(dimsizes(avoc11d),float)
>mean1 = dim_avg(avoc11d)
>sd1 = dim_stddev(avoc21d)
>cdf1 = cdfnor_p(avoc11d,mean1,sd1)
>
>cdf2 = new(dimsizes(avoc11d),float)
>mean2 = new(dimsizes(avoc11d),float)
>sd2 = new(dimsizes(avoc11d),float)
>mean2 = dim_avg(avoc21d)
>sd2 = dim_stddev(avoc21d)
>cdf2 = cdfnor_p(avoc21d,mean2,sd2)
>
>;************************************************
>; define output arrays
>;************************************************
>avocout = new((/2,dimsizes(cdf1)/),float)
>
>avocout(0,:) = cdf1(:)
>avocout(1,:) = cdf2(:)
>
>;************************************************
>; plotting parameters
>;************************************************
>wks = gsn_open_wks ("x11","fig9")
>
>res = True ; plot mods desired
>res_at_xyLineColors = (/"blue","green"/) ; line color
>
>plot = gsn_csm_xy(wks,avoc11d,avocout,res)
>
>end
>_______________________________________________
_______________________________________________

After some offline emails, two solutions were offered:

[1] I suggested that a histogram approach could be used
    to display the pdf.
    
    mean1 = avg(avoc11d)
    sd1 = stddev(avoc11d)
    cdf1 = cdfnor_p(avoc11d, conform(avoc11d,mean1,-1) \
                              , conform(avoc11d,sd1 ,-1) )
    mean2 = avg(avoc21d)
    sd2 = stddev(avoc21d)
    cdf2 = cdfnor_p(avoc21d, conform(avoc21d,mean2,-1) \
                          , conform(avoc21d,sd2 ,-1) )
  [snip]
    dimcdf1 = dimsizes( cdf1 )
    dimcdf2 = dimsizes( cdf2 )

    dimz = max( (/dimcdf1, dimcdf2 /) )

    z = new((/2,dimz/),float)
    z(0,0:dimcdf1-1) = cdf1
    z(1,0:dimcdf2-1) = cdf2

    resc = True
    resc_at_gsnHistogramCompare = True
    resc_at_gsnHistogramComputePercentages = True
    resc_at_tiMainString = "CDF: "+fil1 + " vs "+fil2
    plt = gsn_histogram(wks,z,resc)

[2] A coworker of Allison's suggested sorting the original
    array before using the cdf function.

    qsort(avoc11d)
    
    cdf1 = new(dimsizes(avoc11d),float)
    mean1 = new(dimsizes(avoc11d),float)
    sd1 = new(dimsizes(avoc11d),float)
    mean1 = dim_avg(avoc11d)
    sd1 = dim_stddev(avoc11d)
    cdf1 = cdfnor_p(avoc11d,mean1,sd1)

    Then cdf can be plotted as a continual line.

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Aug 10 2006 - 16:58:05 MDT

This archive was generated by hypermail 2.2.0 : Fri Aug 18 2006 - 10:43:09 MDT