a) Student number 2 is a new student with little experience of elephants, and professor Elestat thus had a prior expectation that he might deviate from the others in his measurements. Does he? (4p)
I use one sample t.test here. Let other students as population, test if student 2’s measurement is different from others.
# data mport and check
eleweigh = read.csv('eleweigh.csv')
str(eleweigh)
stu2.mean = mean(subset(eleweigh, student == '2')$weight)
other = subset(eleweigh, student != '2')
# explore data
hist(other$weight)
boxplot(other$weight)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-
Check assumption of t-test
#Normality of data
x = other$weight
h = hist(x)
xfit = seq(min(x, na.rm=TRUE),max(x, na.rm=TRUE),length=100)
yfit = dnorm(xfit,mean=mean(x, na.rm=TRUE),sd=sd(x, na.rm=TRUE))
yfit = yfit*max(h$counts)/max(yfit)
hist(other$weight, col="red")
lines(xfit, yfit, lwd=2)
> shapiro.test(other$weight)
Shapiro-Wilk normality test
data: other$weight
W = 0.96398, p-value = 0.761
> x = other$weight
> y = pnorm(summary(x), mean =mean(x, na.rm=TRUE), sd =sd(x, na.rm=TRUE))
> ks.test(x, y)
Two-sample Kolmogorov-Smirnov test
data: x and y
D = 1, p-value = 0.0003789
alternative hypothesis: two-sided
> qqnorm(other$weight)
> qqline(other$weight)