TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Levajkovic)/Übungen 2023W/HW11.3
Zur Navigation springen
Zur Suche springen
- An experiment producing numerical data
Suppose we have an experiment that produces numerical data with the possible outcomes −2, −1, 0, 1, 2, 3 or more. We run 55 trials and count the frequency of each outcome, getting the following data: See Table 1.
Use the -test for goodness of fit to test the null hypothesis that the data is drawn from 55 trials of a binomial distribution against the alternative hypothesis that the data is drawn from some other distribution with the level of significance . Compute the p-value
and give your decision on the test.
Dieses Beispiel ist als solved markiert. Ist dies falsch oder ungenau? Aktualisiere den Lösungsstatus (Details: Vorlage:Beispiel)
Outcomes | -2 | -1 | 0 | 1 | 2 | 3 or more |
Observed Frequencies | 3 | 11 | 16 | 14 | 8 | 3 |
Lösungsvorschlag von Lessi[Bearbeiten | Quelltext bearbeiten]
--Lessi 2024-02-07T13:04:11Z
# Suppose we have an experiment that produces numerical data with the possible outcomes −2,
# −1, 0, 1, 2, 3 or more. We run 55 trials and count the frequency of each outcome, getting the
# following data:
data <- c("-2"=3, "-1"=11, "0"=16, "1"=14, "2"=8, "3+"=3)
n <- 55
d <- 6
barplot(data / n, col = rainbow(d))
# Use the χ^2-test for goodness of fit to test the null hypothesis H0 that the data is drawn from 55
# trials of a binomial distribution B(8, 0.5) against the alternative hypothesis HA that the data is
# drawn from some other distribution with the level of significance α = 1%. Compute the p-value
# and give your decision on the test.
alpha <- 0.01
#p_0 <- c(dbinom(2:6, 8, 0.5), pbinom(7, 8, 0.5, lower.tail = FALSE))
# p_0 <- c(dbinom(2:6, 8, 0.5), 1 - sum(dbinom(2:6, 8, 0.5)))
# == correction by tutor ==
p_0 <- c(dbinom(-2:2, 8, 0.5), pbinom(3, 8, 0.5, lower.tail = FALSE))
p_0
e <- p_0 * n
e
# here we get expected frequencies of zero because binom only works for > 0
# the hypothesised distribution cannot fit the data and we reject
# == end correction by tutor ==
x2 <- sum((data - e)^2 / e)
x2
p <- pchisq(x2, d - 1, lower.tail = FALSE)
p
R <- c(qchisq(1 - alpha, d - 1), Inf)
p > alpha
# p > alpha therefore we don't reject the null hypothesis
?chisq.test
chisq.test(data, p=p_0)
plot(-4:4, dbinom(0:8, size=8, prob=0.5),type='h')