/* nag_2_sample_t_test (g07cac) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * * Mark 6 revised, 2000. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Local variables */ double prob, xstd, ystd; double t; double xmean, ymean, df, dl, du; double clevel; Integer exit_status = 0, nx, ny; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_2_sample_t_test (g07cac) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld %ld", &nx, &ny); fscanf(fpin, "%lf %lf %lf %lf", &xmean, &ymean, &xstd, &ystd); fscanf(fpin, "%lf", &clevel); /* nag_2_sample_t_test (g07cac). * Computes t-test statistic for a difference in means * between two Normal populations, confidence interval */ nag_2_sample_t_test(Nag_TwoTail, Nag_PopVarEqual, nx, ny, xmean, ymean, xstd, ystd, clevel, &t, &df, &prob, &dl, &du, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_2_sample_t_test (g07cac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\nAssuming population variances are equal.\n\n"); fprintf(fpout, "t test statistic = %10.4f\n", t); fprintf(fpout, "Degrees of freedom = %8.1f\n", df); fprintf(fpout, "Significance level = %8.4f\n", prob); fprintf(fpout, "Lower confidence limit for difference in means = %10.4f\n", dl); fprintf(fpout, "Upper confidence limit for difference in means = %10.4f\n\n", du); /* nag_2_sample_t_test (g07cac), see above. */ nag_2_sample_t_test(Nag_TwoTail, Nag_PopVarNotEqual, nx, ny, xmean, ymean, xstd, ystd, clevel, &t, &df, &prob, &dl, &du, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_2_sample_t_test (g07cac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\nNo assumptions about population variances.\n\n"); fprintf(fpout, "t test statistic = %10.4f\n", t); fprintf(fpout, "Degrees of freedom = %8.4f\n", df); fprintf(fpout, "Significance level = %8.4f\n", prob); fprintf(fpout, "Lower confidence limit for difference in means = %10.4f\n", dl); fprintf(fpout, "Upper confidence limit for difference in means = %10.4f\n", du); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); return exit_status; }