I am trying to find the power values with fzero function in R using myfunction in the following way:
myfunction = function(delta,data,cv){
if(mean(data^delta)!=0)
y=cv-sd((data^delta),na.rm=TRUE)/mean((data^delta),na.rm=TRUE)
return(y)}
b=repmat(NaN,12,Nest)
for (m in 1:12) {
if (m==1)
indDates=which(is.element(month, c(12, 1, 2)))
else if (m==12)
indDates=which(is.element(month, c(11, 12, 1)))
else
indDates=which(is.element(month, c(m-1, m, m+1)))
cvO=apply(prO[indDates,],2,sd,na.rm=TRUE)/colMeans(prO[indDates,], na.rm=TRUE)
for (i in 1:Nest) {
if (!is.na(cvO[i]))
b[m,i]=fzero(function(x) myfunction(x,abs(prM[indDates,i]),cvO[i]),1)
}
}
But I get the following error message: Error in if (fb == 0) return(list(x = b, fval = fb)) : missing value where TRUE/FALSE needed I do not understand what is the matter and how I should fix it? Could someone please help me?