Skip to content
Snippets Groups Projects
Commit 4b7257a6 authored by Ben Anderson's avatar Ben Anderson
Browse files

removed stuff, fixed t test model outputs using broom to tidy

parent 40cd1e7b
No related branches found
No related tags found
No related merge requests found
placeholder.jpg

19.8 KiB

......@@ -9,10 +9,6 @@ author: '`r paste0(params$author)` (Contact: b.anderson@soton.ac.uk, `@dataknut`
date: 'Last run at: `r Sys.time()`'
always_allow_html: yes
output:
bookdown::word_document2:
fig_caption: yes
toc: yes
toc_depth: 2
bookdown::html_document2:
code_folding: hide
fig_caption: yes
......@@ -22,6 +18,10 @@ output:
toc: yes
toc_depth: 2
toc_float: yes
bookdown::word_document2:
fig_caption: yes
toc: yes
toc_depth: 2
bookdown::pdf_document2:
fig_caption: yes
keep_tex: yes
......@@ -50,6 +50,7 @@ rmdLibs <- c("data.table", # data munching
"lubridate", # for today
"SAVEr", # power stats functions
"GREENGridData",
"broom", # tidy test results
"knitr" # for kable
)
# load them
......@@ -212,7 +213,7 @@ p <- p +
p
ggplot2::ggsave("figs/fig1_statPowerEsts80.png", p)
ggplot2::ggsave("figs/fig1_statPowerEsts80p0.05.png", p)
```
......@@ -247,9 +248,6 @@ p <- p +
label = paste0("Effect size = ", round(y005, 2) ,"% with \n p = 0.05, power = 0.8 and n = 1000"),
hjust = 0) # https://stackoverflow.com/questions/26684023/how-to-left-align-text-in-annotate-from-ggplot2
p
ggplot2::ggsave("figs/fig1_statPowerEsts80.png", p)
# add vline at 0.01 effect size for p = 0.05, n = 1000
p001Ref <- powerRes80DT[pValue == "p = 0.01" &
effectSize < ceiling(p005Ref$effectSize) &
......@@ -274,6 +272,8 @@ x02 <- mean(p02Ref$sampleN)
p <- p + geom_segment(x = x02, y = y005, xend = x02, yend = 0, alpha = vLineAlpha,
colour = cbPalette[4])
p
ggplot2::ggsave("figs/fig2_statPowerEsts80All.png", p)
```
Full table of results:
......@@ -343,7 +343,14 @@ T test group 1
# we are going to compare winter with summer to get a large effect. This is not what we would really do as it is a repeat measures dataset but this is irrelevant for our current purposes.
tTest <- t.test(testDT[group == "Intervention 1"]$meanW, testDT[group == "Control"]$meanW)
tTest
tTestTidy <- broom::tidy(tTest)
tTestTidy$`Control mean` <- tTestTidy$estimate2
tTestTidy$`Group 1 mean` <- tTestTidy$estimate1
tTestTidy$`Mean difference` <- tTestTidy$estimate
knitr::kable(tTestTidy[c("Control mean", "Group 1 mean", "Mean difference",
"statistic", "p.value", "conf.low", "conf.high")], caption = "T test results (Group 1 vs Control)")
controlW <- tTest$estimate[[2]]
intW <- tTest$estimate[[1]]
......@@ -365,7 +372,15 @@ T test Group 2
# now compare winter & spring for a smaller effect
tTest <- t.test(testDT[group == "Intervention 2"]$meanW, testDT[group == "Control"]$meanW)
tTest
tTestTidy <- broom::tidy(tTest)
tTestTidy$`Control mean` <- tTestTidy$estimate2
tTestTidy$`Group 2 mean` <- tTestTidy$estimate1
tTestTidy$`Mean difference` <- tTestTidy$estimate
knitr::kable(tTestTidy[c("Control mean", "Group 2 mean", "Mean difference",
"statistic", "p.value", "conf.low", "conf.high")], caption = "T test results (Group 2 vs Control)")
controlW <- tTest$estimate[[2]]
intW <- tTest$estimate[[1]]
cil <- tTest$conf.int[[1]]
......@@ -429,7 +444,15 @@ re-run T tests Group 1
# now compare winter & spring for a smaller effect
tTest <- t.test(largeTestDT[group == "Intervention 2"]$meanW, largeTestDT[group == "Control"]$meanW)
tTest
tTestTidy <- broom::tidy(tTest)
tTestTidy$`Control mean` <- tTestTidy$estimate2
tTestTidy$`Group 1 mean` <- tTestTidy$estimate1
tTestTidy$`Mean difference` <- tTestTidy$estimate
knitr::kable(tTestTidy[c("Control mean", "Group 1 mean", "Mean difference",
"statistic", "p.value", "conf.low", "conf.high")], caption = "T test results (Group 1 vs Control)")
controlW <- tTest$estimate[[2]]
intW <- tTest$estimate[[1]]
cil <- tTest$conf.int[[1]]
......
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment