0% found this document useful (0 votes)
35 views4 pages

R Script Problem (Wrong Solutions)

This document contains the work and responses of a student, Quintus Zhou, for a statistics assignment with 4 questions. For question 1, Zhou generates a bar graph showing the sampling distribution of means for samples of size 4 from a population. For question 2, Zhou concludes that based on a z-test with α=0.05, there is sufficient evidence this year's class performed superior to previous classes in terms of final exam scores. For questions 3a and 3b, Zhou calculates the power to detect a mean increase of 2.0 mpg for sample sizes of 25 and 75 cars. For question 3c, Zhou calculates the type II error rate would be 0.0001 for a sample size of 25 cars.

Uploaded by

zzhquintus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

R Script Problem (Wrong Solutions)

This document contains the work and responses of a student, Quintus Zhou, for a statistics assignment with 4 questions. For question 1, Zhou generates a bar graph showing the sampling distribution of means for samples of size 4 from a population. For question 2, Zhou concludes that based on a z-test with α=0.05, there is sufficient evidence this year's class performed superior to previous classes in terms of final exam scores. For questions 3a and 3b, Zhou calculates the power to detect a mean increase of 2.0 mpg for sample sizes of 25 and 75 cars. For question 3c, Zhou calculates the type II error rate would be 0.0001 for a sample size of 25 cars.

Uploaded by

zzhquintus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Quintus Zhou Psyc 278 L01

40057291

Question 1 (3 pts.) Given the population set of scores {3,4,5,6,7,8,9}, use base R
graphics or ggplot to generate a bar graph representing the sampling distribution of
mean for samples of N = 4. Assume sampling is one at a time with replacement.
Give your graph a descriptive title, and be sure to include appropriate labels for the
yand x-axes.

Input:
scores <- c(3, 4, 5, 6, 7, 8, 9)
N <- 4
num_samples <- 1000
samp.dist.m <- data.frame(expand.grid(rep(list(scores), N)))
samp.dist.m <- samp.dist.m[, c(2, 1)]
colnames(samp.dist.m) <- c('score.1', 'score.2')
samp.dist.m$mean <- rowMeans(samp.dist.m)
t <- table(round(samp.dist.m$mean, 2))
print(t)
require(latex2exp)
pct <- as.numeric(t) / sum(t)
xlab <- names(t)
df <- data.frame(xlab, pct)
p <- ggplot(data = df, aes(x = xlab, y = pct)) +
geom_bar(stat = "identity", fill = 'skyblue3') +
labs(x = TeX("$\\bar{\\textit{X}}$"),
y = TeX("$\\textit{p}(\\bar{\\textit{X}})$"),
title = "Sampling distribution of means (n=4)") +
theme_classic() +
scale_y_continuous(breaks = seq(0, 0.24, .04)) +
theme(axis.title.x = element_text(margin =
unit(c(3.5,0,0,0), "mm"), size = 11),
axis.title.y = element_text(margin =
unit(c(0,3.5,0,0), "mm"), size = 11),
axis.text = element_text(size = 9.5))
ggsave(filename = "hw6plot.png", plot = p, width = 5, height =
4, units = "in", dpi = 400)

Output:
Quintus Zhou Psyc 278 L01
40057291

Question 2 (2 pts.) A professor has been teaching statistics for many years. His
records show that the overall mean for final exam scores is 73, with a standard
deviation of 11. The professor believes that this year’s class is superior to his
previous ones. The mean for final exam scores for this year’s class of 68 students is
76. Using 𝛼 = 0.051-tail, state your conclusion and report Zobt and the associated
p-value.

Input:
N <- 68
Mu <- 73
Sigma <- 11
Xbar.Obt <- 76
alpha <- 0.05
Xbar.Obt.SE <- Sigma / sqrt(N)
Zobt <- (Xbar.Obt - Mu) / Xbar.Obt.SE
Zcrit <- qnorm(alpha, lower.tail = FALSE)
reject_null <- Zobt > Zcrit
p_value <- (pnorm(Zobt, lower.tail = FALSE)
print(round(Zobt, 2))
print(round(Zcrit, 2))
Quintus Zhou Psyc 278 L01
40057291
print(round(p_value, 2))

Output:
Since the absolute value of Zobt (2.25) is greater than the critical Z-value (1.64) and
the p=0.01, we reject the null hypothesis. There is sufficient evidence to conclude
that this year's class performs superior to previous ones in terms of final exam
scores.

Question 3 (4 pts.) Pagano’s (2013, p. 316) Practice Problem 12.2 presented


hypothetical data testing a new gasoline additive. A large number of mileage
measurements on the gasoline without the additive showed a mean of 24.7 miles per
gallon and a standard deviation of 4.8. An experiment was performed in which 75
cars were tested using the gasoline plus the additive. The results showed a sample
mean of 26.5 miles per gallon. To evaluate these data, a directional test with 𝛼 =
0.051-tail was used. Suppose that before doing the experiment, the manufacturer
wants to determine the probability that he will be able to detect a real mean increase
of 2.0 miles per gallon with the additive if the additive is at least that effective.

a. If he tests 25 cars, what is the power to detect a mean increase of 2.0 miles per
gallon? Report your answer to exactly four decimal places. (1 pt.)

Input:
x1 <- 24.7
s <- 4.8
n <- 25
alpha <- 0.051
mu_real <- 2.0
x2 <- x1 + mu_real
sem <- s / sqrt(n)
zcrit <- qnorm(p = alpha, lower.tail = TRUE)
xcrit <- x1 + zcrit * sem
zobt <- (x2 - x1) / sem
power_a <- pnorm(zobt - zcrit, lower.tail = TRUE)
print(round(power_a, 4))

Output:
0.9999

b. If he increases the N to 75 cars, what is the power to detect a mean increase of


2.0 miles per gallon? Report your answer to exactly four decimal places. (1 pt.)

Input:
n <- 75
Quintus Zhou Psyc 278 L01
40057291
sem <- s / sqrt(n)
xcrit <- x1 + zcrit * sem
zobt <- (x2 - x1) / sem
power_b <- pnorm(zobt - zcrit, lower.tail = TRUE)
print(round(power_b, 4))

Output:
1.0000

c. Again using only 25 cars, what is the probability the manufacturer would make a
type-II error rate if there was a mean increase of 2.0 miles per gallon? Report your
answer to exactly four decimal places. (1 pt.)

Input:
beta <- 1 - power_a
print(round(beta, 4))

Output:
1e-04

d. How many cars should he use if he wants to have a 95% chance of detecting a
mean increase of 2.0 miles per gallon? Use 𝛼 = 0.051-tail and report your answer to
the nearest integer that satisfies the power requirement. (1 pt.)

He should use the initial sample size as it was already sufficient.

You might also like