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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|