tTest - start

This commit is contained in:
MikolajPaterka 2022-05-08 23:55:40 +02:00
parent bc7247353f
commit 1896c3cc83
3 changed files with 65 additions and 2 deletions

View File

@ -18,3 +18,8 @@ bootstrappedData <- ourBoot(Wynik, 200, 50)
par(mfrow=c(1,2))
hist(Wynik,prob=T,main='')
hist(bootstrappedData,prob=T,main='')

View File

@ -31,6 +31,61 @@ 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)

View File

@ -33,3 +33,6 @@ Lista tematów:
Pozdrawiam,
Bartosz Naskręcki
Link do strony: https://statsandr.com/blog/student-s-t-test-in-r-and-by-hand-how-to-compare-two-groups-under-different-scenarios/#how-to-compute-students-t-test-in-r