How to generate using Gauss command for a normal distribution with any mean and variance?
To compute random numbers which are normally distributed with a mean
mu and variance
sigma, you multiply the result of
rndn by the square root of
sigma and adding
mu like this:
// Mean of random numbers mu = 8.2; // Variance of random numbers sigma2 = 5.4; // Number of observations to create nobs = 1e6; // Create random numbers N(mu, sigma2) X = rndn(nobs, 1) * sqrt(sigma2) + mu; print meanc(X); print varCovXs(X);
The above code should create random normal numbers with a mean near 8.2 and a variance near 5.4. If you want to be able to make some reusable code, you could create a procedure like this:
x = rndn2(100, 1, 0.5, 1.4); proc (1) = rndn2(nobs, c, mu, sigma2); retp(rndn(nobs, c) * sqrt(sigma2) + mu); endp;
Thanks. Where does the “mu “ enter into this command in your first code? I cannot see anything after “sig”.