function [D,t,df,pvalue,CI]=student1group(Xn,Xmean, Xstd, M, alpha)
% Student't 1-sample t test with grouped data
% [D,t,df,pvalue,CI]=student1group(Xn,Xmean,Xstd,alpha)
% Input: Xn = Size of group = number of cases
%        Xmean = mean for groups
%        Xstd, Ystd= standard deviations for 2 groups
%        M=expected mean, 0 if not provided
%        alpha level for CI, optional, 95% if not specified
% Output: D=Xmean-M or Xmean-0;
%         t=Student's t statistic
%         df=degrees of freedom for t statistic
%         p value, 2-sided, for t Statisitc, with df degrees of freedom
%         CI for 1-alpha CI, [L U];95% CI if alpha not specified.
% Based on Theorem 7.4.2, page 490 in Larsen & Marx (2006)
% Introduction to Mathematical Statistics, 4th edition.
% uses Statistics toolbox
% Written by Eugene.Gallagher@umb.edu, Revised 11/14/10
% see also stud1sample, binom2sample, student2group, stud2sample
if nargin<4
    M=0;
    alpha=0.05;
elseif nargin <5
    alpha=0.05;
end
D=Xmean-M;
% Calculate sample standard deviation
t=D/(Xstd/sqrt(Xn));
% Use stixbox's pt.m for significance of t.
df=Xn-1;
if t>=0
    pvalue=2*(1-tcdf(t,df));
else
    pvalue=2*tcdf(t,df);
end
HalfCI=tinv(1-alpha/2,df)*Xstd*sqrt(1/Xn);
CI=[D-HalfCI D+HalfCI];