Skip to content

Instantly share code, notes, and snippets.

View davebraze's full-sized avatar

Dave Braze davebraze

View GitHub Profile
@davebraze
davebraze / alt-ide-rstats.md
Last active October 28, 2021 18:27
Alternative IDEs for RStats

The RStudio integrated development environment (IDE) was first released in 2011. The goals of its creators, so far as I can tell, were these. First, they wanted to provide a better R coding experience than could be had through the bare-bones text editor that shipped with R itself. They also wanted to take into account the fact that many new users of R had no previous programming experience, and so had no familiarity with the kinds of tools that support efficient coding workflows. The RStudio IDE was intended to provide a relatively simple unified interface to R, its command line, help system, and plots. It eventually expanded to include limited interfaces to command line utilities like (e.g.,) git and pandoc, which can usefully supplement an R based workflow. Importantly, RStudio was geared toward novice programmers who might be coding only in R.

That said, there are other IDEs that will get the job done. Many of these are more general purpose tools, supporting a number of programming languages beyond R (as

@davebraze
davebraze / yaml-rmarkdown.md
Last active June 30, 2019 17:47
Access yaml variables within rmarkdown file

Given a yaml block like this:

---
title: My Data Summary (DRAFT)
subtitle: Fall 2019 Data
author: David Braze
institute: Haskins Laboratories
date: "`r format(Sys.time(), '%B %d, %Y')`"
@davebraze
davebraze / R-ggplot2-tools.md
Last active June 28, 2019 17:40
ggplot2 tools and techniques
@davebraze
davebraze / R-tables.md
Last active July 30, 2023 04:59
R Tables

Intro

Getting the right tables for a project can be fiddly in R, both for content and format. What I really prefer is clean separation between functions for generating content of a table, from those to do with its formatting. I am often, but not always, working in the context of an rmarkdown based workflow. There, fine control over format details will usually require making use of tools peculiar to the output type of the document (pdf, html, etc). This can complicate things a bit.

Table Content

These methods and tools are primarily about getting table content right.

Summary tables from dataframes

dplyr::

@davebraze
davebraze / level-order.R
Last active September 25, 2018 15:29
Basics of factor level ordering
##### Basic factor level ordering and (treatment) contrasts
## set up data.frame with 1 continuous variable and 1 factor with 8 levels.
set.seed(1234)
x <- rnorm(80)
fac <- factor(rep(LETTERS[8:1], 10))
df <- data.frame(x, fac)
df$x[as.integer(df$fac) %% 5 == 0] <- rnorm(10, 1)
head(df, 16) ## Note the order of factor levels in this data is reverse
@davebraze
davebraze / mlm-df-p.R
Last active February 27, 2019 19:04
place holder for thoughts on df correction and pvals in MLMs
lmerTest:: satterthwaite df estimation
pbkrtest:: kenward-roger df estimation; also parametric-bootstrap per Judd, Westfall & Kenny (2012)
mertools:: provides prediction intervals for parameters estimates in lme4 models.
semTools:: supplements lavaan.
mcmcglmm:: bayesian mixed models.
glmmPQL::
plotmcmc::
GLMM FAQ:
@davebraze
davebraze / fixations.R
Last active March 6, 2018 15:46
Convert wide format fixation report to long format samples
library(tidyverse)
## toy fixation report
fixations <- tibble(fixidx=as.integer(1:3), start=c(100,250,372), end=c(202, 348, 426),
x=sample(0:1000,3), y=sample(0:1000,3))
## convert to long format
fixations <- fixations %>%
gather(start, end, -c(fixidx,x,y)) %>%
arrange(fixidx) %>%
@davebraze
davebraze / logits.R
Last active February 2, 2018 19:57
probabilities, odds, log odds (logits)
p <- seq(0,1,.05)
odds <- p/(1-p)
logOdds <- log(odds)
cbind(p, odds, logOdds)
## p odds logOdds
## [1,] 0.00 0.000000 -Inf
## [2,] 0.05 0.052632 -2.94444
## [3,] 0.10 0.111111 -2.19722
@davebraze
davebraze / multicollinearity.R
Last active March 29, 2018 15:33
Assessing Multi-collinearity
library(car)
library(Hmisc)
library(perturb)
n <- 200
x0 <- rnorm(n)
x1 <- rnorm(n)
x2 <- x1 + rnorm(n)/2
x3 <- x2 + rnorm(n)/1.25
@davebraze
davebraze / random-effects.R
Last active September 27, 2018 10:46
Basic random effect structures and non-convergence in lmer()
library(lme4)
library(nlme)
library(ggplot2)
data(Oxboys)
head(Oxboys, 12)
ggplot(aes(y=height, x=age), data=Oxboys) +
geom_point() + geom_path(aes(group=Subject))