Matma_AI_cyber/Projekt_1/T-student-single.R
2022-05-09 12:01:06 +02:00

27 lines
659 B
R

t.test_single <- function(x, m, alternative = "two.sided") {
M <- mean(x)
n <- length(x)
statistic <- ((M - m) / sd(x)) * sqrt(n)
p <- if (alternative == "two.sided") {
2 * pt(q=abs(statistic), df=length(x)-1, lower.tail=FALSE)
} else if (alternative == "less") {
pt(q=statistic, df=length(x)-1, lower.tail = TRUE)
} else {
pt(q=statistic, df=length(x)-1, lower.tail = FALSE)
}
value <- list(mean = M, m = m, statistic = statistic, p.value = p, alternative = alternative)
return(value)
}
load("Hamulce.RData")
attach(Hamulce)
t.test(Wynik,mu=18.6,alternative='less')
t.test_single(Wynik, m=18.6, alternative='less')