I want to randomly generate 1000 normal variates (using rnorm
, e.g.) that have mean 100. 25% of the 1000 numbers should be over 110.
How can I do this in R
?
I only got this far:
x <- rnorm(1000,100,1)
I want to randomly generate 1000 normal variates (using rnorm
, e.g.) that have mean 100. 25% of the 1000 numbers should be over 110.
How can I do this in R
?
I only got this far:
x <- rnorm(1000,100,1)
Just like mentioned in comments, we have the quantile function
$F^{-1}(p;\,\mu,\sigma^2) = \mu + \sigma\Phi^{-1}(p) = \mu + \sigma\sqrt2\operatorname{erf}^{-1}(2p - 1), \quad p\in(0,1)$
in this case
$110=F^{-1}(0.75;\,100,\sigma^2) = 100 + \sigma\Phi^{-1}(0.75)$
So $\sigma$ is all we need:
sd <- 10 / qnorm(0.75)
quantile(rnorm(10000, mean = 100, sd = sd), 0.75)
75%
110.0221
You can draw random numbers until you hit a distribution you like:
while ( TRUE ) {
x <- rnorm(1000,100,1)
if ( sum(x>110) > 25 ) break
}
However, note that you will usually only expect an infinitesimal number of your values to be more than ten standard deviations above the mean, so you will have to wait quite a bit... and the result will be so atypical that I would hesitate to label it "a set of normally distributed random numbers of which 25% just happened to be larger than 110".