Statistics Inverse Method in Rstudio

366 Views Asked by At

I have a problem.

I have to generate 10.000 random variables using the inverse method for Logistic distribution and Cauchy distribution.

I know their corresponding probability density functions and distribution functions, and I think I have to calculate with hand on paper the inverse of F(x) for each one, right? But I have no idea how to write it in Rstudio.

Please, help me!

1

There are 1 best solutions below

1
On BEST ANSWER

I'm not sure about the context (e.g. is this homework?) For most common probability distributions, R has built-in functions for

  • CDF (p***, e.g. pnorm()
  • probability distribution/density function (d***, e.g. dnorm())
  • inverse CDF/quantile function (q***, e.g. qnorm())
  • random deviate generator (r***, e.g. rnorm())

You do have to know that the suffixes for Cauchy and logistic are cauchy and logis. If you ever need an exhaustive list of probability distribution implementations in R, you can see the probability distributions task view ...

The random deviate generators usually have good/special purpose algorithms, which are often better (more efficient) than the inverse method. So the most efficient way to generate random deviates for the logistic and Cauchy distributions would be to use the rlogis() and rcauchy() functions, respectively. But if you insist on using the inverse method, qlogis(runif(10000),...) or qcauchy(runif(10000),...) would do what you want (... would be optional parameter values: looking at ?qlogis, ?qcauchy, both distributions use location parameter 0 and scale parameter 1 by default).