Program written, modified, or edited at StatSoft, Inc.}
RandomAccess;
NoDataFileVariableNames;
{Make sure the users are ready to compute the confidence intervals.}
Startmsg := DisplayMessageBox(MB_OKCANCEL, 'Confidence Intervals of the difference of
two means', 'This program will compute the confidence intervals of the difference of two
means for independent samples. The Grouping Scrollsheet needs to be active on the screen.
You will be prompted to input the alpha value. If you are ready, click "OK".');
If Startmsg = IDCANCEL then stop;
{Start the procedure.}
{Read the Scrollsheet created from t-test independent samples in the Basic Statistics and Tables
module into a matrix.}
scrollsheet := GetScrollsheet (0);
ncols := ScrollsheetGetNbCols(scrollsheet);
nrows := ScrollsheetGetNbRows(scrollsheet);
ReDim matrix(nrows,6), tempmtx(nrows,1), dffmean(nrows), poolsd(nrows), tvalue(nrows),
Ucfd(nrows), Lcfd(nrows);
ScrollsheetGetMatrix(scrollsheet,1,1,matrix);
{Read alpha value from users input.}
DisplayNumericInputBox('Significance Level for Confidence Interval', 'Alpha value', alpha);
If alpha = 0 then Stop;
{Get the right columns for computation.}
ncoln := 2;
For i := 3 to ncols do
begin
ScrollsheetGetColName (scrollsheet, i, Name1$, Name2$);
If (Name1$ = 'Valid N') then
begin
ncoln := ncoln + 1;
ScrollsheetGetMatrix(scrollsheet,1,i,tempmtx);
MatrixCopy(tempmtx, 1,1,nrows,1,matrix,1,ncoln);
end;
If (Name1$ = 'Std.Dev.') then
begin
ncoln := ncoln + 1;
ScrollsheetGetMatrix(scrollsheet,1,i,tempmtx);
MatrixCopy(tempmtx, 1,1,nrows,1,matrix,1,ncoln);
end;
end;
{Start the computation.}
For i :=1 to nrows do
begin
{Compute the difference of two group means.}
dffmean(i) := matrix(i,1)-matrix(i,2);
{Compute the pooled standard deviation.}
pooldf := matrix(i,3)+matrix(i,4)-2;
poolsd(i) :=sqrt( ((matrix(i,3)-1)*matrix(i,5)^2+(matrix(i,4)-1)*matrix(i,6)^2)/pooldf);
{Obtain the t-value and compute confidence intervals.}
tvalue(i) := VStudent(1-alpha/2, pooldf);
Ucfd(i) := dffmean(i)+tvalue(i)*poolsd(i)*sqrt((1/matrix(i,3))+(1/matrix(i,4)));
Lcfd(i) := dffmean(i)-tvalue(i)*poolsd(i)*sqrt((1/matrix(i,3))+(1/matrix(i,4)));
end;
{Arrange the output.}
{Create appropriate new column names.}
lower$ := "-" + Str((1-alpha)*100,6,3) + "%";
upper$ := "+" + Str((1-alpha)*100,6,3) + "%";
mean1$ := "Mean 1 ";
mean2$ :="-" + " Mean 2";
ScrollsheetAppendColumns(scrollsheet,3);
ScrollsheetSetColumnName(scrollsheet,ncols+1,mean1$,mean2$);
ScrollsheetSetColumnName(scrollsheet,ncols+2,"Confid.", lower$);
ScrollsheetSetColumnName(scrollsheet,ncols+3,"Confid.", upper$);
{Define the column format.}
For i := 1 to 3 do
ScrollsheetSetColumnFormat(scrollsheet, ncols+i,SCF_OPTIMAL, ?FmtParam);
{Enter the results to the scrollsheet.}
ScrollsheetSetMatrix(scrollsheet,1,ncols+1,dffmean);
ScrollsheetSetMatrix(scrollsheet,1,ncols+2,Lcfd);
ScrollsheetSetMatrix(scrollsheet,1,ncols+3,Ucfd);
| Back to List of Programs |
![[StatSoft]](../../../images/sssmall.gif)
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217
e-mail: info@statsoft.com
©Copyright StatSoft, Inc., 1984-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.