Matma_AI_cyber/Projekt_1/T-studnet-multiple.R

49 lines
1.2 KiB
R
Raw Normal View History

2022-05-09 17:33:51 +02:00
#jest git
2022-05-09 12:34:50 +02:00
t.test_multiple <- function(x, y, m0=0, alternative = "two.sided") {
2022-05-09 12:01:06 +02:00
M1 <- mean(x)
M2 <- mean(y)
n1 <- length(x)
n2 <- length(y)
2022-05-09 12:34:50 +02:00
S <- sqrt((var(x) / n1) + (var(y) / n2))
2022-05-09 12:01:06 +02:00
statistic <- (M1 - M2 - m0) / S
2022-05-09 12:34:50 +02:00
2022-05-09 12:01:06 +02:00
p <- if (alternative == "two.sided") {
2022-05-09 12:34:50 +02:00
2 * pt(q=abs(statistic), df=n1+n2-2, lower.tail=FALSE)
2022-05-09 12:01:06 +02:00
} else if (alternative == "less") {
2022-05-09 12:34:50 +02:00
pt(q=statistic, df=n1+n2-2, lower.tail = TRUE)
2022-05-09 12:01:06 +02:00
} else {
2022-05-09 12:34:50 +02:00
pt(q=statistic, df=n1+n2-2, lower.tail = FALSE)
2022-05-09 12:01:06 +02:00
}
2022-05-09 12:34:50 +02:00
value <- list(mean1 = M1, mean2 = M2, df=n1+n2-2, m0 = m0, statistic = statistic, p.value = p, alternative = alternative)
2022-05-09 12:01:06 +02:00
return(value)
2022-05-09 12:34:50 +02:00
}
2022-05-09 12:37:50 +02:00
# niezależne
load("Bledy.RData")
attach(Bledy)
2022-05-09 12:34:50 +02:00
2022-05-09 17:33:51 +02:00
size_Bledy <- length(Bledy$Blad)
bootstrappedData_Bledy_Blad <- ourBoot(Bledy$Blad, 200, size_Bledy)
bootstrappedData_Bledy_Kod <- ourBoot(Bledy$Kod, 200, size_Bledy)
2022-05-09 12:37:50 +02:00
2022-05-09 12:34:50 +02:00
2022-05-09 17:33:51 +02:00
#dane zbootstrapowane
#funkcja wbudowana
t.test(x=bootstrappedData_Bledy_Blad, y=bootstrappedData_Bledy_Kod,var.equal=T,alternative='less')
# nasza funkcja
t.test_multiple(x=bootstrappedData_Bledy_Blad, y=bootstrappedData_Bledy_Kod, alternative='less')
#dane normalne
#funkcja wbudowana
t.test(x=Blad, y=Kod,var.equal=T,alternative='less')
# nasza funkcja
t.test_multiple(x=Blad, y=Kod, alternative='less')
2022-05-09 12:34:50 +02:00