-1

I am using the function plkhci from library Bhat to construct Profile-likelihood based confidence intervals and I got this warning:

Warning message: In dqstep(list(label = x$label, est = btrf(xt, x$low, x$upp), low = x$low, : oops: unable to find stepsize, use default

when i run

r <- dfp(x,f=nlogf)

Can I ignore this warning as I still can get the output?

Following is the complete coding:

library(Bhat)
beta0<--8
beta1<-0.03
gamma<-0.0105
alpha<-0.05
n<-100
u<-runif(n)
u
x<-rnorm(n)
x
c<-rexp(100,1/1515)
c
t1<-(1/gamma)*log(1-((gamma/(exp(beta0+beta1*x)))*(log(1-u))))
t1
t<-pmin(t1,c)
t
delta<-1*(t1>c)
delta
length(delta)
cp<-length(delta[delta==1])/n
cp
delta[delta==1]<-ifelse(rbinom(length(delta[delta==1]),1,0.5),1,2)
delta
deltae<-ifelse(delta==0, 1,0)
deltar<-ifelse(delta==1, 1,0)
deltai<-ifelse(delta==2, 1,0)
dat=data.frame(t,delta, deltae,deltar,deltai,x)
dat$interval[delta==2] <- as.character(cut(dat$t[delta==2], breaks=seq(0, 600, 100)))
labs <- cut(dat$t[delta==2], breaks=seq(0, 600, 100))
dat$lower[delta==2]<-as.numeric( sub("\\((.+),.*", "\\1", labs) )
dat$upper[delta==2]<-as.numeric( sub("[^,]*,([^]]*)\\]", "\\1", labs) )  
data0<-dat[which(dat$delta==0),]#uncensored data 
data1<-dat[which(dat$delta==1),]#right censored data 
data2<-dat[which(dat$delta==2),]#interval censored data 
nlogf<-function(para)
{
  b0<-para[1]
  b1<-para[2]
  g<-para[3]
  e<-sum((b0+b1*data0$x)+g*data0$t+(1/g)*exp(b0+b1*data0$x)*(1-exp(g*data0$t)))
  r<-sum((1/g)*exp(b0+b1*data1$x)*(1-exp(g*data1$t)))
  i<-sum(log(exp((1/g)*exp(b0+b1*data2$x)*(1-exp(g*data2$lower)))-exp((1/g)*exp(b0+b1*data2$x)*(1-exp(g*data2$upper)))))
  l<-e+r+i
  return(-l)
}
x <- list(label=c("beta0","beta1","gamma"),est=c(-8,0.03,0.0105),low=c(-10,0,0),upp=c(10,1,1))
r <- dfp(x,f=nlogf)
x$est <- r$est
plkhci(x,nlogf,"beta0")
plkhci(x,nlogf,"beta1")
plkhci(x,nlogf,"gamma")
yap
  • 61
  • 6

1 Answers1

0

I am giving you a super long answer, but it will help you see that you can chase down your own error messages (most of the time, sometimes this means of looking at functions will not work). It is good to see what is happening inside a method when it throws an warning because sometimes it is fine and sometimes you need to fix your data.

This function is REALLY involved! You can look at it by typing dfp into the R command line (NO TRAILING PARENTHESES) and it will print out the whole function.

17 lines from the end, you will see an assignment:

del <- dqstep(x, f, sens = 0.01)

You can see that this calls the function dqstep, which is reflected in your warning.

You can see this function by typing dqstep into the command line of R again. In reading through this function, also long but not so tedious, there is this section of boolean logic:

if (r < 0 | is.na(r) | b == 0) {
        warning("oops: unable to find stepsize, use default")
        cat("problem with ", x$label[i], "\n")
        break
    }  

This is the culprit, it returns the message you are getting. The line right above it spells out how r is calculated. You are feeding this function your default x from the prior function plus a sensitivity equations (which I assume dfp generates, it is huge and ugly, so I did not untangle all of it). When the previous nested function returns either an r value lower than Zero, and r value of NA or a b value of ZERO, that message is displayed.

The second error tells you that it was likely b==0 because b is in the denominator and it returned and infinity value, so NO STEP SIZE IS RETURNED FROM THIS NESTED FUNCTION to the variable del in dfp.

The step is fed into THIS equation:

h <- logit.hessian(x, f, del, dapprox = FALSE, nfcn)  

which you can look into by typing logit.hessian into the R commandline.

When you do, you see that del is a step size in a logit scale, with a default value of del=rep(0.002, length(x$est))...which the function set for you because running the function dqstep returned no value.

So, you now get to decide if using that step size in the calculation of your confidence interval seems right or if there is a problem with your data which needs resolving to make this work better for you.

When I ran it, line by line, I got this message:

Error in if (denom <= 0) { : missing value where TRUE/FALSE needed

at this line of code: r <- dfp(x,f=nlogf(x))

Which makes me think I was correct.

That is how I chase down issues I have with messages from packages when I get a message like yours.

sconfluentus
  • 4,693
  • 1
  • 21
  • 40
  • 1
    i saw another section with similar warning `if (is.na(f2)) f2 <- Inf if (f2 == Inf | f2 == -Inf) { warning("oops: unable to find stepsize, use default") break }`. my warning appeared only got `"oops: unable to find stepsize, use default"` , without `problem with ", x$label[i], "\n`. so is my warning caused by this instead of the one u mentioned? – yap Jan 19 '18 at 08:00
  • what do you mean by **you now get to decide if using that step size in the calculation of your confidence interval seems right** . How should i decide? – yap Jan 19 '18 at 08:08
  • For the lower bound and upper bound in the list of x: `x <- list(label=c("beta0","beta1","gamma"),est=c(-8,0.03,0.0105),low=c(-10,0,0),upp=c(10,1,1))`, do you know how should I decide the lower and upper bound? because I realised different value will produce slightly different confidence interval. – yap Jan 19 '18 at 08:14
  • The error part could be either, but it appears that they are saying the same thing because a division by zero error may throw and infinity value depending on how the sub function is written. As for the step size, this series of functions allows YOU to affect how intervals are calculated based on your submitted data. If your data does not allow one to be calculated you either need to expressly set a default value, or accept the step listed as default. The decision on how to move forward has everything to do with your data, its use, industry standards. There is no simple answer. – sconfluentus Jan 19 '18 at 23:45
  • It seems like you are working with a regression equation. But you are also entering values manually...so it is unclear where the values come from....these questions are not really R related, but more statistics related and extremely domain specific. You might want to reach out to someone in your field and talk about how to proceed... – sconfluentus Jan 19 '18 at 23:47
  • I have found a way to find the lower and upper bound where `low=c(-8.1,-0.29,-0.09),upp=c(-7.6,0.31,0.11))` but then I got an error `Error in if (any((x - xl) <= 0)) stop("ftrf requires x > xl") : missing value where TRUE/FALSE needed` although my **x** all are greater than **xl**. Any idea for this error? – yap Jan 21 '18 at 08:19
  • try entering `frtf` in the r console and looking at the function & equation to see what it is attempting and see if at that point in the process your data does not fit the process properly. – sconfluentus Jan 22 '18 at 11:33
  • I have already tried.... . this comes out: function (x, xl, xu) `{ if (any((x - xl) <= 0)) stop("ftrf requires x > xl") if (any((xu - x) <= 0)) stop("ftrf requires x < xu") return(log((x - xl)/(xu - x))) } > ` – yap Jan 22 '18 at 13:23
  • but my `x` in the list is all greater than `xl`. thats why i dont know whats wrong.... – yap Jan 22 '18 at 13:24
  • Don't know what to tell you, you will likely have to chase it down from function to function, trying small sets of data until you figure out what the trigger is and why it is giving you an error. Or you will need to write your own functions to do this task...then you will know why things happen. – sconfluentus Jan 22 '18 at 23:56