normal ditrubution p-values in matlab

You can use normcdf function available in Matlab to get p values of normal distribution. Here is an example code:

main.m
% create normally distributed random data with mean=2 and standard deviation=3
data = 2 + 3*randn(1,1000); 

% perform a one-sample t-test to test the null hypothesis that population mean is 0
[h,p] = ttest(data, 0); 

% calculate p value using the cumulative distribution function (CDF) of standard normal distribution
p_value = 2*(1 - normcdf(abs(p)));

% display the p value
disp(['The p value is: ' num2str(p_value)])
422 chars
12 lines

In this example code, normcdf is used to calculate the CDF of standard normal distribution for the absolute value of p. The p value is then calculated by multiplying the result by 2 on the basis of two-tailed t-test.

related categories

gistlibby LogSnag