I want to generate random numbers from chi-square distribution with 3 degrees of freedom but shifted to the left . I mean the shifted distribution function f(x-a) a is the amoun
Let's look at the Chi-square distribution with 3 degrees of freedom:
x_vals <- seq(0, 10, 0.1)
plot(x_vals, dchisq(x_vals, 3), type = "l",
main = "Chi Squared distribution of x with 3 DOF")
Now let's shift it to the left by a constant a
. We'll plot a vertical line at x = 0 to emphasize the shift:
a <- 2
plot(x_vals - a, dchisq(x_vals, 3), type = "l",
main = "Chi Squared distribution of x - 2 with 3 DOF")
abline(v = 0, lty = 2)
This is the distribution from which you wish to sample. That being the case, we need only sample from the Chi-square distribution and subtract a
from each element drawn. In R this is as easy as doing rchisq(n, 3) - a
where n
is the desired sample size.
To demonstrate, here is a histogram of 10,000 samples drawn from this distribution:
hist(rchisq(10000, 3) - a, breaks = 100, xlim = c(-2, 8),
main = "10,000 samples from Chi Square distribution of (x - 2) with 3 DOF")