Question

I can't seem to understand why my simple code given below doesn't work. I get NaN for the P_j values.

% Plotting the CDF for normally distributed variable
mu_j = 0.008;
simga_j = -0.002;
x= 0.008 -0.002*randn(100000,1);
X_j = min(x) : (max(x) - min(x))/100000 : max(x);
P_j = normcdf(X_j,0.008,-0.002); 

figure(1)

plot(X_j,P_j);

Thanks

Was it helpful?

Solution

Standard deviations should be positive values. This is because in statistics, it is calculated as sigma = sqrt(E[(X-mu)^2])). The square term inside the expectation will only ever be positive.

If you adjust sigma_j to be 0.002 instead of -0.002, and correct the value elsewhere in your code (such as when you calculate x and P_j), you should get good results.

The specific problem is caused because normcdf() doesn't handle the negative sigma properly, and returns NaN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top