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

Aus VoWi
Zur Navigation springen Zur Suche springen

Coin throws[Bearbeiten | Quelltext bearbeiten]

An unfair coin is thrown 600 times. The probability of geting a tail in each throw is 14 .

  • (a)  Use a Binomial distribution to compute the probability that the number of heads obtained does not differ more than 10 from 420.
  • (b)  Use a Normal approximation without a continuity correction to calculate the probability in (a). How does the result change if the approximation is provided with a continuity correction?

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 16:59:50 CET

# Statistics and Probability HW #5
# Friday 
# Duedate: 09.11.2020

# Problem 2 - Coin throws
# An unfair coin is thrown 600 times. The probability of geting a tail in each 
# throw is 1/4
n <- 600
p <- 1/4

# Problem 2a)
# Use a Binomial distribution to compute the probability that the number of 
# heads obtained does not differ more than 10 from 420.
result_2a <- pbinom(420 + 10, n, 1-p) - pbinom(420 - 10, n, 1-p)
result_2a

# Problem 2b)
# Use a Normal approximation without a continuity correction to calculate the 
# probability in (a). How does the result change if the approximation is 
# provided with a continuity correction?

normal_approx <- function(a, b, n, p, correction=FALSE) {
  if (correction) {
    a <- a - 0.5
    b <- b + 0.5
  }
  pnorm((b-n*p)/sqrt(n*p*(1-p))) - pnorm((a-n*p)/sqrt(n*p*(1-p)))
}

a <- 420 - 10
b <- 420 + 10
result_2b <- c(normal_approx(a, b, n, 1-p, FALSE), normal_approx(a, b, n, 1-p, TRUE))
result_2b