These slides are viewed best by Chrome or Firefox and occasionally need to be refreshed if elements did not load properly. See here for the PDF .
Press the right arrow to progress to the next slide!
Presenter: Emi Tanaka
Department of Econometrics and Business Statistics,
Monash University, Melbourne, Australia
emi.tanaka@monash.edu
27 Mar 2021 @ Fukuoka R
…の前に、
…の前に、
コインを10回フリップします。
結果:
7回は表、3回は裏でした。
コインは表に偏ってますか?
コインを100回フリップします。
結果:
70回は表、30回は裏でした。また7割は表でした。
コインは表に偏ってますか?
Hypotheses | H0:p=0.5 vs. H1:p>0.5 |
Assumptions | Each toss is independent with equal chance of getting a head. |
Test statistic | X∼B(n,p) under H0. |
P-value (or critical value or confidence interval) |
P(X≥x) where x is the observed test statistic. |
Conclusion | Reject null hypothesis when the p-value is less than some significance level α. Usually α=0.05. |
Hypotheses | H0:p=0.5 vs. H1:p>0.5 |
Assumptions | Each toss is independent with equal chance of getting a head. |
Test statistic | X∼B(n,p) under H0. |
P-value (or critical value or confidence interval) |
P(X≥x) where x is the observed test statistic. |
Conclusion | Reject null hypothesis when the p-value is less than some significance level α. Usually α=0.05. |
library(ggplot2)ggplot(trees, aes(log(Girth), log(Volume))) + geom_point() + geom_smooth(method = "lm", se = FALSE)
Consider the model:
log(Volumei)=β0+β1log(Girthi)+ei where ei∼NID(0,σ2).
Note: NID means normal, independent and identically distributed.
library(magrittr) # for `%>%`library(broom) # for `augment`fit <- lm(log(Volume) ~ log(Girth), data = trees)res <- augment(fit)tidy(fit)
## # A tibble: 2 x 5## term estimate std.error statistic p.value## <chr> <dbl> <dbl> <dbl> <dbl>## 1 (Intercept) -2.35 0.231 -10.2 4.18e-11## 2 log(Girth) 2.20 0.0898 24.5 6.36e-21
res
## # A tibble: 31 x 7## `log(Volume)` `log(Girth)` .fitted .std.resid .hat .sigma .cooksd## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 2.33 2.12 2.30 0.281 0.151 0.117 0.00703 ## 2 2.33 2.15 2.38 -0.452 0.133 0.117 0.0156 ## 3 2.32 2.17 2.43 -1.01 0.122 0.115 0.0705 ## 4 2.80 2.35 2.82 -0.200 0.0582 0.117 0.00124 ## 5 2.93 2.37 2.86 0.650 0.0536 0.116 0.0120 ## 6 2.98 2.38 2.88 0.884 0.0516 0.115 0.0213 ## 7 2.75 2.40 2.92 -1.56 0.0478 0.112 0.0609 ## 8 2.90 2.40 2.92 -0.183 0.0478 0.117 0.000842## 9 3.12 2.41 2.94 1.57 0.0461 0.112 0.0594 ## 10 2.99 2.42 2.96 0.259 0.0445 0.117 0.00156 ## # … with 21 more rows
ei∼NID(0,σ2) no pattern in residual plot & straight line for QQ-plot (theoretically)
ggplot(res, aes(`log(Girth)`, .std.resid)) + geom_point() + geom_hline(yintercept = 0) + ggtitle("Residual plot")
ggplot(res, aes(sample = .std.resid)) + geom_qq() + geom_qq_line() + ggtitle("QQ plot")
So is there any pattern in this residual plot?
And is this line straight in the QQ-plot?
意外に統計学者でもプロットを評価する時はちょいと適当
じゃあ、どうやって評価する?
Hypotheses | H0:p=0.5 vs. H1:p>0.5 |
Assumptions | Each toss is independent with equal chance of getting a head. |
Test statistic | X∼B(n,p) under H0. |
P-value (or critical value or confidence interval) |
P(X≥x) where x is the observed test statistic. |
Conclusion | Reject null hypothesis when the p-value is less than some significance level α. Usually α=0.05. |
Hypotheses | H0:ei∼NID(0,σ2) vs. H1: not H0 |
Assumptions | Assume method of moments estimate for σ2 is good enough. |
Test statistic | Residual and QQ-plot But what is its distribution?? |
P-value | ??? |
Conclusion | ??? |
Under H0, we have ei∼NID(0,σ2).
The estimate of σ, denoted ˆσ is given below:
sigma_hat <- glance(fit)$sigmasigma_hat
## [1] 0.1149578
Under H0, we have ei∼NID(0,σ2).
The estimate of σ, denoted ˆσ is given below:
sigma_hat <- glance(fit)$sigmasigma_hat
## [1] 0.1149578
null_generator <- function() { rnorm(n = nrow(trees), mean = 0, sd = sigma_hat) }
sigma_hat <- glance(fit)$sigmasigma_hat
## [1] 0.1149578
null_generator <- function() { rnorm(n = nrow(trees), mean = 0, sd = sigma_hat) }
set.seed(2021) # for reproducibilitysample1 <- null_generator()sample1
## [1] -0.014077733 0.063509210 0.040079987 0.041342539 0.103238294 -0.221014401 0.030089561 0.105251514 0.001583192## [10] 0.198872794 -0.124407911 -0.031363388 0.020921794 0.173418675 0.184446385 -0.211692022 0.186612202 0.015104195## [19] 0.170266610 0.173967771 -0.108341224 -0.021345944 -0.126582888 0.138882296 -0.186799392 0.012114064 -0.167314594## [28] -0.040696923 -0.010771552 0.126530466 -0.225757053
sigma_hat <- glance(fit)$sigmasigma_hat
## [1] 0.1149578
null_generator <- function() { rnorm(n = nrow(trees), mean = 0, sd = sigma_hat) }
set.seed(2021) # for reproducibilitysample1 <- null_generator()sample1
## [1] -0.014077733 0.063509210 0.040079987 0.041342539 0.103238294 -0.221014401 0.030089561 0.105251514 0.001583192## [10] 0.198872794 -0.124407911 -0.031363388 0.020921794 0.173418675 0.184446385 -0.211692022 0.186612202 0.015104195## [19] 0.170266610 0.173967771 -0.108341224 -0.021345944 -0.126582888 0.138882296 -0.186799392 0.012114064 -0.167314594## [28] -0.040696923 -0.010771552 0.126530466 -0.225757053
sample2 <- null_generator()sample2
## [1] -0.166452530 0.117192993 -0.163403008 -0.069495694 -0.182032707 -0.147827979 -0.167227403 -0.010009506 0.058023401## [10] 0.013379792 0.202350333 -0.039673836 0.243710596 -0.003951961 -0.091064303 0.169622012 -0.083408475 0.035910414## [19] 0.079546685 -0.057512339 -0.259329822 0.005028408 -0.042398523 -0.110385074 0.011928749 0.049120227 -0.019598186## [28] -0.178085791 -0.173080487 0.001844330 -0.021309077
gres <- ggplot(res, aes(`log(Girth)`, .std.resid)) + geom_point() + geom_hline(yintercept = 0) + theme_void()gres
Null plot と違いありますか?
gres %+% mutate(res, .std.resid = sample1)
gres %+% mutate(res, .std.resid = sample2)
gres <- ggplot(res, aes(sample = .std.resid)) + geom_qq() + geom_qq_line() + coord_equal() + theme_void()gres
Null plot と違いありますか?
gres %+% mutate(res, .std.resid = sample1)
gres %+% mutate(res, .std.resid = sample2)
Visual Inference
Data plots tend to be over-interpreted
Reading data plots requires calibration
その為に null plots が必要
Buja et al. (2008) “Statistical Inference for Exploratory Data Analysis and Model Diagnostics.” Philosophical Transactions. Series A, Mathematical, Physical, and Engineering Sciences 367 (1906): 4361–83.
ggplot(Orange) + aes(age, circumference, color = Tree) + geom_point(size = 3) + geom_smooth(method = "lm")
The fitted model:
fit <- lm(circumference ~ Tree + age:Tree, data = Orange)
nullabor
library(nullabor)method <- null_lm(circumference ~ Tree + age:Tree, method = "pboot")fit <- lm(circumference ~ Tree + age:Tree, data = Orange)fit_df <- Orange %>% mutate(.resid = residuals(fit))set.seed(2021)line_df <- lineup(method, true = fit_df)
## decrypt("bhMq KJPJ 62 sSQ6P6S2 uD")
ggplot(line_df, aes(age, .resid)) + geom_point() + geom_hline(yintercept = 0) + facet_wrap(~.sample) + labs(x = "", y = "") + theme(axis.text = element_blank(), panel.border = element_rect(fill = "transparent"), axis.line = element_blank(), axis.ticks.length = unit(0, "mm"), strip.background = element_rect(fill = "red"), strip.text = element_text(color = "white", face = "bold", size = 18))
🧑🏻⚖️🧑🏼⚖️🧑🏽⚖️🧑🏾⚖️🧑🏿⚖️👨🏻⚖️👨🏼⚖️👨🏽⚖️👨🏾⚖️👨🏿⚖️
多数人の評価をまとめる
Let X be the number of observers out of K independent observers picking the data plot from the lineup.
Assume that X∼B(K,1/m) under H0.
The p-value of a lineup of size m evaluated by K observers is given as P(X≥x).
Unlike conventional hypothesis testing, visual inference p-value depends on
Majumder, M., Heiki Hofmann, and Dianne Cook. 2013. “Validation of Visual Statistical Inference, Applied to Linear Models.” Journal of the American Statistical Association 108 (503): 942–56.
This slide is made using the xaringan
R-package and found at
Emi Tanaka
Department of Econometrics and Business Statistics,
Monash University, Melbourne, Australia
emi.tanaka@monash.edu
This slide is made using the xaringan
R-package and found at
Emi Tanaka
Department of Econometrics and Business Statistics,
Monash University, Melbourne, Australia
emi.tanaka@monash.edu
Presenter: Emi Tanaka
Department of Econometrics and Business Statistics,
Monash University, Melbourne, Australia
emi.tanaka@monash.edu
27 Mar 2021 @ Fukuoka R
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |