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

Aus VoWi
Zur Navigation springen Zur Suche springen

Absurdity of hypothesis testing[Bearbeiten | Quelltext bearbeiten]

Consider the situation of the previous exercise ”t-test (with R)”, while additionally trice as much laymen played the game. The collection of all data is stored in the file dist_more.Rdata.

  • (a) Perform a t-test. How do you decide now?
    • (b)  Represent the data from dist.Rdata as well as dist_more.Rdata each in a histogram, arranged below each other (par(mfrow=c(2,1))). Mark the mean, the standard error of the mean, as well as the value 550 meters.
    • (c)  Discuss your graphic regarding the outcomes of the tests.

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 17:27:24 CET

load('dist_more.Rdata')
distance_more <- data.frame(distanz)
load('dist.Rdata')
distance <- data.frame(distanz)
h0 <- 550

# 3a)
t.test(distance_more, mu=h0, alternative = 'two.sided', var.equal = F, paired = F, conf.level = 0.95)

# Reject the hypothesis, because P < alpha

# 3b)
plot_distance <- function(data, mu) {
  m <- mean(data)
  h0 <- 550
  n <- length(data)
  S <- sd(data)
  Sem <- S / sqrt(n)
  alpha <- 0.05
  
  hist(data, main=sprintf("Distance %d",n), breaks = 20, xlab="distance (m)", ylab="frequency")
  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)
}

(par(mfrow=c(2,1)))
plot_distance(distance_more$distanz, h0)
plot_distance(distance$distanz, h0)

# 3c)