StatsChiTest P calculation

In the results of StatsChiTest in W_StatsChi table,

StatsChiTest/T=1/S exg,ggg

n 200
df 199
Chi_Squared 0
Critical 232.912
P 1


How does Igor Pro calculate the value for P?
Supriya Balaji wrote:
In the results of StatsChiTest in W_StatsChi table,
How does Igor Pro calculate the value for P?


Here is some code that appears to reproduce the values calculated by StatsChiTest/S:
Function ChiSqTest()
    // make some fake data
    Make/O/I/U/N=(200) wObserved, wExpected
    wExpected[] = 100 + 10 * sin(x/10)
    wObserved[] = wExpected[p] + gnoise( sqrt(wExpected[p]) )
    // plot data
    Display  wExpected, wObserved
    ModifyGraph mode(wObserved)=3,marker(wObserved)=1,msize(wObserved)=0.5
    ModifyGraph rgb(wObserved)=(0,12800,52224)
    // Run test
    StatsChiTest/T=1/S wObserved, wExpected
    // manually compute values
    Variable vNum = DimSize(wObserved, 0)
    Print "Num:", vNum
    Variable vDoF = DimSize(wObserved, 0) - 1  // Degrees of Freedom
    Print "DoF:", vDoF
        // Chi_Squared:
    Make/O/D/N=(DimSize(wObserved, 0)) wChiSqSum
    wChiSqSum[] = ( (wObserved[p] - wExpected[p])^2 ) / wExpected[p]
    Variable vChiSq = sum(wChiSqSum)
    print "ChiSq:", vChiSq
        // Critical Value
    print "Critcial Value:", StatsInvChiCDF(0.95, 199)
        // p-value
    print "p:", 1 - StatsChiCDF(vChiSq, vDoF)
End

Hope this helps,
Kurt