# NOT RUN {
dat.bs <- data.frame(group = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
x = c(3, 1, 4, 2, 5, 3, 2, 3, 6, 4, 3, NA))
#--------------------------------------
# Between-Subject Design
# Two-sided one sample z-test with 95% confidence interval
# population mean = 3, population standard deviation = 1.2
z.test(dat.bs$x, sigma = 1.2, mu = 3)
# Two-sided one sample z-test with 95% confidence interval
# population mean = 3, population variance = 1.44
z.test(dat.bs$x, sigma2 = 1.44, mu = 3)
# One-sided one sample z-test with 95% confidence interval
# population mean = 3, population standard deviation = 1.2
z.test(dat.bs$x, sigma = 1.2, mu = 3, alternative = "greater")
# Two-sided one sample z-test with 95% confidence interval
# population mean = 3, population standard deviation = 1.2
# # convert value 3 to NA
z.test(dat.bs$x, sigma = 1.2, mu = 3, as.na = 3)
# Two-sided one sample z-test with 99% confidence interval
# population mean = 3, population standard deviation = 1.2
z.test(dat.bs$x, sigma = 1.2, mu = 3, conf.level = 0.99)
# Two-sided one sample z-test with 95% confidence interval
# population mean = 3, population standard deviation = 1.2
# print descriptive statistics with 3 digits and p-value with 5 digits
z.test(dat.bs$x, sigma = 1.2, mu = 3, digits = 3, p.digits = 5)
# Two-sided two sample z-test with 95% confidence interval
# population standard deviation (SD) = 1.2, equal SD assumption
z.test(x ~ group, sigma = 1.2, data = dat.bs)
# Two-sided two sample z-test with 95% confidence interval
# population standard deviation = 1.2 and 1.5
z.test(x ~ group, sigma = c(1.2, 1.5), data = dat.bs)
# Two-sided two sample z-test with 95% confidence interval
# population variance = 1.44 and 2.25
z.test(x ~ group, sigma = c(1.44, 2.25), data = dat.bs)
# One-sided two sample z-test with 95% confidence interval
# population standard deviation (SD) = 1.2, equal SD assumption
z.test(x ~ group, sigma = 1.2, data = dat.bs, alternative = "less")
#-----------------
group1 <- c(3, 1, 4, 2, 5, 3, 6, 7)
group2 <- c(5, 2, 4, 3, 1)
# Two-sided two sample z-test with 95% confidence interval
# population standard deviation (SD) = 1.2, equal SD assumption
z.test(group1, group2, sigma = 1.2, data = dat.bs)
#--------------------------------------
# Within-Subject Design
dat.ws <- data.frame(pre = c(1, 3, 2, 5, 7),
post = c(2, 2, 1, 6, 8), stringsAsFactors = FALSE)
# Two-sided paired sample z-test with 95% confidence interval
# population standard deviation of difference score = 1.2
z.test(dat.ws$pre, dat.ws$post, sigma = 1.2, paired = TRUE)
# Two-sided paired sample z-test with 95% confidence interval
# population variance of difference score = 1.44
z.test(dat.ws$pre, dat.ws$post, sigma2 = 1.44, paired = TRUE)
# One-sided paired sample z-test with 95% confidence interval
# population standard deviation of difference score = 1.2
# }
Run the code above in your browser using DataLab