getwd()
## [1] "/Users/owner/Downloads"
setwd("/Users/owner/Desktop/Lab 8 PSYC 2020L Assignment")
Hours studied last week by a sample of five students: 4, 6, 8, 10, 12.
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
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
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.
Your answer: ## There is a variation from the mean (8 hours) that is about 3.16 hours.
z_scores <- (x - mean(x))/sd(x)
z_scores
## [1] -1.2649111 -0.6324555 0.0000000 0.6324555 1.2649111
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.
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.
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.
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.
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.
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.
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
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.
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.
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%.
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.
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.