getwd()
## [1] "/Users/owner/Downloads"
setwd("/Users/owner/Desktop/Lab 9 PSYC 2020 Assignment")
Use qnorm() and report each critical value to 3 decimals.
alpha <- 0.01
qnorm(alpha)
## [1] -2.326348
alpha <- 0.10
qnorm(1-alpha)
## [1] 1.281552
alpha <- 0.01
qnorm(alpha / 2)
## [1] -2.575829
qnorm(1 - alpha / 2)
## [1] 2.575829
Your answer:
z <- -2.10
critical_value <- qnorm(0.01)
z < critical_value
## [1] FALSE
Your answer: ## After finding the critical value, the result was “FALSE,” which means that we fail to reject H0 since z = -2.10 (which is not less than the critical value of -2.326). The test statistic is not far enough into the lower tail in order to have statistical significance at alpha value of 0.01
x <- iris$Sepal.Width
sample_mean <- mean(x)
sample_sd <- sd(x)
n <- length(x)
se <- sample_sd / sqrt(n)
sample_mean
## [1] 3.057333
sample_sd
## [1] 0.4358663
n
## [1] 150
se
## [1] 0.03558833
alpha <- 0.05
cutoff <- qnorm(1 - alpha / 2)
lower <- sample_mean - cutoff * se
upper <- sample_mean + cutoff * se
c(lower, upper)
## [1] 2.987581 3.127085
alpha <- 0.10
cutoff <- qnorm(1 - alpha / 2)
lower_90 <- sample_mean - cutoff * se
upper_90 <- sample_mean + cutoff * se
c(lower_90, upper_90)
## [1] 2.998796 3.115871
Your answer: ## The resulting lower value is 2.999, and the upper value is 3.116.
Your answer: ## There is 95% confidence that the true population mean sepal width of the iris flowers is between 2.988 cm and 3.127.
Your answer:
3.2 >= lower & 3.2 <= upper
## [1] FALSE
Your answer: ## The t cutoff is larger for small samples since small samples provide less precise estimates of the population standard deviation. The t-distribution accounts for this remaining uncertainty with heavier tails and a greater critical value. As the sample size increases, the t-distribution reaches the sample normal distribution, so its critical value gets smaller.
A car magazine claims cars average 22 mpg. Test this claim with the 32 cars in mtcars$mpg (σ unknown, α = .05).
Your answer:
cat("H0: mu = 22 mpg\nH1: mu != 22 mpg")
## H0: mu = 22 mpg
## H1: mu != 22 mpg
test <- t.test(mtcars$mpg, mu = 22, alternative = "two.sided")
test
##
## One Sample t-test
##
## data: mtcars$mpg
## t = -1.7921, df = 31, p-value = 0.08288
## alternative hypothesis: true mean is not equal to 22
## 95 percent confidence interval:
## 17.91768 22.26357
## sample estimates:
## mean of x
## 20.09062
test$statistic
## t
## -1.792127
test$parameter
## df
## 31
test$p.value
## [1] 0.08287848
if (test$p.value < 0.05) {
cat("Reject H0.")
} else {
cat("Fail to reject H0.")
}
## Fail to reject H0.
Your answer: ## This resulted in a failure to reject the null hypothesis, especially because the p-value is 0.0829 is greater than 0.05. There is not enough evidence to conclude that the population mean mpg is different from 22.
test$conf.int
## [1] 17.91768 22.26357
## attr(,"conf.level")
## [1] 0.95
test$conf.int[1] <= 22 & test$conf.int[2] >= 22
## [1] TRUE
Your answer: ## The confidence interval, which is about 17.918 to 22.264, does include 22 mpg. This is consistent with failing to reject the null hypothesis since 22 is a plausible value for the population mean based on the interval.
test_less <- t.test(mtcars$mpg, mu = 22, alternative = "less")
test_less
##
## One Sample t-test
##
## data: mtcars$mpg
## t = -1.7921, df = 31, p-value = 0.04144
## alternative hypothesis: true mean is less than 22
## 95 percent confidence interval:
## -Inf 21.89707
## sample estimates:
## mean of x
## 20.09062
test_less$p.value
## [1] 0.04143924
Your answer: ## This one-tailed test resulted in a p-value of about 0.0414, so I would reject the null hypothesis at a alpha value of 0.05. There is enough evidence that the poulation mean mpg is less than 22. The one-tailed test only considers the predicted lower direction, making it far more sensitive to evidence in that direction.
d <- (mean(mtcars$mpg) - 22) / sd(mtcars$mpg)
d
## [1] -0.3168063
Your answer: ## The resulting Cohen’s d value is -0.317 which indicates a small effect in the negative direction. This means that the sample mean mpg is lower than the claimed population mean of 22 mpg.
x <- mtcars$mpg
n_new <- 4 * length(x)
t_new <- (mean(x) - 22) / (sd(x) / sqrt(n_new))
p_new <- 2 * pt(-abs(t_new), df = n_new - 1)
d_new <- (mean(x) - 22) / sd(x)
t_new
## [1] -3.584254
p_new
## [1] 0.0004804257
d_new
## [1] -0.3168063
Your answer: ## The new t-statistic is -3.584, the new p-value is about 0.001, and the new Cohen’s d value is -0.317. If the sample size increased by four times, and the mean and standard deviation stayed the same, the magnitude of the t-statistic would double, the p-value would decrease, and the Cohen’s d would be unchanged. The larger sample would result in stronger statistical evidence without changing the approximate effect size.
Your answer: ## Statistical significance tells us whether there is enough evidence against the null hypothesis, and practical significance tells us whether an effect is substantial enough to matter in real-world situations. A result can be statistically significant without being practically important.