- Group 1: mean = m1, std = s1, n = n1
- Group 2: mean = m2, std = s2, n = n2
ttest - no data
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
Is there a way in Matlab to perform t-test (where we check for variance first and then perform the test and find the p-value) using means and std (no data)?
Thanks
댓글 수: 0
답변 (1개)
Samayochita
2025년 4월 24일
편집: Samayochita
2025년 4월 24일
Hi Seldeeno,
I understand that the goal is to perform a t-test without raw data, using just the means, standard deviations, and sample sizes of two independent samples. Since MATLAB’s ttest2 function needs the actual data vectors, here's how one can do it manually:
Step 1: Gather the summary statistics (means, standard deviations, and sample sizes)
For example:
Step 2: Test for equality of variances, F-test could be used to compare variances:
F = (s1^2) / (s2^2);
df1 = n1 - 1;
df2 = n2 - 1;
p_var = 2 * min(1 - fcdf(F, df1, df2), fcdf(F, df1, df2));
Here, p_var is the p-value for the F-test. If p_var < 0.05, variances are significantly different.
Step 3: Calculate t-test
Case 1: Equal variances (pooled t-test used if p_var > 0.05)
sp2 = ((n1-1)*s1^2 + (n2-1)*s2^2) / (n1 + n2 - 2);
se = sqrt(sp2 * (1/n1 + 1/n2));
t = (m1 - m2) / se; % t-statistic
df = n1 + n2 - 2; % degrees of freedom
p = 2 * (1 - tcdf(abs(t), df)); % two-tailed p-value
Case 2: Unequal variances (Welch's t-test, used if p_var is not greater than 0.05)
se = sqrt(s1^2/n1 + s2^2/n2);
t = (m1 - m2) / se; % t-statistic
df = (se^4) / ((s1^2/n1)^2/(n1-1) + (s2^2/n2)^2/(n2-1)); % degrees of freedom
p = 2 * (1 - tcdf(abs(t), df)); % two-tailed p-value
Step 4: Display the results
fprintf('t = %.3f, df = %.2f, p = %.4f\n', t, df, p);
For more information on the functions used above please refer to the following documentation links:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Hypothesis Tests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!