Skip to content

Instantly share code, notes, and snippets.

View benwhalley's full-sized avatar

Ben Whalley benwhalley

  • Plymouth University
View GitHub Profile
@benwhalley
benwhalley / Ben.plist
Last active September 19, 2018 07:54
Mailmate key bindings
{
// Mailmate keybindings
"\U007F" = "archive:"; // ⌫
"@\U007F" = "deleteMessage:"; // ⌘+⌫
" " = "scrollPageDownOrNextUnreadMessage:";
"@S" = "saveAttachments:";
// Based on: https://mail.google.com/support/bin/answer.py?answer=6594
@benwhalley
benwhalley / a
Created September 4, 2018 08:43
c
month temperature day.of.week icecreams.sold
5 18.46 Su 60
6 20.42 Th 102
1 13.02 Sa 62
3 17.98 We 46
6 14.31 Su 110
4 16.87 Th 24
8 23.77 Th 52
2 11.02 Tu 26
12 14.36 We 46
@benwhalley
benwhalley / kidiq.csv
Last active September 4, 2018 09:11
Kids IQ data from the Gelman and Hill ARM book
kid_score mom_hs mom_iq mom_work mom_age
65 Completed 121.118 4 27
98 Completed 89.362 4 25
85 Completed 115.443 4 27
83 Completed 99.45 3 25
115 Completed 92.746 4 27
98 Did not complete 107.902 1 18
69 Completed 138.893 4 20
106 Completed 125.145 3 23
102 Completed 81.62 1 24
@benwhalley
benwhalley / slugify.R
Created June 13, 2018 08:49
Make strings url and filename friendly (akin to Django's eponymous function)
slugify <- function(text){
text %>%
tolower() %>%
str_trim() %>%
str_replace_all('[\\s-]+', "-") %>%
str_remove_all('[^\\w-]+')
}
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 3.
Package,LibPath,Version,Priority,Depends,Imports,LinkingTo,Suggests,Enhances,License,License_is_FOSS,License_restricts_use,OS_type,MD5sum,NeedsCompilation,Built
afex,/usr/local/lib/R/3.5/site-library,0.20-2,NA,"R (>= 3.1.0), lme4 (>= 1.1-8), emmeans","stringr, coin, pbkrtest (>= 0.4-1), lmerTest, car, reshape2,
stats, methods",NA,"xtable, parallel, plyr, optimx, nloptr, knitr, rmarkdown,
R.rsp, lattice, latticeExtra, multcomp, testthat, mlmRev,
dplyr, tidyr, dfoptim, Matrix, psych, ggplot2, MEMSS, effects,
carData",NA,GPL (>= 2),NA,NA,NA,NA,no,3.5.0
broom,/usr/local/lib/R/3.5/site-library,0.4.4,NA,NA,"plyr, dplyr, tidyr, psych, stringr, reshape2, nlme, methods",NA,"knitr, boot, survival, gam, glmnet, lfe, Lahman, MASS, rgeos,
sp, maps, maptools, multcomp, testthat, lme4, zoo, lmtest, plm,
biglm, ggplot2, nnet, geepack, AUC, ergm, network,
statnet.common, xergm, btergm, binGroup, Hmisc, bbmle, gamlss,
m <- "drink.to.cope ~ work.distress + work.pressure + lack.job.control
alcohol.consumption ~ work.distress + work.pressure + lack.job.control
drink.problems ~ work.distress + work.pressure + lack.job.control"
semPlot::semPaths(semPlot::semPlotModel(m))
library(DiagrammeR)
library(DiagrammeRsvg)
knit_gv <- function(code, filename=NULL, width=NULL, height=800){
assetpath <- "assets"
dir.create(assetpath, showWarnings = F)
if (!is.character(knitr::current_input())){
format <- "png"
a b c d person y
1 1 1 1 1 -1.9867918044766353
2 1 1 1 1 1.065594791935321
1 2 1 1 1 0.6576719872341061
2 2 1 1 1 -0.03331218442628086
1 3 1 1 1 -0.5614874631574662
2 3 1 1 1 -0.6356947275051624
1 1 2 1 1 -1.2451082574418397
2 1 2 1 1 1.5710269904971152
1 2 2 1 1 -1.200570220426128
library(tidyverse)
set.seed(1234)
df <- data_frame(g=c(rep(1, 100), rep(2,100))) %>%
mutate(y = rnorm(n(), 0, 1.5) + .5 * g)
t.test(y~g, data=df)
df %>%
sample_n(50) %>%
ggplot(aes(g,y)) + stat_summary(fun.data=mean_cl_boot)