有人能用这个小功能来帮助我吗?
opt <- function( x, shape, scale){
k=shape
wpd1=0.3395
wpd2=c()
for(i in 1:101){
wpd = mean((k/scale) * x^k)
if(wpd==wpd1){wpd2=wpd}else{k=k+(i-1)/100 -0.5}
}
return(wpd2)
}
当我使用opt(rnorm(10),2,3)
时,我收到错误:
Error in if (wpd == wpd1) { : missing value where TRUE/FALSE needed
答案 0 :(得分:0)
将mean((k/scale) * x^k)
更改为mean((k/scale) * x^k, na.rm = TRUE)
您在运行(-#)^(2/3)