function [D,t,df,pvalue,CI]=Stud1sample(X,meanHo,alpha)
% [D,t,df,pvalue,CI]=Stud1sample(X,meanHo,alpha)
% Input: X sample
%        meanHo under Ho, 0 if not specified
%        alpha level for CI, optional, 
%              alpha=0.05 for 95% CI if not specified
% Output: D=mean(X)-meanHo;
%         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, page 
% Written by Eugene.Gallagher@umb.edu in 2001, revised 11/17/2010
X=X(:);
n=length(X);
if nargin<2
    meanHo=0;
    alpha=0.05;
elseif nargin <3
    alpha=0.05;
end
D=mean(X)-meanHo;
% Calculate sample standard deviation
stdX=std(X);
t=D/(stdX/sqrt(n));
% Use stixbox's pt.m for significance of t.
df=n-1;
if t>=0
    pvalue=2*(1-tcdf(t,df));
else
    pvalue=2*tcdf(t,df);
end
HalfCI=tinv(1-alpha/2,df)*stdX*sqrt(1/n);
CI=[D-HalfCI D+HalfCI];