0% found this document useful (0 votes)
12 views8 pages

Week5 ProblemSet Solutions

The document presents a problem set for a statistics course, focusing on the relationship between social media usage and student anxiety levels. It includes data analysis, hypothesis testing, and the interpretation of results, indicating that high social media usage correlates with higher anxiety. The findings suggest a significant difference in anxiety levels between high and low social media users, supported by a p-value of 0.009.

Uploaded by

zoe909714
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)
12 views8 pages

Week5 ProblemSet Solutions

The document presents a problem set for a statistics course, focusing on the relationship between social media usage and student anxiety levels. It includes data analysis, hypothesis testing, and the interpretation of results, indicating that high social media usage correlates with higher anxiety. The findings suggest a significant difference in anxiety levels between high and low social media users, supported by a p-value of 0.009.

Uploaded by

zoe909714
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

35898 358 98 35898

y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A

STA130H1F – Winter 2021


Week 5 Problem Set
98 98
2358 2358
y Zoe [Link], N. Moon, and [Link] y Zo
e
em cade em
EZ Acad EZ A EZ Acad

Part 1
Question 1 [Required]
98 been many questions regarding whether
There 5have or8 not usage of social media increases
3589 98
o e 23 8levels. A study was conducted to examine
anxiety o e 2the relationship between social media usageo e 2358
y Z y Z y Z
A c adem and student anxiety. The following A c dem are measures of anxiety levels of students
ascores A c adem on a
EZ Z
Monday. Higher scores indicate Ehigher anxiety; and, if a student used social mediaEZ more than
1 hour per day then their usage was categorized as “High”.

social_media_usage <- c(rep("Low", 30), rep("High", 16));


anxiety_score <- c(24.64, 39.29, 16.32, 32.83, 28.02,
33.31, 20.60, 21.13, 26.69, 28.90,
26.43, 24.23, 7.10, 32.86, 21.06,
2 3 5898 28.71, 31.73,
28.89, 30.02, 21.96, 2 3589
8
e e e
m y Zo 25.49, 38.81, 27.85, 30.29, 30.72, y Zo y Zo
A ca d e
A c adem Acad
em
E Z 21.43, 22.24, 11.12, 30.86,
EZ 19.92, EZ
33.57, 34.09, 27.63, 31.26,
35.91, 26.68, 29.49, 35.32,
26.24, 32.34, 31.34, 33.53,
27.62, 42.91, 30.20, 32.54)

anxiety_data <- tibble(social_media_usage, anxiety_score)


98 98 98
2358
glimpse(anxiety_data) 2358 oe 2
358
Zoe Zoe Z
c a d emy c a d emy cade
m y
EZ A ## Rows: 46 EZ A EZ A
## Columns: 2
## $ social_media_usage <chr> "Low", "Low", "Low", "Low", "Low", "Low", "Low", "L~
## $ anxiety_score <dbl> 24.64, 39.29, 16.32, 32.83, 28.02, 33.31, 20.60, 21~

(a) Construct boxplots of anxiety_score for the two levels of social media usage. Write 2-3
sentences comparing the distributions of anxiety scores across the social media usage groups.
8 8
e 2 3589 e 2 3589 e
anxiety_data o ggplot(aes(y=social_media_usage, x=anxiety_score))
y Z%>% y Zo + y Zo
A c adem
geom_boxplot() A c adem Acad
em
EZ EZ EZ

35898 358 98 35898


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A
1
358 98 358 98 35898
y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A

Low
social_media_usage

98 98
2358 2358
y Zoe y Zoe y Zo
e
em em em
EZ Acad EZ Acad EZ Acad

High

358 98 358 98 35898


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A 10 EZ A 20 30 EZ A40
anxiety_score

There indeed appears to be a clear difference in anxiety between “Low” and “High” social media
usage groups, with the median of the latter exceeding the 75th percentile of the former. For the
“High” social media usage group, the anxiety scores are much more concentrated around high
(>30) anxiety scores; whereas, for the “Low” social media usage group the anxiety scores are
much more highly 2 3 5898
variable, with the upper 50% of anxiety 2
scores3 898the “Low” social media
5in
Zoe
my overlapping
usage agroup or even exceeding those in athe m
“High”
e
y Zo social media usage group, and m y Zo
e
d e d e ca d e
E Z Acof the lower 50% of anxiety scores in theE“Low”
most Z Ac social media usage group being less than EZ A
those in the “High” social media usage group.

(b) Do these data support the claim that the median anxiety level is different for those who
use social media in high frequency compared to those who use social media in lower frequency?
(i) State the hypotheses you are testing (be sure to define any parameters you refer to).
358 98 98 98
oe 2“High” social media usage population H
For and 2358 social media usage population L with
oe “Low” oe 2
358
y Z
m medians 50%H and 50%L , respectively,adem y Z m y Z
cade c cade
EZ A EZ A EZ A
H0 : 50%H = 50%L HA : 50%H 6= 50%L
(ii) Look at the code below and write a few sentences explaining what the code inside the for loop is doing
and why.
# Note: including the .groups="drop" option in summarise() will suppress a friendly
# warning R prints otherwise
8 "`summarise()` ungrouping output (override
8 with
#`.groups` argument)".
e 2 3589 e 2 3589 e
y Zothe .groups="drop" option is optional,em
# Including y Zo y Zo
A c adem A c ad but you should include it if you Acad
em
Z
#don't
E want to see that warning. EZ EZ
test_stat <- anxiety_data %>% group_by(social_media_usage) %>%
summarise(medians = median(anxiety_score), .groups="drop") %>%
summarise(value = diff(medians))
test_stat <- [Link](test_stat)
test_stat

89 8 98 98
## [1]
235-4.57 358 358
Zoe Z oe 2 Z oe 2
c a d emy cade
m y
cade
m y
EZ A EZ A EZ A
2
98 98 98
o e 2358 oe 2
358
oe 2
358
y Z y Z y Z
A c adem cade
m
cade
m
EZ [Link](523) EZ A EZ A
repetitions <- 1000;
simulated_values <- rep(NA, repetitions)

for(i in 1:repetitions){
simdata <- anxiety_data %>% mutate(social_media_usage = sample(social_media_usage))

sim_value <- 23
simdata
5898 23 5898
m y Zoe m y Zoe
%>% group_by(social_media_usage) %>%
y Zo
e
cade = median(anxiety_score), .groups="drop")
cade em
Acad
summarise(medians %>%
EZ Asummarise(value = diff(medians)) EZ A EZ

simulated_values[i] <- [Link](sim_value)


}

sim <- tibble(median_diff = simulated_values)

358 98 358 98 358 98


sim color="black", fill="gray")
Zoe 2%>% ggplot(aes(x=median_diff)) + geom_histogram(binwidth=1,
oe 2 Z oe 2 Z
cademy cademy cademy
EZ A EZ A EZ A

150

98 98
2358 2358
y Zoe y Zoe y Zo
e
em em em
EZ Acad EZ Acad EZ Acad
100
count

8 98 98
3589
250 358 358
y Z o e
y Z oe 2 y Z oe 2
A c adem cade
m
cade
m
EZ EZ A EZ A

−6 −3 0 3 6
58 98 median_diff 589 8
o e 23 o e 23 e
my Z my Z
em y Zo
# Z A cade
Calculate p-value Z A cade Acad
E E EZ
num_more_extreme <- sim %>% filter(abs(median_diff) >= abs(test_stat)) %>% summarise(n())

p_value <- [Link](num_more_extreme / repetitions)


p_value

## [1] 0.009
98
358 in the for loop is first shuffling the e“High” 98 98
The 2code 2358 and “Low” social media usage group 2358
Zoe Zo Zoe
cademy cademy cademy
EZ A EZ A EZ A
3
98 98 98
o e 2358 o e 2358 o e 2358
y Z y Z y Z
A c adem A c adem A c adem
EZ EZmeans the outcomes for both groups are sampled
labels for each observation. This EZ from the
same population (i.e, our sample), or, equivalently, that group label doesn’t matter in terms
of what the median of the population of a sample will be. But this then means that the null
hypothesis is true for these simulated data. So the subsequently calculated (median) statistic
represents a draw from the sampling distribution of the median under the assumption that the
null hypothesis is true. And by repeatedly sampling in this manner we create a simulation of
the sampling distribution of the median under the null hypothesis.
8 8
3589
2 e 2 3589
(iii) Write a few
m y Zoesentences summarizing your conclusions. Be sure
m y Zointerpret
to the p-value carefully and to
m y Zo
e
ca d e
clearly address the research question. ca d e ca d e
EZ A EZ A EZ A
At a alpha=0.05 significance level we reject the null hypothesis that the median anxiety level
among “High” and “Low” social media usage groups is the same. The p-value of 0.009 rep-
resents “very strong” evidence against the null hypothesis. Further, the observed difference
indicates that individuals with “High” social media usage have MORE anxiety than individu-
als with “High” social media usage; however, in rejecting the null hypothesis in favor of the
alternative hypothesis, all we are “formally” claiming is that the groups have different medi-
8 other hand, since the evidence against the
589the 98 98
ans.23
o e
On
o e 2358 null hypothesis is “very strong”, it is o e 2358
y Zsensible to conclude that “High” social media y Zusage increases anxiety relative to “Low” y Z
social
A c adem media usage. A c adem A c adem
EZ EZ EZ

98 98
2358 2358
y Zoe y Zoe y Zo
e
em em em
EZ Acad EZ Acad EZ Acad

358 98 358 98 358 98


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A

98 98
2358 2358
y Zoe y Zoe y Zo
e
em em em
EZ Acad EZ Acad EZ Acad

358 98 358 98 358 98


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A
4
98 98 98
o e 2358 oe 2
358
oe 2
358
y Z y Z y Z
A c adem cade
m
cade
m
EZ Question 2 [Optional] EZ A EZ A
A criminal court considers two opposing claims about a defendant: they are either innocent or guilty. In the
Canadian legal system, the role of the prosecutor is to present convincing evidence that the defendant is not
innocent. Lawyers for the defendant attempt to argue that the evidence is not convincing enough to rule out
that the defendant could be innocent. If there is not enough evidence to convict the defendant and they are
set free, the judge generally does not deliver a verdict of “innocent”, but rather of “not guilty”.
8 8
e 2 3589 e 2 3589 e
(a) If we look o the criminal trial example in the hypothesis
y Zat y Zotest framework, which would be y Zo
d e m d e m d e m
ca hypothesis and which the alternative? Z Aca
the null ca
EZ A E EZ A
H0 : Defendent is Innocent HA : Defendent is Guilty

(b) In the context of this problem, describe what rejecting the null hypothesis would mean.
Convicting Someone with a “Guilty” sentencing.

898context of this problem, describe what2failing


235the
(c) In 8
3589 to reject the null hypothesis woulde 23589
8
o e o e o
y Zmean. y Z y Z
A c adem A c adem A c adem
EZ EZ
The defendant succeeding in convincing EZ
the court that there was not enough evidence to form
the basis of a conviction.

(d) In the context of this problem, describe what a type II error would be.
A guilty defendant being set free.

98
8 problem, describe what a type I error 2would
35this 58 be. 98
e 2of
(e) In the context e 3 e
y Zo y Zo y Zo
An c adem defendant being wrongly convicted asAcbeing
innocent
A ademguilty. Acad
em
EZ EZ EZ

35898 358 98 358 98


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A

98 98
2358 2358
y Zoe y Zoe y Zo
e
em em em
EZ Acad EZ Acad EZ Acad

35898 358 98 358 98


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A
5
98 98 98
o e 2358 oe 2
358
oe 2
358
y Z y Z y Z
A c adem cade
m
cade
m
EZ Question 3 [Optional] EZ A EZ A
(Adapted from “Biostatistics for the Biological and Health Sciences”) The table below presents
data from a random sample of passengers sitting in the front seat of cars involved in car crashes. Researchers
are interested in whether the fatality rates (i.e. death rates) differ for passengers in cars with airbags and
passengers in cars without airbags.

98 8
3589available
2358
Airbag available No airbag
2
y Zoe oe
y Z62 y Zo
e
cadem Passenger Fatalities 45
ca d e m
Acad
em
EZ A Total number of Passengers EZ A
10,541 9,867 EZ

The code below creates a tidy data frame for this problem, using the R command rep. This function creates a
vector which replicates its first argument the number of times indicated by its second argument. For example,
the rep("hello", 5) creates a vector with 5 elements, each of which is “hello”. Run the code chunk below
to load a tidy tibble called data which you’ll use for the remainder of this question.
35 898 2358
98 358 98
oe 2
library(tidyverse)
y Z y Z o e
y Z oe 2
A c adem A c adem cade
m
EZ EZ
data <- tibble(group=c(rep("airbag",10541),rep("no_airbag",9867)), EZ A
outcome=c(rep("dead",45), rep("alive",10541-45),
rep("dead",62), rep("alive",9867-62)))

(a) State appropriate hypotheses to compare the proportions of deaths in cars with and without
airbags. Be sure to define any parameters you refer to in your hypotheses.
For cars with (W) 2and898
35 without (WO) airbags having chance ofe death 898
235 in a car crash of πW and
m y Zoe m y Zo y Zo
e
πW O , a
respectively,
de we consider the one-sided hypothesis
ade test em
EZ A
c
EZ A
c
EZ Acad

H0 : πW = πW O HA : πW < πW O
which means “as or more extreme under the null hypothesis” will only consider test statistics
sampled under the null hypothesis which are less than or equal to the observed test statistic.
Generally, one-sided hypothesis tests lead to smaller p-values since only half of the outcomes
that would be considered “as or more extreme” are actually counted as being so.
98 98 98
o e 2358 o e 2358 oe 2
358
y Z emy
Z y Z
A c adem (b) Carry out a hypothesis test for Athe
c adhypotheses stated in part (a).
cade
m
EZ EZ EZ A
[Link](523) # Replace the number in the parentheses with the 1st, 3rd, and 5th
# digits in your student number.

test_stat <- data %>%


mutate(outcome = case_when(outcome=='dead'~1, outcome!='dead'~0)) %>%
group_by(group) %>%
5898
summarise(prop =23mean(outcome), .group="drop") %>% 2 3589
8
e
o = diff(prop)) o e e
my Z
summarise(value
e my Z e emy Zo
EZ Acad EZ Acad EZ Acad
repetitions <- 1000;
simulated_values <- rep(NA, repetitions)

for(i in 1:repetitions){
simdata <- data %>% mutate(group = sample(group))

sim_value
98 <- simdata %>%
358 358 98 358 98
y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A
6
98 98 98
o e 2358 o e 2358 o e 2358
y Z y Z y Z
A c adem A c adem A c adem
EZ EZ
mutate(outcome = case_when(outcome=='dead'~1, outcome!='dead'~0)) %>% E
Z
group_by(group) %>%
summarise(prop = mean(outcome), .group="drop") %>%
summarise(value = diff(prop))

simulated_values[i] <- [Link](sim_value)


} 98 98
2358 2358
Zoe Zoe y Zo
e
sim <- emy
cadtibble(prop_diff = simulated_values) em y em
EZ A EZ Acad EZ Acad
# Calculate p-value
num_more_extreme <- sim %>% filter(prop_diff >= [Link](test_stat)) %>% summarise(n())
p_value <- [Link](num_more_extreme / repetitions)
p_value

## [1] 0.027
98 98 98
#o 2358for scratch work if needed
space
e oe 2
358
oe 2
358
Z Z Z
cademy cade
m y
cade
m y
EZ A EZ A EZ A
(c) Based on your answer in part (b), would you reject the null hypothesis at the 0.1 significance
level?
Yes – the p-value is less than 0.1.

(d) Based on your answer in part (c), what kind of error did you possibly make?
8 8
If the decision to 2 3589 the null hypothesis is wrong then we e
reject have 89 a Type I Error.
235made
yZoe yZo y Zo
e
em em em
EZ Acad EZ Acad EZ Acad

35898 35898 358 98


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A

98 98
2358 2358
y Zoe y Zoe y Zo
e
em em em
EZ Acad EZ Acad EZ Acad

35898 35898 358 98


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A
7
98 98 98
o e 2358 oe 2
358
oe 2
358
y Z y Z y Z
A c adem cade
m
cade
m
EZ Question 4 [Optional] EZ A EZ A
In class we’ve talked about two kinds of hypothesis tests. In the first kind (week 4) we talked about how to
test whether a proportion is equal to a specific value, with hypotheses of the form: H0 : p = p0 vs HA : p 6= p0 .
In this week’s class (week 5), we talked about how to test if there is a difference between two groups (e.g. a
difference in the means of two groups, the medians of two groups, or proportions of two groups). A test for
the difference between the means of two groups takes the form: H0 : µ1 = µ2 vs HA : µ1 6= µ2 .
589 8 8
89 sure to carefully define any
For each of the following ande H2A3.5Be
e 23 scenarios, state appropriate hypotheses H0 Z e
y Z o y o y Zo
parameters
demyou refer to. dem em
EZ A
ca
EZ A
ca
EZ Acad
(a) A health survey asked individuals to report the number of times they exercised each week.
Researchers were interested in determining if the proportion of individuals who exercised at
least 100 minutes per week differed between people who live in the condos vs people who do
not live in condos.
H0 : pcondo = pnocondo vs HA : pcondo 6= pnocondo where pcondo is the proportion of daily condo
898
owners/renters
235livers
who exercise at least 100 min per week
2358
98and pnocondo is the proportion of non-
2358
98
Z o e
condo who exercise at least 100 min per
Z o e
week. Z o e
cademy cad emy cad emy
EZ A EZ A EZ A
(b) A study was conducted to examine whether a baby is born prematurely/early (i.e., before
their due date) to whether or not the baby’s mother smoked while she was pregnant.
H0 : psmoking = pnonsmoking vs HA : psmoking 6= pnonsmoking , where psmoking is the proportion of
premature babies born to smoking mothers and pnonsmoking is the proportion of premature babies
born to non-smoking mothers. Under the null hypothesis that there is no relationship between
a baby’s earliness and whether or not the mother smoked, there should be no difference between
5898 5898
e 23 . Note that there are other correct wayse to
psmoking and pnonsmoking 23formulate these hypotheses. e
em y Zo em y Zo emy Zo
E
(c) Acad
Z Nintendo is interested in whether or not E Acad
Z online advertisements are working. They
their EZ Acad
record whether or not a user had seen an ad on a given day and their amount of spending
on Nintendo products in the next 48 hours. They are interested in determining if there is an
association between whether or not the user say an ad and their expenditures.
Since the researcher is interested in comparing values of a numerical variable (spending) across
two groups (seen or not seen the ad), a two-sample test comparing the mean (or median)
spending 8 the two groups (saw ad vs did not see ad)
589for 5898would be appropriate. 9 8
o e 23 o e 23 o e 2358
y ZH0 : µad = µ[Link] vs HA : µad 6= µ[Link] , where y Z is the mean spending for users who sayem
µ y Z
the ad
A c adem A c adem ad A c ad
EZ and µ[Link] is the mean spending Efor Z those who did not see the ad. EZ

(d) Based on results from a survey of graduates from the University of Toronto, we would like
to compare the median salaries of graduates from the statistics and graduates of mathematics
programs.
H0 : Mstat = Mmath vs HA : Mstat 6= Mmath where Mstat is the median salary for graduates of
statistics programs and 8M is the median salary for graduates of 8
math programs.
3589 math
e 2 3589 e 2 e
e m y Zo e m y Zo emy Zo
ca d ca d Acad
EZ A EZ A EZ

358 98 358 98 358 98


y Z oe 2 y Z oe 2 y Z oe 2
m m m
cade cade cade
EZ A EZ A EZ A
8

You might also like