1
$\begingroup$

Let X1,...,Xn be a random sample from the pdf

f(x)=(1/b)exp[-(x-a)/b], a< x< infinity, 0< b< infinity,

where a and b are location and scale parameter, respectively.

Now I have to generate X of 1000 observations from the pdf. I am a R user.

For initiate the problem, I set parameter values of a and b arbitrarily. But to generate the probability f(x), I need to set the values of x, but I have been asked to generate X from the pdf. It seems to calculate the probabilities f(x) and to generate the values of X are simultaneous work. How can I do that ?

$\endgroup$
4
  • $\begingroup$ (Trying not to give a complete solution to a homework problem:) The usual method to take a first stab at generating random variables (if prevented from using a built-in function) from a particular distribution is to invert the function to get a quantile function and then feed it random variates from the uniform distribution on the interval [0,1]. You can look at the shape of the distribution thereby produced using hist. hist( -log( runif(1000) ) ). I'm guessing this is homework from a mathematical statistics course and that you should demonstrate steps in getting to your final solution. $\endgroup$
    – DWin
    Commented Nov 30, 2015 at 2:19
  • 1
    $\begingroup$ Close vote on the hypothesis that this is request of stats advice. $\endgroup$
    – DWin
    Commented Nov 30, 2015 at 2:24
  • $\begingroup$ @42- hm, that's inversion method. $\endgroup$
    – user 31466
    Commented Nov 30, 2015 at 2:44
  • $\begingroup$ Yes, it is. What is your point? $\endgroup$
    – DWin
    Commented Nov 30, 2015 at 2:45

1 Answer 1

2
$\begingroup$

Well, that looks like exponential distribution

Use rexp function to generate vector with rate equal to 1/b and then shift the result by adding a.

Link: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Exponential.html

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.