student dwie

This commit is contained in:
Jakub Adamski 2022-05-09 12:34:50 +02:00
parent 11f948c114
commit fa03e4d6fe

View File

@ -1,26 +1,34 @@
t.test_knownvar <- function(x, y, V1, V2, m0 = 0, alpha = 0.05, alternative = "two.sided") {
t.test_multiple <- function(x, y, m0=0, alternative = "two.sided") {
M1 <- mean(x)
M2 <- mean(y)
n1 <- length(x)
n2 <- length(y)
sigma1 <- sqrt(V1)
sigma2 <- sqrt(V2)
S <- sqrt((V1 / n1) + (V2 / n2))
S <- sqrt((var(x) / n1) + (var(y) / n2))
statistic <- (M1 - M2 - m0) / S
p <- if (alternative == "two.sided") {
2 * pnorm(abs(statistic), lower.tail = FALSE)
2 * pt(q=abs(statistic), df=n1+n2-2, lower.tail=FALSE)
} else if (alternative == "less") {
pnorm(statistic, lower.tail = TRUE)
pt(q=statistic, df=n1+n2-2, lower.tail = TRUE)
} else {
pnorm(statistic, lower.tail = FALSE)
pt(q=statistic, df=n1+n2-2, 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, alternative = alternative)
# print(sprintf("P-value = %g",p))
# print(sprintf("Lower %.2f%% Confidence Limit = %g",
# alpha, LCL))
# print(sprintf("Upper %.2f%% Confidence Limit = %g",
# alpha, UCL))
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')