After searching the forum, I did not find similair questions. If you find one, please let me know. I would really appreciate.

In R, I need to check the return values from function Gammad and Truncate (from lib distr and truncdist).

It means that if they fail to generate the Gammad and Truncate pdf, a fail value or exception can be returned so that I can handle it.

   G0 <- Gammad(scale = s, shape = sh) 
   # what if Gammad() fails ? 
   TG <- Truncate(G0, lower = lowerbound, upper = upperbound) 
   # what if Truncate() fails ? 

Thanks !

有帮助吗?

解决方案

From the rgamma help page: "Invalid arguments will result in return value NaN, with a warning."

If this is what you see, you could use

ow <- options("warn")
options(warn=2)
G0 <- try(Gammad(scale = s, shape = sh), silent=TRUE)
if(inherits(G0, "try-error")) # handle invalid arguments
options(warn=ow)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top