In: Statistics and Probability
a). Calculate the test statistic. (R code and R result).
b). Find the p-value (R code and R result).
c). Make your decision.
We want to test that Mrs. Jones is a more effective teacher than Mrs. Smith.
U1:- Mrs. Smith's students average test score
U2:- Mrs. Jones' students average test score
We want to test Mrs. Jones is a more effective teacher than Mrs. Smith. ie. Mr.Jones have higher average scores.
The null & alternative Hypothesis:
Ho: U1 =U2
VS
Ha: U1<U2
a)
> # m1, m2: the sample means
> # s1, s2: the sample standard deviations
> # n1, n2: the same sizes
>
>
> n1<-30;n2<-25
> m1<-78;m2<-85
> s1<-10;s2<-15
> alpha=0.10
>
>
> # pooled standard deviation, scaled by the sample sizes
> se <- sqrt( ((1/n1) + (1/n2)) * (((n1-1)*s1^2) +
((n2-1)*s2^2))/(n1+n2-2) )
> df <- n1+n2-2
>
> # The test statistic:
>
> t <- (m1-m2)/se
>
> t
[1] -2.0656
>
>
b)
> # p-value
> pt(t,df)
[1] 0.02188548
c)
P-value = 0.02 < 0.10(level of significance)
So we reject Ho.
we may conclude that the data provide suficient evidence to connclude that the Mrs. Jones is a more effective teacher than Mrs. Smith.
***********R code ************
# m1, m2: the sample means
# s1, s2: the sample standard deviations
# n1, n2: the same sizes
n1<-30;n2<-25
m1<-78;m2<-85
s1<-10;s2<-15
alpha=0.10
# pooled standard deviation, scaled by the sample sizes
se <- sqrt( ((1/n1) + (1/n2)) * (((n1-1)*s1^2) +
((n2-1)*s2^2))/(n1+n2-2) )
df <- n1+n2-2
# The test statistic:
t <- (m1-m2)/se
t
# p-value
pt(t,df)
********* using a Function *********
# R code for left tailed test#
# m1, m2: the sample means
# s1, s2: the sample standard deviations
# n1, n2: the same sizes
# m0: the null value for the difference in means to be tested
for. Default is 0.
# Alternative is
# equal.variance: whether or not to assume equal variance. Default
is FALSE.
t.test2 <-
function(m1,m2,s1,s2,n1,n2,m0=0,equal.variance=FALSE)
{
if( equal.variance==FALSE )
{
se <- sqrt( (s1^2/n1) + (s2^2/n2) )
# welch-satterthwaite df
df <- ( (s1^2/n1 + s2^2/n2)^2 )/( (s1^2/n1)^2/(n1-1) +
(s2^2/n2)^2/(n2-1) )
} else
{
# pooled standard deviation, scaled by the sample sizes
se <- sqrt( (1/n1 + 1/n2) * ((n1-1)*s1^2 +
(n2-1)*s2^2)/(n1+n2-2) )
df <- n1+n2-2
}
t <- (m1-m2-m0)/se
dat <- c(m1-m2, se, t, pt(t,df))
names(dat) <- c("Difference of means", "Std Error", "t",
"p-value")
return(dat)
}
# you'll find this output agrees with that of t.test when you
input x1,x2
t.test2( m1, m2, s1, s2, n1, n2,equal.variance=TRUE)