ounad10=read.table("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad10.txt", header=TRUE, sep=",")
ounad10
## ounasort diameeter
## 1 Kuldrenett 3.11
## 2 Kuldrenett 3.18
## 3 Liivi sibul 2.75
## 4 Liivi sibul 1.23
## 5 Liivi sibul 3.06
## 6 Kuldrenett 3.10
## 7 Kuldrenett 2.02
## 8 Kuldrenett 4.75
## 9 Liivi sibul 3.86
## 10 Kuldrenett 5.51
t.test(ounad10$diameeter)
##
## One Sample t-test
##
## data: ounad10$diameeter
## t = 8.3615, df = 9, p-value = 1.552e-05
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 2.375835 4.138165
## sample estimates:
## mean of x
## 3.257
t.test(ounad10$diameeter, conf.level=0.9)
##
## One Sample t-test
##
## data: ounad10$diameeter
## t = 8.3615, df = 9, p-value = 1.552e-05
## alternative hypothesis: true mean is not equal to 0
## 90 percent confidence interval:
## 2.542958 3.971042
## sample estimates:
## mean of x
## 3.257
#90% tõenäosusega on sarnaste õunte diameetrite
#aritmeetiline keskmine 2.54-3.97
t.test(ounad10$diameeter, conf.level=0.99)
##
## One Sample t-test
##
## data: ounad10$diameeter
## t = 8.3615, df = 9, p-value = 1.552e-05
## alternative hypothesis: true mean is not equal to 0
## 99 percent confidence interval:
## 1.991111 4.522889
## sample estimates:
## mean of x
## 3.257
t.test(ounad10$diameeter, alternative="greater")
##
## One Sample t-test
##
## data: ounad10$diameeter
## t = 8.3615, df = 9, p-value = 7.762e-06
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
## 2.542958 Inf
## sample estimates:
## mean of x
## 3.257
#95% tõenäosusega on õunte keskmine diameeter suurem kui 2.54
#Leidke, millisest väärtusest on õunte keskmine diameeter
#väiksem (less) 90% tõenäosusega
#Harjutus: Tehke samad tehed läbi sama kataloogi failiga ounad100.txt
#Võrrelge, kuidas vahemikud erinevad
ounad100=read.table("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad100.txt", header=TRUE, sep=",")
t.test(ounad100$diameeter)
##
## One Sample t-test
##
## data: ounad100$diameeter
## t = 21.197, df = 99, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 2.948132 3.557068
## sample estimates:
## mean of x
## 3.2526
attributes(t.test(ounad100$diameeter))
## $names
## [1] "statistic" "parameter" "p.value" "conf.int" "estimate"
## [6] "null.value" "alternative" "method" "data.name"
##
## $class
## [1] "htest"
vahemik=t.test(ounad100$diameeter)[["conf.int"]]
vahemik=round(vahemik, 1)
paste("95% tõenäosusega on õunte keskmine diameeter vahemikus ",
vahemik[1], " kuni ", vahemik[2], " cm ")
## [1] "95% tõenäosusega on õunte keskmine diameeter vahemikus 2.9 kuni 3.6 cm "
plot(density(ounad100$diameeter), main="Õunte läbimõõt",
xlab="Keskmine ja keskmise 90% usaldusvahemik")
abline(v=mean(ounad100$diameeter))
vahemik=t.test(ounad100$diameeter, conf.level=0.9)[["conf.int"]]
abline(v=vahemik, lty=2)
#Harjutus: koostage sarnane joonis kümne õunaga
Diameetrite võrdlemine õunasortide järgi
boxplot(ounad100$diameeter~ounad100$ounasort)
kuldrenetid=ounad100[ounad100$ounasort=="Kuldrenett", "diameeter"]
sibulounad=ounad100[ounad100$ounasort=="Liivi sibul", "diameeter"]
kuldrenetid
## [1] 3.99 3.65 5.52 2.53 9.76 3.65 8.16 5.50 7.48 5.53 1.71 1.82 1.93 0.42
## [15] 3.49 6.13 1.64 2.06 6.92 0.75 3.65 6.84 1.17 1.32
sibulounad
## [1] 3.68 1.79 3.66 1.95 3.26 2.56 2.91 2.85 3.67 3.47 2.80 1.01 2.85 4.03
## [15] 1.95 3.49 3.44 2.28 3.06 1.99 3.58 2.22 2.81 2.13 2.19 3.87 3.48 3.91
## [29] 4.01 2.74 4.04 2.64 3.48 3.05 3.21 2.51 2.00 2.59 4.43 3.41 2.27 3.35
## [43] 1.43 2.76 2.77 2.96 3.44 5.67 2.55 2.74 2.85 3.52 1.99 4.53 2.39 2.98
## [57] 4.50 2.18 3.23 4.30 3.11 1.99 4.42 5.20 2.36 1.85 4.13 3.96 2.11 3.34
## [71] 1.66 3.21 2.66 1.57 2.56 4.10
plot(density(sibulounad), xlim=c(0, 10))
lines(density(kuldrenetid), col="brown")
#abline(v=mean(sibulounad))
segments(mean(sibulounad), 0, mean(sibulounad), 0.3)
abline(v=mean(kuldrenetid), col="brown")
t.test(kuldrenetid, sibulounad)
##
## Welch Two Sample t-test
##
## data: kuldrenetid and sibulounad
## t = 1.7798, df = 24.757, p-value = 0.08738
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1518338 2.0770093
## sample estimates:
## mean of x mean of y
## 3.984167 3.021579
# 95% tõenäosusega on kuldrenetid suuremad -0.1518338 kuni 2.0770093 cm
# Kuna võimalus kõikuda on mõlemale poole, siis selle tõenäosusega
# ma ei või midagi väita
t.test(kuldrenetid, sibulounad, conf.level=0.9)
##
## Welch Two Sample t-test
##
## data: kuldrenetid and sibulounad
## t = 1.7798, df = 24.757, p-value = 0.08738
## alternative hypothesis: true difference in means is not equal to 0
## 90 percent confidence interval:
## 0.03841949 1.88675595
## sample estimates:
## mean of x mean of y
## 3.984167 3.021579
#90% tõenäosusega on kuldrenetid suuremad kui sibulõunad
#Harjutus: võtke 1000 õunaga fail ning näidake,
#millise tõenäosusega võite väita, et üks õunasort on suurem kui teine
ounad1000=read.table("http://www.tlu.ee/~jaagup/andmed/muu/ounad/ounad1000.txt", header=TRUE, sep=",")
kuldrenetid=ounad1000[ounad1000$ounasort=="Kuldrenett", "diameeter"]
sibulounad=ounad1000[ounad1000$ounasort=="Liivi sibul", "diameeter"]
t.test(kuldrenetid, sibulounad)
##
## Welch Two Sample t-test
##
## data: kuldrenetid and sibulounad
## t = 11, df = 946.53, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.8614071 1.2355042
## sample estimates:
## mean of x mean of y
## 4.059494 3.011038
#95% tõenäosusega on kuldrenetid suuremad 0.8614071 kuni 1.2355042 cm
t.test(kuldrenetid, sibulounad, conf.level=0.99)
##
## Welch Two Sample t-test
##
## data: kuldrenetid and sibulounad
## t = 11, df = 946.53, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 99 percent confidence interval:
## 0.8024505 1.2944608
## sample estimates:
## mean of x mean of y
## 4.059494 3.011038
#99% tõenäosusega on kuldrenetid suuremad vähemalt 0.8 cm