97 lines
1.9 KiB
R
97 lines
1.9 KiB
R
library('MKinfer')
|
|
library(boot)
|
|
|
|
#test t-studenta dla jednej próby
|
|
load("Hamulce.RData")
|
|
attach(Hamulce)
|
|
mean(Wynik)
|
|
t.test(Wynik,mu=18.6,alternative='less')
|
|
boot.t.test(Wynik,mu=18.6,alternative='less', R = 100)
|
|
|
|
par(mfrow=c(1,2))
|
|
|
|
hist(Wynik,prob=T,main='')
|
|
|
|
|
|
meanboot <- function(x,i)mean(x[i])
|
|
bmean=boot(Wynik,meanboot,100)
|
|
|
|
hist(bmean$t,prob=T,main='')
|
|
|
|
t.test(bmean$t,mu=18.6,alternative='less')
|
|
|
|
|
|
|
|
|
|
# dwie próby niezależne
|
|
load("Bledy.RData")
|
|
attach(Bledy)
|
|
tapply(Blad,Kod,mean)
|
|
tapply(Blad,Kod,var)
|
|
var.test(Blad~Kod)
|
|
t.test(Blad~Kod,var.equal=T,alternative='less')
|
|
|
|
# tTest dla dwoch prób-------------------------------------------------------------------
|
|
#wariancj
|
|
|
|
#podiał danych tak by tam gdzie jest 1 w blad był jeden zdbió® i tam gdzier 2 był drugi zbiór
|
|
|
|
x <- Bledy$Blad
|
|
y <- Bledy$Kod
|
|
|
|
var1 <- var(x)
|
|
var2 <- var(y)
|
|
|
|
#m0 i alpha- będzie przekazen w funcki
|
|
m0 <- 0
|
|
alpha = 0.05
|
|
|
|
m1 <- mean(x)
|
|
m2 <- mean(y)
|
|
n1 <- length(x)
|
|
n2 <- length(y)
|
|
|
|
sigma1 <- sqrt(n1)
|
|
sigma2 <- sqrt(n2)
|
|
|
|
# odchulylenie standardowe
|
|
S <- sqrt((var1/n1)+(var2/n2))
|
|
|
|
#Test statistic used to compute the p-value.
|
|
statistic <- (m1 - m2 - m0) / S
|
|
|
|
alternative = "less"
|
|
|
|
#p wartość
|
|
p <- if (alternative == "two.sided") {
|
|
2 * pnorm(abs(statistic), lower.tail = FALSE)
|
|
} else if (alternative == "less") {
|
|
pnorm(statistic, lower.tail = TRUE)
|
|
} else {
|
|
pnorm(statistic, lower.tail = FALSE)
|
|
}
|
|
|
|
LCL <- (m1 - m2 - S * qnorm(1 - alpha / 2))
|
|
UCL <- (m1 - m2 + S * qnorm(1 - alpha / 2))
|
|
|
|
value <- list(mean1 = m1, mean2 = m2, m0 = m0, sigma1 = sigma1, sigma2 = sigma2, S = S, statistic = statistic, p.value = p, LCL = LCL, UCL = UCL)
|
|
var1
|
|
var2
|
|
|
|
value
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------
|
|
|
|
|
|
|
|
#dwie próby zależne
|
|
load("Cisnienie.RData")
|
|
attach(Cisnienie)
|
|
mean(Po-Przed)
|
|
t.test(Po-Przed,mu=0,alternative='less')
|
|
|
|
#TODO
|
|
# trzeba narysować rozkład statystyki testowej
|