#Data  on Porsche
x = c(80000,30100,97500,58551,73787,51800,69267,44530,
      42192,104920,41442,27418,43436,77219,5991,14362)
x2 = c(80000,30100,97500,58551,73787,51800,69267,44530,
      42192,104920,41442,27418,43436,77219,5991,143620)
qqnorm(x)
qqline(x)
n = length(x)
s = sd(x)
alpha=0.05

#Intervall basert på Normal-tilnærming
mean(x)+c(-1,1)*qnorm(1-alpha/2)*s/sqrt(n)

#Intervall basert på Normal-antagelse, bruk av t-fordeling
mean(x)+c(-1,1)*qt(1-alpha/2,n-1)*s/sqrt(n)

#Normalfordeling og t fordeling
x = seq(-2.5,2.5,length=100)
matplot(cbind(x,x),cbind(dnorm(x),dt(x,n-1)),type="l",lty=1,lwd=2,col=1:2,
        xlab="",ylab="")
legend("topright",c("Normal",expression(t[15])),lty=1,lwd=2,col=1:2)
abline(v=qnorm(c(0.025,0.975)))
abline(v=qt(c(0.025,0.975),n-1),col=2)

#Direct use of routine in R
t.test(x,conf.level=0.95)$conf.int

#Prediction interval:

mean(x)+c(-1,1)*2.131*s*sqrt(1+1/n)
