1) [1 pt] Setting up

I will now check the working directory.

getwd()
## [1] "/Users/owner/Downloads"

I will now set the working directory to an easily accesible file in my “Desktop.”

setwd("/Users/owner/Desktop/Lab 9 PSYC 2020 Assignment")

Now that the working directory has been set, I will begin the prompts.

1a. [0.5 pts] Rename the template and fill out the author and date lines.

Done!

1b. [0.5 pts] Knit the empty template once to make sure it knits without errors before you start.

Done!

2) [2 pts] Review of Lab 7: critical values

Use qnorm() and report each critical value to 3 decimals.

2a. [0.5 pts] A study app is predicted to make students spend less time on homework. Lower-tail critical value for α = .01?

I will find the lower-tail critical value using alpha and qnorm():

alpha <- 0.01
qnorm(alpha)
## [1] -2.326348

The lower-tail critical value is -2.326.

2b. [0.5 pts] A training program is predicted to make runners score higher on a fitness test. Upper-tail critical value for α = .10?

I will find the upper tail using alpha and an adjusted qnorm():

alpha <- 0.10
qnorm(1-alpha)
## [1] 1.281552

The upper-tail critical value is 1.281.

2c. [0.5 pts] Does music change memory scores (no direction predicted)? Both two-tailed critical values for α = .01. Which one do you compare to if the sample mean is above μ? Below μ?

I will find both of the two-tailed critical values using alpha and adjustments to qnorm():

alpha <- 0.01
qnorm(alpha / 2)
## [1] -2.575829
qnorm(1 - alpha / 2)
## [1] 2.575829

I would compare to the upper-tail critical value of 2.576 if the sample mean was above μ. If the sample mean was below μ, I would compare to the lower-tail critical value, -2.576.

Your answer:

2d. [0.5 pts] In 2a (lower-tailed, α = .01), the test statistic is z = −2.10. Reject or fail to reject H0? Explain using the critical value.

I will find the critical value:

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

3) [2 pts] Confidence interval by hand (iris$Sepal.Width)

3a. [0.5 pts] Compute the sample mean, the sample SD, n, and the standard error.

This is me calculating the descriptive statistics and standard error:

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

The sample mean is 3.057, the sample SD is 0.436, n is 150, and the standard error is 0.036.

3b. [0.5 pts] Use qnorm() to find the cutoff and compute the 95% CI for the mean sepal width.

This is me calculating the 95% confidence interval:

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

The lower and upper bounds of the 95% confidence interval are 2.988 and 3.127, respectively.

3c. [0.5 pts] Compute the 90% CI. Which interval is wider, and why?

This is me calculating the 90% confidence interval:

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.

3d. [0.5 pts] In one sentence, interpret the 95% CI from 3b.

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.

4) [1 pt] CIs, NHST, and the t-distribution

4a. [0.5 pts] A botanist claims the mean sepal width is 3.2 cm. Using only your 95% CI from 3b, would you reject H0: μ = 3.2 (two-tailed, α = .05)? Explain.

Your answer:

4b. [0.5 pts] Find the 95% two-tailed t cutoff for n = 10 and for n = 150, and compare both to qnorm(.975). Why is the t cutoff bigger for small samples?

This is me testing the claim using the 95% confidence interval:

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.

5) [2.5 pts] One-sample t-test (mtcars$mpg)

A car magazine claims cars average 22 mpg. Test this claim with the 32 cars in mtcars$mpg (σ unknown, α = .05).

5a. [0.5 pts] State H0 and H1 for a two-tailed test.

This is me stating the null and alternative hypotheses:

Your answer:

cat("H0: mu = 22 mpg\nH1: mu != 22 mpg")
## H0: mu = 22 mpg
## H1: mu != 22 mpg

Null hypothesis: the population mean fuel efficiency is 22 mpg.

Alternative hypothesis: the population mean differs from 22 mpg.

5b. [0.5 pts] Run t.test() and report t, df, and the p-value.

This is me running the two-tailed t-test:

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

The resulting t-statistic is -1.792, there are 31 degrees of freddom, and the p-value is 0.0829.

5c. [0.5 pts] Do you reject or fail to reject H0? State your conclusion in words.

This is me deciding whether or not to reject the null hypothesis:

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.

5d. [0.5 pts] Does the 95% CI from t.test() include 22? Is that consistent with your decision in 5c?

This is me checking whether the confidence interval includes 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.

5e. [0.5 pts] Critics predicted, before collecting data, that cars get less than 22 mpg. Run the one-tailed test (alternative = “less”). Report the p-value and your decision. Did it change? Why?

This is me running the lower-tailed t-test:

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.

6) [1.5 pts] Effect size

6a. [0.5 pts] Compute Cohen’s d for the test in Question 5. Is it a small, medium, or large effect? Which direction?

This is me calculating and classifying Cohen’s d:

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.

6b. [0.5 pts] Suppose the magazine had tested 4 times as many cars and found the same mean and SD. What would happen to t, the p-value, and d?

This is me examining the effect of quadrupling sample size:

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.

6c. [0.5 pts] In one or two sentences, explain the difference between statistical significance and practical significance.

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.