我有这个离散数据,我想做一个样本 kolmogorov smirnov 测试但是当我运行以下代码时它给了我一个错误
d <- c(5, 11, 21, 31, 46, 75, 98, 122, 145, 165, 196, 224, 245, 293,321, 330, 350, 420)
#log likelihood function for the discrete distribution
#*********************************************************
loglik <-function(param){
q <- param[1]
if(q<=0){return(NaN)}
b <- param[2]
if(b<=0){return(NaN)}
c <- param[3]
if(c<=0){return(NaN)}
sum(log((q^(sqrt(d)*(1+b*c^d)))-(q^(sqrt(d+1)*(1+b*c^(d+1))))))
}
# maximum likelihood estimation using maxLik function
#*****************************************************
library(maxLik)
mle <- maxLik(loglik, start=c(q=0.9658,b=0.1237,c=1.0086), control=list(printLevel=2))
# the cumulative distribution function of the discrete distribution
#*******************************************************************
cdf <- function(param){
if(q<=0){return(NaN)}
b <- param[2]
if(b<=0){return(NaN)}
c <- param[3]
if(c<=0){return(NaN)}
cdf= 1-q^(sqrt(d)(1+b*c^d))
}
#one-sample kolmogorov smirnov test
#**********************************
ks<- ks.test(d, cdf, q=coef(mle)[1], b=coef(mle)[2], c= coef(mle)[3] )
错误:
Error in y(sort(x), ...) :
unused arguments (q = coef(mle)[1], b = coef(mle)[2], c = coef(mle)[3])
当我尝试测试 cdf 函数时,
cdf(q=2,b=3,c=3)
R给我以下错误
Error in cdf(q = 2, b = 3, c = 3) :
unused arguments (q = 2, b = 3, c = 3)
我认为 ks.test 中的错误来自错误的累积分布函数。