Note: this code is being submitted 1 day late, and I humbly request that it still be graded. I acknowledge the 10% off penalty and apologize for the inconvenience/delay.

1) [1 pt] Setting up

I will begin by setting the working directory to an easily accesible file in my “Desktop.” First, I will get the working directory to see where the file currently is.

getwd()
## [1] "/Users/owner/Downloads"
setwd("/Users/owner/Desktop/Lab 8 PSYC 2020L Assignment")

The working directory has been changed to an easily accesible file on my desktop.

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] Variance and SD, step by step

Hours studied last week by a sample of five students: 4, 6, 8, 10, 12.

2a. [0.5 pts] Compute the mean, the deviations, the squared deviations, and the sum of squares (SS).

This is me computing:

x <- c(4, 6, 8, 10, 12)

mean_x <- mean(x)
deviations <- x - mean_x
squared_deviations <- deviations^2
SS <- sum(squared_deviations)

mean_x
## [1] 8
deviations
## [1] -4 -2  0  2  4
squared_deviations
## [1] 16  4  0  4 16
SS
## [1] 40

These are the found values:

mean = 8

deviations = -4, -2, 0, 2, 4

squared deviations = 16, 14, 0, 4, 0, 4, 16

SS = 40

2b. [0.5 pts] Divide the SS by n − 1 to get the sample variance, then take the square root to get the SD. Check with var(x) and sd(x).

This is me dividing for the sample variance, getting the SD, and then checking with var(x) and sd(x):

n <- length(x)

sample_variance <- SS/(n-1)
sample_SD <- sqrt(sample_variance)

sample_variance
## [1] 10
sample_SD
## [1] 3.162278
var(x)
## [1] 10
sd(x)
## [1] 3.162278

The resulting sample variance is 10, the SD is 3.152278, and these values are confirmed after checking with var(x) and sd(x).

2c. [0.5 pts] Now divide the SS by n instead. Which one (n or n − 1) is correct for these data, and why?

Analysing the sample variance, SD, and SS:

population_variance <- SS/n
population_SD <- sqrt(population_variance)

population_variance
## [1] 8
population_SD
## [1] 2.828427

Your answer: ## The population variance is 8, and the SD is 2.2828427. (n-1) is correct since these data are of a sample of five students, and the sample variance uses (n-1) degrees of freedom to estimate the population variance.

2d. [0.5 pts] In one sentence, interpret the SD from 2b in the context of study hours.

Your answer: ## There is a variation from the mean (8 hours) that is about 3.16 hours.

3) [1.5 pts] z-scores for each observation

3a. [0.5 pts] Compute the z-score of every observation in x.

This is me computing the z-score:

z_scores <- (x - mean(x))/sd(x)

z_scores
## [1] -1.2649111 -0.6324555  0.0000000  0.6324555  1.2649111

The z-scores found are: -1.2649111, -0.6324555, 0.0000000, 0.6324555, and 1.2649111.

3b. [0.5 pts] How many z-scores did you get? How many variances does this dataset have? Explain the difference.

Your answer: ## I got five total z-scores for the five observations. There is only one sample variance, because the variance describes the spread of the entire dataset.

3c. [0.5 pts] Interpret the z-score of the student who studied 12 hours.

Your answer: ## The student who studied 12 hours has a z-score of about 1.26. This means that the student studied about 1.26 standard deviations above the sample mean.

4) [1 pt] Quiz 6 revisited

4a. [0.5 pts] For a two-tailed test with α = .05, the critical values of z are plus or minus ______. For a one-tailed test with α = .05, the critical value of z is ______, ignoring the sign.

Figuring out the fill-in-the-blanks by using qnorm():

qnorm(1 - 0.05 / 2)
## [1] 1.959964
qnorm(1 - 0.05)
## [1] 1.644854

Your answer: ## For a two-tailed test, the critical values of z are plus or minus 1.959964, and for a one-tailed test, plus or minus 1.644854.

4b. [0.5 pts] A hypothesis that predicts a difference without specifying its direction is called a ______ hypothesis, and it is tested with a ______-tailed test.

Your answer: ## A hypothesis that predicts a difference without specifiying its direction is called a non-directional hypothesis, and it is tested with a two-tailed test.

5) [2.5 pts] Hypothesis test, step by step

College students sleep μ = 7 hours a night, σ = 1.2. A random sample of n = 36 GT students sleeps x̄ = 6.64 hours. Do GT students sleep a different amount? Use α = .05.

5a. [0.5 pts] State H0 and H1. Is H1 directional or non-directional?

Your answer: ## The H0 is μ = 7 hours, and the H1 is μ (is not =) 7 hours. H1 is non-directional, since H1 is not equal to H0.

5b. [0.5 pts] Find the critical value(s) and compute the z-statistic.

Note: I use x_bar to represent the value that is mentioned as 6.64 hours in the prompt before 5.a.

This is me finding the critical value(s) and computing the z-statistic:

mu <- 7
sigma <- 1.2
n <- 36
x_bar <- 6.64

critical_values <- qnorm(c(0.025, 0.975))
z_statistic <- (6.64 - 7) / (1.2 / sqrt(36))

critical_values
## [1] -1.959964  1.959964
z_statistic
## [1] -1.8

The critical values are -1.959964 and 1.959964. The z-statistic is -1.8.

5c. [0.5 pts] Compute the two-tailed p-value. Reject or fail to reject H0? State your conclusion in words.

Two-tailed p-value computation with corresponding reject/fail output:

alpha <- 0.05
z <- (6.64 - 7) / (1.2 / sqrt(36))
p_value <- 2 * pnorm(-abs(z))

p_value
## [1] 0.07186064
if (p_value < alpha) {
  "Reject H0"
} else {
  "Fail to reject H0"
}
## [1] "Fail to reject H0"

Your answer: ## This resulted in a “Fail to reject H0”. There is not enough evidence at the significance level (0.05) in order to conclude that GT students sleep an amount of hours per night that is different from 7 hours. If the value was less than 0.05, there would be enough statistical significance.

5d. [0.5 pts] Suppose the researcher had predicted that GT students sleep less. Find the new critical value and the one-tailed p-value. Does your decision change?

Finding the new critical value and the one-tailed p-value, with -1.8 plugged in for z for my own convenience of understanding:

critical_value <- qnorm(alpha)
p_value_one_tailed <- pnorm(-1.8)

critical_value
## [1] -1.644854
p_value_one_tailed
## [1] 0.03593032
if (p_value_one_tailed < alpha) {
  "Reject H0"
} else {
  "Fail to reject H0"
}
## [1] "Reject H0"

Your answer: ## The critical value is -1.644854, or about -1.65. The one-tailed p-value is about 0.0359.

5e. [0.5 pts] In one sentence, interpret the two-tailed p-value from 5c.

Your answer: ## Based on the results above, the two-tailed p-value tells men that is the true population mean was 7 hours, then the probability of getting a sample mean at least as far from 7 hours as 6.64 hours, in either direction, would be a probability of approximately 7.19%.

6) [2 pts] Errors and power

6a. [0.5 pts] In 5c, suppose GT students really do sleep less than 7 hours. What kind of error, if any, did the two-tailed test make? Explain.

My answer below contains my rationale when I was identifying the error:

Your answer: ## A Type II error occurred since the test failed to reject H0, even though GT students do, in fact, sleep less than 7 hours per night.

6b. [0.5 pts] If a study has β = .30, what is its power? What does that number mean?

Calculating and interpreting the power:

Your answer: ## Power is (1-beta) which is equal to 1 - 0.30 = 0.70, or 70%. This indicates the study has a 70% probability of rejecting the null hypothesis when the alternative hypothesis is true.

In class, we were instructed to not complete 6.c and 6.d, so those sections have been deleted from here and this is now the end of the code.