- Group 1: mean = m1, std = s1, n = n1
- Group 2: mean = m2, std = s2, n = n2
ttest - no data
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Samayochita
el 24 de Abr. de 2025
Editada: Samayochita
el 24 de Abr. de 2025
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 comentarios
Ver también
Categorías
Más información sobre Hypothesis Tests en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!