From 1896c3cc830e43c5aa58d31377173478a46085a8 Mon Sep 17 00:00:00 2001 From: MikolajPaterka Date: Sun, 8 May 2022 23:55:40 +0200 Subject: [PATCH] tTest - start --- Projekt_1/Bootstrapping.R | 7 ++++- Projekt_1/Projekt_1.R | 55 +++++++++++++++++++++++++++++++++++++++ README.md | 5 +++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Projekt_1/Bootstrapping.R b/Projekt_1/Bootstrapping.R index ef8e1bf..1f7983f 100644 --- a/Projekt_1/Bootstrapping.R +++ b/Projekt_1/Bootstrapping.R @@ -17,4 +17,9 @@ bootstrappedData <- ourBoot(Wynik, 200, 50) par(mfrow=c(1,2)) hist(Wynik,prob=T,main='') -hist(bootstrappedData,prob=T,main='') \ No newline at end of file +hist(bootstrappedData,prob=T,main='') + + + + + diff --git a/Projekt_1/Projekt_1.R b/Projekt_1/Projekt_1.R index 028c434..1a53178 100644 --- a/Projekt_1/Projekt_1.R +++ b/Projekt_1/Projekt_1.R @@ -31,6 +31,61 @@ tapply(Blad,Kod,var) var.test(Blad~Kod) t.test(Blad~Kod,var.equal=T,alternative='less') +# tTest dla dwoch prób------------------------------------------------------------------- +#wariancj + +#podiał danych tak by tam gdzie jest 1 w blad był jeden zdbió® i tam gdzier 2 był drugi zbiór + +x <- Bledy$Blad +y <- Bledy$Kod + +var1 <- var(x) +var2 <- var(y) + +#m0 i alpha- będzie przekazen w funcki +m0 <- 0 +alpha = 0.05 + +m1 <- mean(x) +m2 <- mean(y) +n1 <- length(x) +n2 <- length(y) + +sigma1 <- sqrt(n1) +sigma2 <- sqrt(n2) + +# odchulylenie standardowe +S <- sqrt((var1/n1)+(var2/n2)) + +#Test statistic used to compute the p-value. +statistic <- (m1 - m2 - m0) / S + +alternative = "less" + +#p wartość +p <- if (alternative == "two.sided") { + 2 * pnorm(abs(statistic), lower.tail = FALSE) +} else if (alternative == "less") { + pnorm(statistic, lower.tail = TRUE) +} else { + pnorm(statistic, 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) +var1 +var2 + +value + + + +#--------------------------------------------------------------------- + + + #dwie próby zależne load("Cisnienie.RData") attach(Cisnienie) diff --git a/README.md b/README.md index fd88dbb..7e17446 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,7 @@ Lista tematów: Pozdrawiam, -Bartosz Naskręcki \ No newline at end of file +Bartosz Naskręcki + + +Link do strony: https://statsandr.com/blog/student-s-t-test-in-r-and-by-hand-how-to-compare-two-groups-under-different-scenarios/#how-to-compute-students-t-test-in-r \ No newline at end of file