pnorm(-1, mean = 0, sd = 1) + # считает, вероятность быть меньше -1
pnorm(1, mean = 0, sd = 1, lower.tail = FALSE) # вероятность быть больше 1[1] 0.3173105
3/9/23
\[ P(Z < -1\textrm{ ИЛИ } Z > 1) = P(Z < - 1) + P(Z > 1) = \\ F_Z(-1) + [1 - F_Z(1)] = \\ \int_{-\infty}^{-1}\frac{1}{\sqrt{2\pi}}e^{-z^2/2}dz + \int_{1}^{\infty}\frac{1}{\sqrt{2\pi}}e^{-z^2/2}dz = \\ \textrm{ pnorm(-1, mean = 0, sd = 1)} + \textrm{pnorm(1, mean = 0, sd = 1, lower.tail = FALSE)} \]
\[ P(-z < Z < z) = 95\% \\ 1 - P(Z > z \cup Z < -z ) = 95\% \\ 1 - P(Z > z) - P(Z < - z) = 95\% \\ 2*P(Z < - z) = 5\% \\ P(Z < - z) = 2.5\% \\ \]
Исследователь разослал 200 вымышленных резюме по объявлениям о приеме на работу.
Резюме абсолютно идентичны, за исключением того, что половина из них представляет якобы составлена мужчиной, а половина - женщиной
23 мужских резюме получили звонок от работодателя; женщинам звонили только в 8 случаев
Предположим, что разница двух выборочных пропорций нормально распределена со средним значением, равным истинной разнице между популяциями, и дисперсией, равной 3,5%
Мы знаем, что наша точечная оценка вряд ли попадет в реальную разницу между двумя популяциями. Но что если мы придумаем интервал, который будет содержать истинный параметр с некоторой желаемой вероятностью.
Доверительный интервал для популяционного среднего: выборочное средне плюс-минус погрешность \[CI_{\alpha}: \bar{x} \pm z^*\times SE = \bar{x} \pm z^{*}\times \frac{\sigma}{\sqrt{n}}\]
\(\bar{x}, \sigma, n\) считается на выборке
library(tidyverse)
# Берем 5000 наблюдений за Бернулиевой случайной переменной с вероятностью успеха 0.3. Это будет нашей популяции.
population <- rbinom(50000, size = 1, prob = 0.3)
true_p <-
population %>% mean()
z_score <- 1.96
# Берем 1000 выборок из популяции, каждая размером в 100 наблюдений
n <- 100
samples <-
lapply(1:1000,
function(x) sample(population, n, replace = TRUE))
# Считаем пропорции
sample_props <- sapply(samples, mean)
# Смотрим насколько далеко наши выборочные пропорции "уходили" от истинной пропорции
temp <- (sample_props - true_p) %>% abs()
ME <- z_score*sqrt(true_p*(1 - true_p)/n)
temp2 <- (temp < ME)
table(temp2) %>% prop.table()temp2
FALSE TRUE
0.046 0.954
\[ME = z* \frac{s}{\sqrt{n}} \rightarrow n = (\frac{z*s}{ME})^2\]
\[ \bar{x} \pm z^{*}_{95\%}\times\frac{\sigma}{\sqrt{n}} = 3.4 \pm 1.96\times\frac{0.3}{10} = \\ 3.4 \pm 1.96\times0.03 \approx (3.34, 3.45) \]
Окей, у нас есть интервал \((3.34, 3.45)\). Что он может нам сказать?
Подтверждают ли наши данные гипотезу о том, что студенты-спортсмены учатся лучше чем студенты в целом?
\(H_{0}: \mu = 3.3\); \(H_{A}: \mu > 3.3\)
\(\mu = 3.3 \notin (3.34, 3.45) \implies H_{0} \textrm{ отвергнута }\)
Наш доверительный интервал содержит истинное среднее с вероятностью \(95\%\), то есть параметр, который мы оцениваем, оказывается за пределами интервала только в \(5\%\) случаев
P-значение это вероятность наблюдать данные как наши, при условии, что нулевая гипотезы верна
\[ P(\bar{X} > 3.4|H_{0} \textrm{ is TRUE}) \\ P(\bar{X} > 3.4)| H_{0}:\mu = 3.3) \\ \bar{X} \sim N(\mu = 3.3, SE = 0.03) \\ z = \frac{\bar{x} - \mu}{SE} = \frac{3.4 - 3.3}{0.03} \approx 3.33 \\ P(Z > 3.33) \approx 0.0004\% \]
\[p\_value = P(\overline{X} < 6.9 \textrm{ OR }\overline{X} > 7.1|H_{0}\textrm{ is TRUE}) = \\ P(X < 6.9) + P(X > 7.1) = 2 \times 0.25 = 0.5\]
\[ H_{0}: \mu_{NU} = 9.8 = \mu_{KZ}\\ H_{A}: \mu_{NU} > 9.8 = \mu_{KZ} \]
https://homepage.divms.uiowa.edu/~mbognar/applets/normal.html
\(z = \frac{10.3 - 9.8}{0.2} = 2.5\)
\(P(\overline{X} > 10.3|H_{0}: \overline{X} \sim N(\mu = 9.8, SE = 0.2)) = P(Z > 2.5|H_{0}) \approx 0.006 < \alpha = 0.01\)
\(p\_value < \alpha\) hence reject the \(H_{0}\) and accept \(H_{A}\)
\[ P(Z < -2.5 \textrm{ OR } Z > 2.5| H_{0} \textrm{ is true}) = \\ P(\overline{X} < 9.3 \textrm{ OR } \overline{X} > 10.3| H_{0} \textrm{ is true}) \\ \approx 2 \times 0.006 = 0.012 > 0.01 = \alpha \]
An unbiased estimator is an estimator which distribution has the same center as the true population distribution
Confidence intervals for nearly normal estimators \[\textrm{point estimate} \pm z^{*} \times SE\]
Hypothesis testing for nearly normal estimators \[z = \frac{\textrm{point estimate - null value}}{SE}\]
Consider the following question: How many immigrants lived in Germany in 2017
Write down your answer and tell me
The correct answer is
Now suppose I have made a poll asking this question among 400 randomly selected NU students and figured that 150 or \(37.5\%\) of them gave the right answer. The standard error of the estimate is \(2\%\). Does these data provide convincing evidence that the average NU student does better than a random choice at at a significance level of \(\alpha = 0.01\)
\(\hat{P}_n = \frac{Y}{n}\) - random variable proportion of “successes” in n trials
When we do hypothesis testing we assume that the true population proportion is equal to some hypothecial value \(p_{true} = p_{0}\), and we want to test how likely it is
but \(Y \sim Bi(p_0, n)\) which means \(E[Y] = p_{0}n\) and \(var(Y) = p_{0}(1-p_{0})n\)
Now suppose I have made a poll asking this question among 400 randomly selected NU students and figured that 150 or \(37.5\%\) of them gave the right answer. The standard error of my estimate is about \(2.4\%\). Does these data provide convincing evidence that the average NU student does better than a random choice at a significance level of \(\alpha = 0.01\)
\[ H_{0}: p_{NU} = 0.33 = p_{0} \\ H_{A}: p_{NU} > 0.33 = p_{0} \]
Calculate the point estimate: \(\hat{p} = 0.375\)
Calculate the z-score and p-value
\[ z = \frac{\hat{p} - p_0}{SE} = \frac{0.375 - 0.333}{0.024} = \frac{0.042}{0.024} = 1.75 \\ p\_value = P(Z > 1.75|H_0) \approx 0.04\% > 0.01 = \alpha \implies \textrm{fail to reject } H_0 \]
prop.test(). prop.test() tests the null hypotheses that the proportions are the same or that they equal to certain given values
1-sample proportions test with continuity correction
data: 150 out of 400, null probability 0.33
X-squared = 3.4628, df = 1, p-value = 0.03138
alternative hypothesis: true p is greater than 0.33
99 percent confidence interval:
0.3195126 1.0000000
sample estimates:
p
0.375
another_test <- prop.test(150, n = 400, p = 0.33,
alternative = "two.sided",
conf.level = 0.95)
another_test
1-sample proportions test with continuity correction
data: 150 out of 400, null probability 0.33
X-squared = 3.4628, df = 1, p-value = 0.06276
alternative hypothesis: true p is not equal to 0.33
95 percent confidence interval:
0.3277503 0.4246901
sample estimates:
p
0.375
This also means that \(p_1 = p_2\), let’s denote them as \(p_0\), which implies that the variance and sd of \(\Delta \hat{P}\) are \[ var(\Delta \hat{P}) = \frac{p_0(1-p_0)}{n1} + \frac{p_0(1-p_0)}{n2}\\ sd(\Delta \hat{P}) = SE = \sqrt{\frac{p_0(1-p_0)}{n1} + \frac{p_0(1-p_0)}{n2}} \\ \textrm{where } p_0 = \frac{n_1p_1 + n_2p_2}{n1 + n2} \]
2-sample test for equality of proportions with continuity correction
data: c(23, 8) out of c(100, 100)
X-squared = 7.4823, df = 1, p-value = 0.006231
alternative hypothesis: two.sided
95 percent confidence interval:
0.0418647 0.2581353
sample estimates:
prop 1 prop 2
0.23 0.08
A student collected ENT and gender data from 5000 randomly selected high-school students in Kazakhstan. The average UNT score for the 2465 boys in the sample was \(70.5\%\) and the average score for girls was \(72.3\%\). The standard error for the difference between the average boy and girl scores is \(0.9\). Do these data provide convincing evidence that girls do better on UNT than boys at a \(\alpha = 0.05\) significance level. Assume that the distribution of the point estimate is nearly normal
A student collected ENT and gender data from 5000 randomly selected high-school students in Kazakhstan. The average UNT score for the 2465 boys in the sample was \(70.5\%\) and this value was \(72.3\%\) for the 2535 girls. The standard error for the difference between the average boy and girl scores was \(0.9\). Do these data proivde convincing evidence that girls do better on UNT than boys at a \(\alpha = 0.05\) significance level. Assume that the distribution of the point estimate is nearly normal
\[ H_{0}: \mu_{girls} = \mu_{boys} \\ H_{A}: \mu_{girls} > \mu_{boys} \\ \textrm{null value} = \mu_{girls} - \mu_{boys} = 0 \]
Calculate the point estimate \[ \overline{x}_{girls} - \overline{x}_{boys} = 72.3 - 70.5 = 1.8 \]
Calculate z-score and p-value \[ z = \frac{1.8}{0.9} = 2 \\ p\_value = P(Z > 2|H_0) \approx 0.02 < \alpha = 0.05 \implies \textrm{reject } H_0 \]
These data provide convicing evidence that the average ENT score of girls is higher than that of boys
| TRUTH\Decision | not reject \(H_{0}\) | reject \(H_{0}\) |
|---|---|---|
| \(H_{0}\) is true | OK | Type 1 Error |
| \(H_{A}\) is true | Type 2 Error | OK |
| TRUTH\Decision | not reject \(H_{0}\) | reject \(H_{0}\) |
|---|---|---|
| \(H_{0}\) is true | \(1 - \alpha\) | \(\alpha\) |
| \(H_{A}\) is true | Type 2 Error, \(\beta\) | \(1 - \beta\) |