In: Statistics and Probability
A study presents data on widths and lengths of the native butter clam. Here is a small random sample of dimensions for four of these clams that we will use to test whether, in general, the clams are longer than they are wide.
Width | Length |
3.2 4.4 4.8 5.8 |
4.1 5.6 6.6 7.0 |
(a) Use software to carry out a paired t test to see if
the mean of differences, width minus length, is negative for the
larger population of clams from which the sample was taken: first
report the t statistic using software. (Round your answer
to two decimal places.)
t =
(b) Next report the P-value using software. (Round your
answer to three decimal places.)
(c) Is there evidence at the 5% level that the population mean is
negative?
Yes
No
(d) To see how choice of test procedure can play a role in
conclusions, carry out a two-sample t test to see if the
difference between population means is negative. (This is
not the appropriate procedure, because the samples of
widths and lengths are not independent, but paired together.)
Report the t statistic for this test using software.
(Round your answer to two decimal places.)
t =
(e) Report the P-value using software. (Round your answer
to three decimal places.)
(f) Would the two-sample test provide evidence at the 5% level that
the population mean is negative?
Yes
No
R-code :
Paired t-test
> w<-c(3.2,4.4,4.8,5.8)
> h<-c(4.1,5.6,6.6,7)
> d<-w-h
> d
[1] -0.9 -1.2 -1.8 -1.2
> mean(d)
[1] -1.275
> sd(d)
[1] 0.3774917
Function for doing lower tailed t-test :
t_lt<-function(mu0,xbar,sigma,n,alpha)
{
z_t<-(xbar-mu0)*sqrt(n)/(sigma)
z_c<-qt(alpha,df=n-1)
pvalue <- pt(z_t,df=n-1)
conc<-ifelse(pvalue>alpha,"Fail to reject H0","Reject
H0")
cint<-c("- \U221E",xbar+abs(z_c)*(sigma/sqrt(n)))
op<-c(z_t,z_c,conc,pvalue,cint)
op
}
> t_lt(0,-1.275,0.377,4,0.05)
[1] "-6.76392572944297" "-2.35336343480183" "Reject H0"
"0.00330129528999329"
[5] "- ∞" "-0.831390992539856"
Two-sample unequal variance t-test :
> mean(w)
[1] 4.55
> mean(h)
[1] 5.825
> sd(w)
[1] 1.075484
> sd(h)
[1] 1.291962
Function for computing t-test :
twosamuneq <- function(xbar1,xbar2,s1,s2,n1,n2,alpha)
{
t1<-s1^2/n1
t2<-s2^2/n2
nr<-(t1+t2)^2
t3<-(t1^2)/(n1-1)
t4<-(t2^2)/(n2-1)
dr<-t3+t4
d<-nr/dr
s<-(t1+t2)^0.5
z_t<-(xbar1-xbar2)/s
z_c<-qt(1-(0.5*alpha),df=d)
pvalue <- 2*(1-pt(abs(z_t),df=d))
conc<-ifelse(pvalue>alpha,"Fail to reject H0","Reject
H0")
cint<-c(xbar1-xbar2-z_c*s,xbar1-xbar2+z_c*s)
moe<-z_c*s
op<-c(z_t,z_c,conc,pvalue,cint,d,s,moe)
op
}
p-value :
> 1-pt(-1.517,df=6)
[1] 0.9099711