From fa03e4d6fe3f649d62164b95f77fabf5a02ac0cb Mon Sep 17 00:00:00 2001 From: Jakub Adamski Date: Mon, 9 May 2022 12:34:50 +0200 Subject: [PATCH] student dwie --- Projekt_1/T-studnet-multiple.R | 40 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/Projekt_1/T-studnet-multiple.R b/Projekt_1/T-studnet-multiple.R index 1d062c3..2df4597 100644 --- a/Projekt_1/T-studnet-multiple.R +++ b/Projekt_1/T-studnet-multiple.R @@ -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) -} \ No newline at end of file +} + + +#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') + + + + +