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

Aus VoWi
Zur Navigation springen Zur Suche springen
t-test (with R)

Two programmers are developing a computer game in which a BMX rider has to pass a parcours. The goal is to cover as much distance as possible. They are interested in the mean distance covered by a layman, who plays the game for the first time. For that they let some trialists play the game and for each player note the distance covered. The distances (unit meter) are found in the file dist.Rdata.

Test the null hypothesis, that the mean distance covered by a layman is 550 meters using a two-sided one-sample t-test. Set the significance level to .

Proceed as follows (a)  Visualize the data in a histogram. Are the data approximately bell-shaped? Mark the null hypothesis, the mean and the standard error of the mean (i.e., mean standard error). Add labels and legends. (b)  Calculate the t-statistic (without using t.test()) (c)  Calculate the p-value (without t.test()). Do you reject the null hypothesis? (d)  Interpret your result.

(e)  Now perform the test using t.test() and compare your results.

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:23:34 CET

load("dist.Rdata")
m <- mean(distanz)
h0 <- 550
n <- length(distanz)
S <- sd(distanz)
Sem <- S / sqrt(n)
alpha <- 0.05

# 1b)
hist(distanz)
abline(v=h0, col='blue')
abline(v=m, col='green')
abline(v=m+Sem, col='red')
abline(v=m-Sem, col='red')
legend("topleft", 
       legend=c('error', 'mean', 'hypothesis'), 
       col=c('red', 'green', 'blue'), 
       cex=0.8, 
       lty=1)

# 2b)
t <- (m - h0)/(S / sqrt(n))
t

# 2c) 
p <- pt(-t, df=n - 1) * 2
p

# Do not reject the hypotheses because P > alpha

# 2e)
t.test(distanz, mu=h0)