0
$\begingroup$

I am defining a Normal Distribution in Octave by using this command "y = normpdf(x,0,2)". The standard deviation is 2 and x is independent uniform variable values. When I calculate standard deviation from std(y) then I do not get answer 2. Why is that so ?

$\endgroup$
3
  • 1
    $\begingroup$ What is the distribution of x? $\endgroup$
    – Glen_b
    Commented Aug 7, 2016 at 12:10
  • $\begingroup$ Can you add a full reproducible example, i.e., containing also code that generates x $\endgroup$ Commented Aug 7, 2016 at 12:15
  • $\begingroup$ @Juho : x = (-5:0.01:5); y = normpdf(x); std_y = std(y) $\endgroup$
    – TonyParker
    Commented Aug 7, 2016 at 12:28

1 Answer 1

4
$\begingroup$

normpdf(X,0,2) returns the probability density function at all values of X (be it a scalar, vector, or matrix) of a Normal random variable having mean = 0 and standard deviation = 2.

It does not return sample (simulated) values of such a Normal random variable. For that, either

A) use normrnd

or

B) generate uniform random variables and use them as arguments for the inverse Normal cdf.

So here is what I think you wanted to do:

>> % Method A
>> % Generates 1e6 Normal random numbers with mean 0, standard deviation 2
>> y = normrnd(0,2,1e6,1); 
>> disp(std(y))
    1.9994

or

>> % Method B
>> % Generate 1e6 U[0,1} r.v.s, apply inverse normal CDF, and multiply by standard deviation
>> u = rand(1e6,1);
>> y = 2*norminv(u);
>> disp(std(y))
    1.9991

Edit: Here is a plot of what you generated, which of course is the pdf:

>> x=-5:.01:5;
>> plot(x,normpdf(x,0,2))

enter image description here

$\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.