# Wu course 20200131: MATLAB t-test

``````load examgrades;
%only take column 1
%look at the data
figure;

%one sample t test
%if the national mean for the exam is 70
%Question: is grade1 different from the national mean?
%Hypothesis: grade1 is different from 70.
%equal variance assumed
%step by step
proposed_mean = 70;
sx_bottom = sqrt(n);
sx = sx_top/sx_bottom;
t_bottom = sx;
t = t_top/t_bottom
%one step
%h = 1, means hypothesis is true. Grade1 is different from 70.

%independent samples t tests
%same or different exam score?)
figure;
%Test the null hypothesis that the two data samples are from populations with equal means.
%step by step
sp_bottom = n1+n2-2;
sp = sqrt(sp_top/sp_bottom);
t_bottom = sp*sqrt(1/n1+1/n2);
t = t_top/t_bottom
%one step
%h = 0, hypothesis false. grade1 is not significantly different from

%Repeated samples t test
%if grade1 and grade2 are two exams (eg, exam1 and exam2) in one classroom
%and each row of grade1 and grade2 corresponds to the same student
%worse in exam2 than exam1)
%step by step
%compare the difference of to zero
proposed_mean = 0;
n = length(d);
sx_top = std(d);
sx_bottom = sqrt(n);
sx = sx_top/sx_bottom;
t_top = mean(d)-proposed_mean;
t_bottom = sx;
t = t_top/t_bottom
%one step