data=read.delim("example10_3.dat",header=TRUE)
str(data)
## 'data.frame': 20 obs. of 1 variable:
## $ rating: num 5.2 6.8 7 7.8 6.4 6.5 7.2 8.4 6.7 9.2 ...
par(mfrow=c(1,2))
hist(data$rating,prob=TRUE,col="red")
qqnorm(data$rating,col="green")
qqline(data$rating)

par(mfrow=c(1,1))
xbar=mean(data$rating)
xbar
## [1] 7.23
s=sd(data$rating)
s
## [1] 0.9498
n=length(data$rating)
n
## [1] 20
mu=7.5
(7.23-7.5)/(0.9498476/sqrt(20))
## [1] -1.271
t.stat=(xbar-mu)/(s/sqrt(n))
t.stat
## [1] -1.271
x=seq(-4,4,length=200)
df=n-1
plot(x,dt(x,df),type="l",col="blue")
xx=seq(-4,-1.271,length=100)
yy=dt(xx,df)
polygon(c(-4,xx,-1.271),c(0,yy,0),col="orangered")
text(-1.271,0,"-1.271",pos=4)

pt(-1.271,19)
## [1] 0.1095
pt(t.stat,df)
## [1] 0.1095
t.test(data$rating,alternative="less",mu=7.5)
##
## One Sample t-test
##
## data: data$rating
## t = -1.271, df = 19, p-value = 0.1095
## alternative hypothesis: true mean is less than 7.5
## 95 percent confidence interval:
## -Inf 7.597
## sample estimates:
## mean of x
## 7.23