TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Levajkovic)/Übungen 2023W/HW09.2

Aus VoWi
Zur Navigation springen Zur Suche springen
Two-sample t-test using normal approximation

Messages are frequently sent from a sender to either receiver 1 or receiver 2. For both receivers, several times for the transfer were measured (in seconds) and stored in the file waitingtimes2.Rdata.

  • (a)  Plot both data sets. Is their distribution approximately bell-shaped?
  • (b)  Test the null-hypothesis of equal mean transfer times for both receivers on the 1%-level with a two sample t-test (using the normal approximation).
  • (c)  Compare your result to the output of t.test()
Dieses Beispiel ist als solved markiert. Ist dies falsch oder ungenau? Aktualisiere den Lösungsstatus (Details: Vorlage:Beispiel)


Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 17:35:53 CET

# Statistics and Probability: HW #9
# Friday 
# Duedate: 07.12.2020

# Problem 2 - Two-sample t-test using normal approximation
# Messages are frequently sent from a sender to either receiver 1 or receiver 2.
# For both re- ceivers, several times for the transfer were measured 
# (in seconds) and stored in the file waitingtimes2.Rdata.

load("waitingtimes2.Rdata")
d1 <- wt[[1]]
d2 <- wt[[2]]
n1 <- length(d1)
n2 <- length(d2)

# Problem 2a)
# Plot both data sets. Is their distribution approximately bell-shaped?
plot_wait <- function(data, text) {
  hist(data, main=text, xlab="time (sec)", ylab="frequency")
}

(par(mfrow=c(2,1)))
plot_wait(d1, "Data set 1")
plot_wait(d2, "Data set 2")
# The data is not bell-shaped

# Problem 2b)
# Test the null-hypothesis of equal mean transfer times for both receivers on 
# the 1%-level with a two sample t-test (using the normal approximation).
sem1 <- sd(d1)^2/n1
sem2 <- sd(d2)^2/n2
m1 <- mean(d1)
m2 <- mean(d2)
t <- (m1 - m2)/sqrt(sem1+sem2)
pnorm(t)*2

# Problem 2c)
# Compare your result to the output of t.test()
t.test(d1,d2)

#