Norm (not standard normal) random variable?

How to generate using Gauss command for a normal distribution with any mean and variance?

2 Answers



0



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;

aptech

1,773


0



Thanks. Where does the “mu “ enter into this command in your first code? I cannot see anything after “sig”.

ray

0

Your Answer

2 Answers

0

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;

0

Thanks. Where does the “mu “ enter into this command in your first code? I cannot see anything after “sig”.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy