shabbychef / sadists

Some Additional Distributions R package
GNU Lesser General Public License v3.0
8 stars 0 forks source link

dsumchisqpow gets wild with df=1, ncp=0 and pow=1 #4

Open mauimuc opened 8 years ago

mauimuc commented 8 years ago

With ncp=0 and pow=1 the non-central becomes the central chi-square. However, for small degrees of freedom dsumchisqpow yields weird values.

Simply try

x = seq(0, 10, len=500)
plot(x, dchisq(x=x, df=1), type='l', col='green', ylim=0:1)
lines(x, dsumchisqpow(x=x, ncp=0, wts=1, df=1, pow=1))

for a comparison. I just realized that order.max has a huge impact. I run sadists 0.2.1.

shabbychef commented 8 years ago

Probably changing the underlying 'basis' to gamma will improve the fit. This relies on some changes in the PDQutils package, which I am still working on. Thanks for submitting the issue; I will get to this.

shabbychef commented 8 years ago

to wit:

require(sadists)
require(PDQutils)
# compute cumulants
cumuls <- sadists:::sumchisqpow_cumuls(wts=1,ncp=0,df=1,pow=1,order.max=5)
# turn into raw moments
moms <- PDQutils::cumulant2moment(cumuls)
# use the Gram Charlier with 'gamma' basis:
x <- seq(0,1,len=500)
plot(x, dchisq(x=x, df=1), type='l', col='green', ylim=0:1)
lines(x, dapx_gca(x=x,raw.moments=moms,support=c(0,100),basis='gamma'))