Skip to content

Instantly share code, notes, and snippets.

library("shiny")
library("ggplot2")
n_obs <- 500L
## Define UI for application that draws a histogram
ui <- fluidPage(
## Application title
titlePanel("Visualizing Raw Data vs Residuals"),
@dalejbarr
dalejbarr / t1_error.R
Last active July 10, 2017 13:26
Monte Carlo simulation showing how large samples can increase false positive rates when a source of variation is neglected
library("simgen") # devtools::install_github("dalejbarr/simgen")
library("tibble")
library("ggplot2")
library("parallel")
get_typeI <- function(ns, ni, pops, clust) {
res <- mcRun(fitanova, mcr.fnArgs = list(wsbi = FALSE),
mcr.cluster = clust,
mcr.datFn = mkDf,
mcr.datArgs = list(wsbi = FALSE, nsubj = ns, nitem = ni),
@dalejbarr
dalejbarr / L3_stats_homework_5_2016.R
Created November 4, 2016 12:26
script for video walkthrough on using R/RStudio for 3-way ANOVA
## youtube video: https://youtu.be/AJDo9gpkEcg
library("readr")
library("ggplot2")
## read.csv() <- from base R. DON'T USE!
hw5 <- read_csv("homework_5.csv") # from readr
hw5$A <- factor(hw5$A)
hw5$B <- factor(hw5$B)
hw5$C <- factor(hw5$C)
@dalejbarr
dalejbarr / scottish_babynames.rmd
Created September 9, 2016 13:42
RMarkdown document for generating a report on scottish babynames
---
title: "Scottish Babynames"
author: "Dale Barr"
date: "7 September 2016"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@dalejbarr
dalejbarr / scottish_babynames.R
Created September 9, 2016 13:40
R script for analyzing Scottish babynames
library(dplyr)
library(readr)
library(ggplot2)
dat <- read_csv("babies-first-names-all-names-all-years2.csv")
# pull out babies born in 1998
dat98 <- filter(dat, yr == 1998) %>%
group_by(sex) %>%
filter(rank <= 5)
## join x and y, replacing any columns in x with matching columns from y
## x : the table with values to be replaced
## y : the table containing replacement values
## cols : the key columns (i.e., cols to join on)
replace_join <- function(x, y, cols) {
keep <- setdiff(names(x), names(y))
dplyr::inner_join(dplyr::select_(x, .dots = c(cols, keep)), y, cols)
}
## like above, but:
@dalejbarr
dalejbarr / buzz_me.R
Last active August 29, 2015 14:23
buzz_me(): receive notifications on your mobile from R!
## Inspired by http://bconnelly.net/2015/06/connecting-r-to-everything-with-ifttt/
## NB: set up IFTTT Maker channel to watch for R_event and then notify.
## Get your own personal maker key from https://ifttt.com/maker
## Put the code snippet below in ~/.Rprofile
buzz_me <- function(msg = "DONE!", event = "R_event") {
maker_key <- "yOuR_maKER_keY_GoES_HerE"
url <- paste0("https://maker.ifttt.com/trigger/", event, "/with/key/", maker_key)
if (requireNamespace("httr", quietly = TRUE)) {
invisible(httr::POST(url, body = list(value1 = msg), encode = "json"))
} else {
@dalejbarr
dalejbarr / full_analysis.R
Last active August 29, 2015 14:06
Datahowler reanalysis of Fredrickson et al. (2013)
# you will need to install the package RR53 to run this script
# to download and install, use the following two commands:
# library(devtools)
# install_github("RR53", "dalejbarr")
library(RR53)
# download Brown et al.'s version of the data from PNAS
# you need only do this once to store a local copy
# comment out from the script after first use