Matma_AI_cyber/Projekt_1/T-student-multiple.R
2022-05-24 16:17:00 +02:00

50 lines
1.3 KiB
R

t.test_multiple <- function(x, y, m0=0, alternative = "two.sided") {
M1 <- mean(x)
M2 <- mean(y)
n1 <- length(x)
n2 <- length(y)
S <- sqrt((var(x) / n1) + (var(y) / n2))
statistic <- (M1 - M2 - m0) / S
p <- if (alternative == "two.sided") {
2 * pt(q=abs(statistic), df=n1+n2-2, lower.tail=FALSE)
} else if (alternative == "less") {
pt(q=statistic, df=n1+n2-2, lower.tail = TRUE)
} else {
pt(q=statistic, df=n1+n2-2, lower.tail = FALSE)
}
value <- list(mean1 = M1, mean2 = M2, df=n1+n2-2, m0 = m0, statistic = statistic, p.value = p, alternative = alternative)
return(value)
}
# niezależne
load("Bledy.RData")
attach(Bledy)
size_Bledy <- length(Bledy$Blad)
wyniki <- data.frame()
for (i in 1:10){
bootstrappedData_Bledy_Blad <- ourBoot(Bledy$Blad, size_Bledy, size_Bledy)
bootstrappedData_Bledy_Kod <- ourBoot(Bledy$Kod, size_Bledy, size_Bledy)
ttest <- t.test_multiple(x=bootstrappedData_Bledy_Blad, y=bootstrappedData_Bledy_Kod, alternative='less')
wyniki <- rbind(wyniki, ttest)
}
mean(wyniki$mean1)
mean(wyniki$mean2)
mean(wyniki$statistic)
mean(wyniki$p.value)
#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')