I was plotting 2 cumulative distribution for 2 columns of data in a dataframe. my code is:
library(EnvStats)
cdfCompare(Ratio1,Ratio2 discrete = FALSE,
prob.method = ifelse(discrete, "emp.probs", "plot.pos"), plot.pos.con = NULL,
distribution = "norm", param.list = NULL,
estimate.params = is.null(param.list), est.arg.list = NULL,
x.col = "blue", y.or.fitted.col = "black",
x.lwd = 3 * par("cex"), y.or.fitted.lwd = 3 * par("cex"),
x.lty = 1, y.or.fitted.lty = 2, digits = .Options$digits,
type = ifelse(discrete, "s", "l"), main = NULL, xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL)
When I ran this code an error was generated:
Error in ifelse(discrete, "emp.probs", "plot.pos") :
object 'discrete' not found
When I use a shorter code:
cdfCompare(Ratio1,Ratio2 discrete = FALSE)
There is no error. I also tried to set
discrete=TRUE
, it looks it does not affect the shape of the plotting (not smooth, I have ~170,000 values). Thank you very much.
You can define a separate variable to pass discrete value and use if
/else
to select prob.method
.
discrete_value <- FALSE
cdfCompare(Ratio1,Ratio2 discrete = discrete_value,
prob.method = if(discrete_value) "emp.probs" else "plot.pos", plot.pos.con = NULL,
distribution = "norm", param.list = NULL,
estimate.params = is.null(param.list), est.arg.list = NULL,
x.col = "blue", y.or.fitted.col = "black",
x.lwd = 3 * par("cex"), y.or.fitted.lwd = 3 * par("cex"),
x.lty = 1, y.or.fitted.lty = 2, digits = .Options$digits,
type = ifelse(discrete, "s", "l"), main = NULL, xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL)