Jamie Carr
Jamie Carr

Reputation: 113

quantile function given a distribution that is not in r

I am trying to produce a quantile function(f_q) for a given distribution. Here are my codes:

library(GoFKernel)

f_cdf <- function(x) {
  integrate(fstar, 1e-10, x)$value/I
}
f_q <- inverse(f_cdf, lower=1e-10, upper=5-1e-10)

ggplot(x_plot, aes(sample=x))+
  labs(title="Empirical against theoretical quantiles")+
   stat_qq(distribution=f_q) +
   stat_qq_line(distribution=f_q)

When I do this, I get the following errors:

Computation failed in stat_qq(): unused argument (p = quantiles).
Computation failed in stat_qq_line(): unused argument (p = quantiles).

There is no problem when my codes for plotting and the samples I get from f. The reason is I can successfully get a ggplot when I changed 'distribution=f_q' to 'distribution=qnorm': the qqplot given a 'wrong' distribution

So, I can be sured that there are some bugs with my 'f_q', the quantile function. So, if there is anyone who knows about specific requirements for the 'distribution' parameter for stat_qq and stat_qq.line, that would be greatly helpful.

fstar is undefined at 0 and 5 and has a range between 0 and 5. I designed a rejection scheme to simulate from this distribution and I am trying to compare the theoretical quantiles and the sample quantiles by a quantile-quantile plot.

Upvotes: 1

Views: 622

Answers (1)

SmokeyShakers
SmokeyShakers

Reputation: 3412

Your formal for the distribution function may need to be named p. Try:

f_q_p <- function(p) { f_q(p) }

Then

ggplot(x_plot, aes(sample=x))+
  labs(title="Empirical against theoretical quantiles")+
   stat_qq(distribution=f_q_p) +
   stat_qq_line(distribution=f_q_p)

Upvotes: 1

Related Questions