[英]Kolmogorov-Smirnov test using L-moments instead of mle estimates in R
I am trying to perform a KS test to assess the suitability of fitting a Pearson III distribution to my data. 我正在尝试进行KS测试,以评估将Pearson III分布拟合到我的数据中的适用性。 Using mle implemented in fitdist
from the fitdistrplus
package we obtain parameter estimates which can be directly plugged into ks.test
: 使用从fitdistrplus
包在fitdist
实现的mle,我们可以获得可以直接插入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. 另外:我知道使用数据中的参数估计值执行KS测试会使测试无效。 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: 现在,计算L矩:
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. ks.test
需要使用pgamma3
函数,该函数仅接受shape
, scale
和thres
参数。 My question is how can I adapt ks.test
to use the L-moments rather than the mle estimates? 我的问题是我如何才能使ks.test
使用L矩而不是mle估计?
you can choose one of this solution 1. define function in fitdistrplus using lmomco and then perform the test. 您可以选择以下解决方案之一:1.使用lmomco在fitdistrplus中定义函数,然后执行测试。 in this case you will perform the test directly with (mu,sigma,gamma) 2. estimate the (scale shape location) parameter using lmoment 在这种情况下,您将直接使用(mu,sigma,gamma)2进行测试。使用lmoment估计(刻度形状位置)参数
`library("lmomco")
library("fitdistrplus")
lmompe3 <-lmoms(X, nmom = 5)
parape3 <- parpe3(lmompe3, checklmom=TRUE)
dpe3 <- function(x,mu,sigma,gamma ){pdfpe3(x,list(type="pe3",para=c(mu,sigma,gamma),source="parpe3"))}
ppe3 <- function(q,mu,sigma,gamma ) {cdfpe3(q,list(type="pe3",para=c(mu,sigma,gamma),source="parpe3"))}
qpe3 <- function(p,mu,sigma,gamma ) {quape3(p,list(type="pe3",para=c(mu,sigma,gamma),source="parpe3"))}
ks.test(X, "ppe3",mu, sigma, gamma)
library("nsRFA")
library("fitdistrplus")
l_mom <- Lmoments(X) #nsRFA package
lmompe3 <-lmoms(X, nmom = 5) #Lmomco package
# 2. Find parameter from lmoment
parameters <- par.gamma(l_mom[1],l_mom[2],l_mom[4]) #nsRFA package
# 3. find mu sigma gamma parameter
mu_sigma_gamma <- par2mom.gamma(parameters$alfa,parameters$beta,parameters$xi); mu_sigma_gamma
parape3 <- parpe3(lmompe3, checklmom=TRUE);parape3#Lmomco package
ks.test(X, "pgamma3", shape=alpha,scale=beta,thres=xi)`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.