Skip to content

Instantly share code, notes, and snippets.

View benwhalley's full-sized avatar

Ben Whalley benwhalley

  • Plymouth University
View GitHub Profile
"mediationexample1.csv"
predictor mediator outcome
-1.2070657493854209 -0.18900934031772498 -0.9108482691338935
0.27742924211066 -0.33600385247403014 0.6381941682015424
1.084441176683056 0.6082140820459894 1.8781691743121023
-2.3456977026293493 -1.6753266337085408 -3.3202908207934287
0.42912468881105 -0.6114362427238106 0.12936947474859867
0.506055892157574 0.4200172258317707 1.686535479957183
-0.5747399601346488 -1.1836346063120828 0.08408905976092917
-0.546631855784187 -0.10513054023633653 0.46060044524207233
-0.564451999093283 0.07274226146821294 -0.45904578012362596
-1.2070657493854209 -0.18900934031772498 -0.9108482691338935
0.27742924211066 -0.33600385247403014 0.6381941682015424
1.084441176683056 0.6082140820459894 1.8781691743121023
-2.3456977026293493 -1.6753266337085408 -3.3202908207934287
0.42912468881105 -0.6114362427238106 0.12936947474859867
0.506055892157574 0.4200172258317707 1.686535479957183
-0.5747399601346488 -1.1836346063120828 0.08408905976092917
-0.546631855784187 -0.10513054023633653 0.46060044524207233
-0.564451999093283 0.07274226146821294 -0.45904578012362596
predictor mediator outcome
-0.5799569890194015 -2.386729068806458 0.16615007241450852
-0.9532787019469066 -1.8704045357635897 -2.365057031487532
-0.179428586945621 -0.7802502874626318 0.45227260237394107
1.0098082149443033 1.120252021425702 1.0126134245088094
0.023626614921408818 0.46469454732937937 1.85270396504268
-0.6490282195839006 -1.1446117023037912 -1.0069340694172548
-0.5043742220481909 0.4545346010968645 -1.9860277841931153
1.6143914954583631 2.107280493591184 2.3169539162841035
-0.446959811255663 -1.41170770556635 -0.23362692088530584
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)
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(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"
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))
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,
@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-]+')
}