TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Bura)/Übungen 2020W/HW12.3

Aus VoWi
Zur Navigation springen Zur Suche springen

Two-sample test for proportions (with R)[Bearbeiten | Quelltext bearbeiten]

Students were interviewed regarding the outcome of an exam. Does the regular participation of the associated lecture have an impact on the pass of the exam? The results of the interview are stored in the data Umfrage.Rdata (1 = passed / 0 = failed). Test the null hypothesis that the participation in the lecture does not have an impact on the outcome of the exam.

  • (a)  In a barplot, represent the proportions of passed exams depending on whether the lecture was taken or not. Mark the standard errors.
  • (b)  Comment on your graphic.
  • (c)  Test the null hypothesis on the 5% level with a two-sided test for the comparison of two proportions.
  • (d)  Interpret your result.

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 18:26:49 CET

# Statistics and Probability: HW #12
# Friday 
# Duedate: 18.01.2021

# 3) Two-sample test for proportions (with R)
# Students were interviewed regarding the outcome of an exam. Does the regular 
# participation of the associated lecture have an impact on the pass of the 
# exam? The results of the interview are stored in the data Umfrage.Rdata 
# (1 = passed / 0 = failed). Test the null hypothesis that the participation 
# in the lecture does not have an impact on the outcome of the exam.
load("Umfrage.Rdata")
(par(mfrow=c(1,1)))

# 3a)
# In a barplot, represent the proportions of passed exams depending on whether 
# the lecture was taken or not. Mark the standard errors.
n1 <- length(umfrage$vorlesung_besucht)
n2 <- length(umfrage$vorlesung_verpasst)
v1 <- rev(table(umfrage$vorlesung_besucht) / n1)
v2 <- rev(table(umfrage$vorlesung_verpasst) / n2)
m <- matrix(c(v1,v2), ncol=2)
barplot(m, horiz = TRUE, col=c('lightcoral','lightblue'))
h1 <- v1[1]
h2 <- v2[1]
s1 <- sqrt((h1*(1-h1))/n1)
s2 <- sqrt((h2*(1-h2))/n2)
arrows(v2[1]-s2,1.9,v2[1]+s2,1.9, angle=90, length=0.05, code=3, lw=2)
arrows(v1[1]-s1,0.7,v1[1]+s1,0.7, angle=90, length=0.05, code=3, lw=2)

# 3b)
# Comment on your graphic.
# The standard errors seh1 and seh2 are large in relation to the distance.

# 3c)
# Test the null hypothesis on the 5% level with a two-sided test for the 
# comparison of two proportions.
prop.test(m, conf.level = 0.05)

# 3d)
# Interpret your result.
# Reject the hypothesis as the p-value is outside of the confidence interval