Matma_AI_cyber/Projekt_1/T-studnet-multiple.R
2022-05-09 12:34:50 +02:00

35 lines
785 B
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)
}
#dwie próby zależne
load("Cisnienie.RData")
attach(Cisnienie)
t.test(x=Po, y=Przed, alternative='less')
t.test_multiple(x=Po, y=Przed, alternative='less')