R Z-test


The z-test tests the hypothesis H0: μ = μ0 against μ ≠ μ0 when the standard deviation σ is known.

Formula for Z Score:

z = √n(x - x0)/σ
Where:
n: Sample number
x: Population mean
x0: Hyposized population mean
σ: Standard Deviation

We hypothesize water volume will not change under X rays. So we checked 100 bottles of drinking water with 300 ml volume, and recorded the volume difference from 300 ml. We will test the Hypothesis H0: μ = 0 against μ ≠ 0.

Data in "tp.txt":

Calculate the Z Score:

> x <- read.csv("tp.txt",header=F)
> x <- x[1:100,]
> z <- sqrt(100) * (mean(x) - 0)/sd(x)
> z

[1] -0.2334861



Calculate P value:

> p <- 2 * pnorm(-abs(z),0,1)
> p

[1] 0.8153839


Since p>0.05, we accept the hypothesis.


We then hypothesize water volume will not change under higher temperature at 80 degrees. So we checked 100 bottles of drinking water with 300 ml volume, and recorded the volume difference from 300 ml. We will test the Hypothesis H0: μ = 0 against μ ≠ 0.

Data in "tp.txt":


Calculate the Z Score:

> x <- read.csv("tp.txt",header=F)
> x <- x[1:100,]
> z <- sqrt(100) * (mean(x) - 0)/sd(x)
> z

[1] 18.28636



Calculate P value:

> p <- 2 * pnorm(-abs(z),0,1)
> p

[1] 1.06279e-74


Since p < 0.05, the hypothesis is rejected.



endmemo.com © 2024  | Terms of Use | Privacy | Home