This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Function is also in this package: https://github.com/rubenarslan/formr | |
#' It's easy to attach packages that overwrite functions from other packages. Especially dplyr has a lot of conflicts | |
#' with base packages, MASS and plyr. Because some of these conflicts do not always lead to error messages, sometimes | |
#' just incorrect behaviour, this function exists. Don't trust your faulty memory, just check whether dplyr's (or any other | |
#' package's) functions are 'on top' if you so desire. | |
#' | |
#' @param fix defaults to true. Detaches the desired package (without unloading) and loads it again. Won't work for base packages and can't overwrite functions that you defined yourself. | |
#' @param package the package you want to be on top (loaded last), defaults to dplyr | |
#' @param iteration for internal use only, if set to 0 the function will call itself to check that it worked, if set to 1, it won't. | |
#' @export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' easier marginal effect plots from brms objects | |
#' ## ideas? | |
#' visualise uncertainty with violin plots instead of pointranges | |
#' (would mean getting rid of early-on summary) | |
#' ### shorthand for finding mode | |
#' from https://stackoverflow.com/questions/2547402/standard-library-function-in-r-for-finding-the-mode | |
Mode <- function(x) { | |
ux <- unique(x) | |
ux[which.max(tabulate(match(x, ux)))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
diary = structure(list(short_session = c("006935", "006935", "006935", | |
"006935", "006935", "006935", "006935", "006935", "006935", "006935", | |
"006935", "006935", "006935", "006935", "006935", "006935", "006935", | |
"006935", "006935", "006935", "006935", "006935", "006935", "006935", | |
"006935", "006935", "006935", "006935", "006935", "006935", "006935", | |
"006935", "006935", "006935", "006935", "006935", "006935", "006935", | |
"006935", "008e1a", "008e1a", "008e1a", "008e1a", "008e1a", "008e1a", | |
"008e1a", "008e1a", "008e1a", "008e1a", "008e1a", "008e1a", "008e1a", | |
"008e1a", "008e1a", "008e1a", "008e1a", "008e1a", "008e1a", "008e1a", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fact_levels = c("[0,25]","(25,30]","(30,35]") | |
cases = 5e4 | |
exampledata = data.frame(idParents = sample(1:(cases/10), size = cases, replace = T), | |
paternalage.factor = factor(sample(fact_levels, size = cases, replace=T),levels = fact_levels)) | |
exampledata$outcome = rpois(cases,lambda = log(30 + (as.numeric(exampledata$paternalage.factor))*-0.2 + 0.8 *rnorm(cases))) | |
exampledata$outcome = ifelse(plogis(log(as.numeric(exampledata$paternalage.factor))-2 + rnorm(cases)) > 0.5, 0, exampledata$outcome) | |
samples = 1000; thin = 10; burnin = 3000; nitt = samples * thin + burnin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype HTML> | |
<meta charset = 'utf-8'> | |
<html> | |
<head> | |
<script src='http://ramnathv.github.io/rCharts/libraries/widgets/polycharts/js/polychart2.standalone.js' type='text/javascript'></script> | |
<style> | |
.rChart { | |
display: block; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggprplots <- function(fit, alpha=0.1) { | |
design <- model.matrix(fit) | |
# Skip the intercept term, if any. | |
m0 <- if (colnames(design)[1] == '(Intercept)') { 2 } else { 1 } | |
M <- ncol(design) | |
data <- do.call(rbind, lapply(m0:M, function(m) { | |
var <- colnames(design)[m] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> raw_c3_a3 | |
Linear mixed model fit by REML ['lmerMod'] | |
Formula: churchattendance ~ poly(cohort_c, 3, raw = T) * poly(age_c, 3, raw = T) + ctd_c + dropoutalive + obs_c + (1 + poly(age_c, 3, raw = T) | PERSNR) | |
Data: long.kg | |
REML criterion at convergence: 316048.9 | |
Random effects: | |
Groups Name Variance Std.Dev. Corr | |
PERSNR (Intercept) 0.6409284 0.80058 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(272773) | |
individuals = data.frame( | |
children = c(6, 6, 1, 4, 1, 1, 1, 2, 11, 3, 7, 2, 6, 4, 4, 3, 1, 4, 2, 10, | |
2, 1, 2, 3, 1, 6, 14, 4, 4, 1, 7, 8, 2, 3, 2, 1, 1, 8, 8, 5, | |
7, 4, 1, 3, 4, 1, 2, 8, 1, 1, 1, 1, 2, 7, 4, 3, 4, 1, 1, 3, 1, | |
1, 6, 3, 1, 3, 4, 3, 3, 5, 5, 5, 3, 6, 2, 6, 4, 7, 4, 2, 7, 7, | |
5, 1, 4, 1, 9, 1, 6, 5, 3, 1, 4, 1, 9, 3, 5, 3, 3, 12, 1, 4, | |
4, 8, 14, 2, 1, 4, 5, 4, 4, 10, 3, 5, 1, 1, 2, 5, 4, 1, 4, 1, | |
5, 1, 3, 5, 2, 1, 8, 3, 7, 2, 6, 5, 3, 2, 4, 1, 3, 7, 3, 1, 1, | |
14, 3, 1, 3, 3, 2, 1, 5, 3, 4, 13, 7, 9, 3, 3, 7, 2, 2, 4, 7, |
NewerOlder