필터 지우기
필터 지우기

how to test a hypothesis with t-test or p value

조회 수: 136 (최근 30일)
farfar
farfar 2017년 3월 22일
댓글: farfar 2017년 3월 22일
Hello I am testing the null hypothesis mu=3.4 against mu>3.4, for a sample of size 9. I want to test this with both t-distribution table and p-value but its giving me NaN instead of 0 or 1.this is the code im using :
mu = 3.4; % Population mean
sample=[3.4,3.6,3.8, 3.3,3.4,3.5,3.7,3.6,3.7]
n = numel(sample)
xobs = mean(sample) % Sample mean
s = std(sample) % Sample standard deviation
t = (xobs - mu)/(s/sqrt(n))
p = 1-tcdf(t,n-1)
[h,ptest] = ttest(xobs,mu,0.05,'right')
Thank you

채택된 답변

the cyclist
the cyclist 2017년 3월 22일
I can't look at this fully right now, but one thing I notice immediately is that you are putting the mean value of the sample as the first argument of ttest(), but you should be putting the sample itself:
ttest(sample,mu,0.05,'right')
I don't know if that is the only problem with your code, but is is definitely a problem with it. :-)
  댓글 수: 4
the cyclist
the cyclist 2017년 3월 22일
편집: the cyclist 2017년 3월 22일
You can't do a t-test with just the sample mean. You need the distribution. This is pretty obvious if you consider the two samples
sample = [10 10 10 10 10 10 10];
and
sample = [-8 0 7 10 13 20 28];
which have the same mean, but obviously different likelihood of being different from the population mean.
The specific reason you get NaN from what you are doing is that you are putting in a "sample" of one value, and the t-test is ill-defined for a sample size of one.
farfar
farfar 2017년 3월 22일
Tnx!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by