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!
Lecturer: Emi Tanaka
ETC5521.Clayton-x@monash.edu
Week 11 - Session 2
nullabor
+ ggplot2
nullabor
+ ggplot2
nullabor
+ ggplot2
nullabor
+ ggplot2
nullabor
package makes it easy to create the data for the lineup and you can use ggplot2
to construct the lineup.library(nullabor)library(tidyverse) # which includes ggplot2
data(cochran.crd, package = "agridat")skimr::skim(cochran.crd)
## ── Data Summary ────────────────────────## Values ## Name cochran.crd## Number of rows 32 ## Number of columns 4 ## _______________________ ## Column type frequency: ## factor 1 ## numeric 3 ## ________________________ ## Group variables None ## ## ── Variable type: factor ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────## skim_variable n_missing complete_rate ordered n_unique top_counts ## 1 trt 0 1 FALSE 7 O: 8, F12: 4, F3: 4, F6: 4## ## ── Variable type: numeric ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist ## 1 inf 0 1 15.7 8.22 4 9 16 19.5 32 ▇▃▇▃▃## 2 row 0 1 2.5 1.14 1 1.75 2.5 3.25 4 ▇▇▁▇▇## 3 col 0 1 4.5 2.33 1 2.75 4.5 6.25 8 ▇▃▇▃▇
cochran.crd %>% ggplot(aes(factor(col), factor(row), fill = inf)) + geom_tile(color = "black", size = 2) + geom_text(aes(label = trt)) + labs(x = "Column", y = "Row", fill = "Infection\npercent") + scale_fill_continuous_sequential(palette = "Reds 3")
W.G. Cochran and G. Cox, 1957. Experimental Designs, 2nd ed. John Wiley, New York.
method <- null_permute("trt")
method <- null_permute("trt")
set.seed
to get the same random instance.set.seed(1)line_df <- lineup(method, true = cochran.crd, n = 10)
## decrypt("bhMq KJPJ 62 sSQ6P6S2 ua")
glimpse(line_df)
## Rows: 320## Columns: 5## $ inf <int> 9, 12, 18, 10, 24, 17, 30, 16, 10, 7, 4, 10, 21, 24, 29, 12, 9, 7, 18, 30, 18, 16, 16, 4, 9, 18, 17, 19, 32, 5, 26, 4, 9, 12, 18, 10, 24, 17, 30, 16, 10, 7, 4, 10, 21, 24, 29, 12, 9,…## $ trt <fct> S3, F12, S3, F3, O, F3, F12, O, S12, F6, O, F6, S3, F3, O, F12, O, O, S6, S12, S6, F6, S3, F12, S6, F6, S12, S12, O, S6, O, F3, S6, S12, S3, F12, O, O, O, O, F6, F3, S6, F6, F12, S12…## $ row <int> 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1,…## $ col <int> 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5,…## $ .sample <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,…
.sample
variable has information of which sample it is. .sample
number belongs to the real data. line_df %>% ggplot(aes(trt, inf)) + geom_point(size = 3, alpha = 1/2) + facet_wrap(~.sample, nrow = 2) + theme(axis.text = element_blank(), # remove data context axis.title = element_blank())
decrypt("bhMq KJPJ 62 sSQ6P6S2 ua")
## [1] "True data in position 5"
skimr::skim(trees)
## ── Data Summary ────────────────────────## Values## Name trees ## Number of rows 31 ## Number of columns 3 ## _______________________ ## Column type frequency: ## numeric 3 ## ________________________ ## Group variables None ## ## ── Variable type: numeric ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist ## 1 Girth 0 1 13.2 3.14 8.3 11.0 12.9 15.2 20.6 ▃▇▃▅▁## 2 Height 0 1 76 6.37 63 72 76 80 87 ▃▃▆▇▃## 3 Volume 0 1 30.2 16.4 10.2 19.4 24.2 37.3 77 ▇▅▁▂▁
g1 <- trees %>% ggplot(aes(Girth, Volume)) + geom_point() + scale_x_log10() + scale_y_log10()g2 <- trees %>% ggplot(aes(Height, Volume)) + geom_point() + scale_x_log10() + scale_y_log10()g1 + g2
fit <- lm(log(Volume) ~ log(Girth) + log(Height), data = trees)fit_df <- trees %>% # below are needed for lineup mutate(.resid = residuals(fit), .fitted = fitted(fit))
Atkinson, A. C. (1985) Plots, Transformations and Regression. Oxford University Press.
method <- null_lm(log(Volume) ~ log(Girth) + log(Height), method = "pboot")
method <- null_lm(log(Volume) ~ log(Girth) + log(Height), method = "pboot")
set.seed(2020)line_df <- lineup(method, true = fit_df, n = 10)
## decrypt("bhMq KJPJ 62 sSQ6P6S2 uT")
method = "pboot"
,method = "boot"
or method = "rotate"
method <- null_lm(log(Volume) ~ log(Girth) + log(Height), method = "boot")
method = "pboot"
,method = "boot"
or method = "rotate"
method <- null_lm(log(Volume) ~ log(Girth) + log(Height), method = "boot")
line_df <- lineup(null_dist("temp", "exp", list(rate = 1/mean(dslabs::stars$temp))), true = dslabs::stars, n = 10)
## decrypt("bhMq KJPJ 62 sSQ6P6S2 ug")
data(aud, package = "nullabor")line_df <- lineup(null_ts("rate", forecast::auto.arima), true = aud, n = 10)
## Registered S3 method overwritten by 'quantmod':## method from## as.zoo.data.frame zoo
## decrypt("bhMq KJPJ 62 sSQ6P6S2 um")
ggplot(line_df, aes(date, rate)) + geom_line() + facet_wrap(~ .sample, scales = "free_y", nrow = 2) + theme(axis.title = element_blank(), axis.text = element_blank())
tidyverse
suite of R packages xaringan
, remark.js, knitr
, and R Markdown.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Lecturer: Emi Tanaka
ETC5521.Clayton-x@monash.edu
Week 11 - Session 2
Lecturer: Emi Tanaka
ETC5521.Clayton-x@monash.edu
Week 11 - Session 2
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 |