I am trying to perform a KS test to assess the suitability of fitting a Pearson III distribution to my data. Using mle implemented in fitdist
from the fitdistrplus
package we obtain parameter estimates which can be directly plugged into ks.test
:
library(FAdist)
library(fitdistrplus)
> summary(x) #summary of my data vector
Min. 1st Qu. Median Mean 3rd Qu. Max.
144.8 646.0 1031.0 1130.0 1472.0 4283.0
fit.p3 <- fitdist(x, "gamma3", start=list(shape=1,scale=100, thres=100))
> fit.p3
Fitting of the distribution ' gamma3 ' by maximum likelihood
Parameters:
estimate Std. Error
shape 2.60075 0.2408922
scale 400.45463 28.5769539
thres 88.22411 29.6652668
> ks.test(x, "pgamma3", shape= fit.p3$estimate["shape"],
+ scale = fit.p3$estimate["scale"], thres = fit.p3$estimate["thres"])
One-sample Kolmogorov-Smirnov test
data: x
D = 0.0328, p-value = 0.2405
alternative hypothesis: two-sided
This works fine.
Aside: I am aware that performing a KS test using parameter estimates from the data invalidates the test. I have left out the simulation procedure I use to work around this to ensure the clarity of my question and simplicity of the code.
Now, calculating L-moments:
library(lmomco)
lmom <- lmom.ub(x)
para <- parpe3(lmom)
> para
$type
[1] "pe3"
$para
mu sigma gamma
1129.738563 628.035773 1.040752
$source
[1] "parpe3"
ks.test
requires using the pgamma3
function which only accepts shape
, scale
, and thres
arguments. My question is how can I adapt ks.test
to use the L-moments rather than the mle estimates?