0% found this document useful (0 votes)
6 views3 pages

T Test

Uploaded by

Cleo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

T Test

Uploaded by

Cleo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

t.test for Hg.

txt
# Script (Sintax)
hg = c(6,5,6,8,9,7,5,4,7,11)
# Manual calculation:
n <- length(hg)
mean(hg)
crit.value <- 4.0
t <- (mean(hg)-crit.value)/(sd(hg)/sqrt(n))
t
2*pt(-abs(t),df=n-1) # two sided
1*pt(-abs(t),df=n-1) # less or greates
# Built-in analysis:
# Jawaban (a)
t.test(hg, alternative = c("two.sided"),mu = 4.0, conf.level = 0.95)
# Jawaban (b)
t.test(hg, alternative = c("greater"),mu = 4.0, conf.level = 0.95)
# Jawaban (c)
t.test(hg, alternative = c("greater"),mu = 10.0, conf.level = 0.95)
#------------------- Oke !
##
#find t critical value one tail:
#qt(p, df, lower.tail=TRUE)
qt(p=.05, df=9, lower.tail=TRUE)
qt(p=.05, df=9, lower.tail=FALSE)
#----------
#find two-tailed t critical values
qt(p=.05/2, df=9, lower.tail=FALSE)
#----------
paired t.test for Hg.txt
hg1 = c(6,5,6,8,9,7,5,4,7,11)
hg2 = c(4,6,7,11,2,5,12,5,10,3)
data.frame(hg1,hg2)
# Uji t untuk 2 populasi data Hg
#t.test(x, y = NULL, alternative = c("two.sided", "less", "greater"),
mu = 0, paired = FALSE, var.equal = FALSE, conf.level = 0.95)
t.test(hg1, hg2, alternative = c("two.sided"), mu = 0, paired = TRUE,
var.equal = FALSE, conf.level = 0.95)
#---------------
# Calculating a Single p Value From a Normal (z) Distribution
#Ho:µx=a,
#Ha:µx<a,
a <- 5
s <- 2
n <- 20
xbar <- 7
z <- (xbar-a)/(s/sqrt(n))
2*pnorm(-abs(z))
#--------------
#find Z critical value
qnorm(p, mean = 0, sd = 1, lower.tail = TRUE)
# Right-tailed test
qnorm(p=.05, lower.tail=FALSE)
# Two-tailed test
qnorm(p=.05/2, lower.tail=FALSE)
#--------------
#
#Calculating a Single p Value From a t Distribution
a <- 5
s <- 2
n <- 20
xbar <- 7
t <- (xbar-a)/(s/sqrt(n))
t
2*pt(-abs(t),df=n-1) # for two sided (dua arah atau tdk sama dengan)
#
#contoh dengan data:
#hipotesis:
#Ho: µx= 5.0
#H1: µx>5.0
x <- c(2.3, 4.1,3.5,2.7,4.8, 9.2,8.4, 10.1,3.6)
n <- length(x)
mean(x)
crit.value <- 3.0
t <- (mean(x)-crit.value)/(sd(x)/sqrt(n))
t
2*pt(-abs(t),df=n-1) # two sided
1*pt(-abs(t),df=n-1) # less or greates
#-------------
#program :
x <- c(2.3, 4.1,3.5,2.7,4.8, 9.2,8.4, 10.1,3.6)
t.test(x, alternative = c("two.sided"),mu = 3, conf.level = 0.95)
t.test(x, alternative = c("less"),mu = 3, conf.level = 0.95)
t.test(x, alternative = c("greater"),mu = 3, conf.level = 0.95)
#------------------

You might also like