Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
🐝
Back at work

Nicholas Tierney njtierney

🐝
Back at work
View GitHub Profile
library(lme4)
# broom tidies up model summaries
library(broom) # install.packages("broom")
# fit a mixed model
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
# print the model output
fm1
library(plyr)
library(dplyr)
library(tidyr)
library(visdat)
library(ggplot2)
library(readr)
bible_quote <- read_csv("/Users/tierneyn/Downloads/public-bible-quotations.csv")
# Parsed with column specification:
# cols(
@njtierney
njtierney / advise.md
Created August 18, 2016 09:17 — forked from hadley/advise.md
Advise for teaching an R workshop

I think the two most important messages that people can get from a short course are:

a) the material is important and worthwhile to learn (even if it's challenging), and b) it's possible to learn it!

For those reasons, I usually start by diving as quickly as possible into visualisation. I think it's a bad idea to start by explicitly teaching programming concepts (like data structures), because the pay off isn't obvious. If you start with visualisation, the pay off is really obvious and people are more motivated to push past any initial teething problems. In stat405, I used to start with some very basic templates that got people up and running with scatterplots and histograms - they wouldn't necessary understand the code, but they'd know which bits could be varied for different effects.

Apart from visualisation, I think the two most important topics to cover are tidy data (i.e. http://www.jstatsoft.org/v59/i10/ + tidyr) and data manipulation (dplyr). These are both important for when people go off and apply

@njtierney
njtierney / all_na.R
Created September 5, 2016 06:47
find if a matrix contains only missing values
ras_1 <- matrix(data = rep(NA, 100),
nrow = 10,
ncol = 10,
byrow = TRUE)
ras_1
ras_2 <- matrix(data = c(1,rep(NA, 99)),
nrow = 10,
ncol = 10,
iris_lm_fit_all <- lm(Sepal.Length ~ ., iris)
iris_lm_fit_all_step <- step(iris_lm_fit_all,
scope = Sepal.Length ~ .^2)
#> Start: AIC=-348.57
#> Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species
#>
#> Df Sum of Sq RSS AIC
#> + Petal.Length:Species 2 0.4883 13.068 -350.07
#> + Sepal.Width:Petal.Length 1 0.2754 13.281 -349.64
@njtierney
njtierney / Makefile
Created September 20, 2016 05:58 — forked from PirateGrunt/Makefile
Basic makefile
####################
# Makefile
# Copyright Brian A. Fannin 2015
####################
RDIR = .
DATA_DIR = $(RDIR)/data
GATHER_DIR = $(DATA_DIR)/gather
GATHER_SOURCE = $(wildcard $(GATHER_DIR)/*.Rmd)
# working out whether transactions have reciprocated
library(tibble)
library(dplyr)
# let's boil this example down
df_boil <- tribble(
~sender, ~receiver, ~transaction_id,
1, 2, "A",
project
|- DESCRIPTION # project metadata and dependencies
|- README.md # top-level description of content and guide to users
|- NAMESPACE # exports R functions in the package for repeated use
|- LICENSE # specify the conditions of use and reuse of the code, data & text
|- data/ # raw data, not changed once created
| +- my_data.csv # data files in open formats such as TXT, CSV, TSV, etc.
|
|- analysis/ # Series of folders for each step of the analysis
@njtierney
njtierney / copula-example.R
Last active October 20, 2016 01:54
R copula code exampl
# install.packages("VineCopula")
# install.packages("copula")
# install.packages("tigerstats")
library(VineCopula)
library(copula)
library(tigerstats)
set.seed(123)
N=200
dim=dim
@njtierney
njtierney / qut_hpc_r_packages.R
Last active November 1, 2016 00:48
QUT HPC R packages, as of 31/10/2016 @ 17:50
ip <- as.data.frame(installed.packages()[,c(1,3:4)])
rownames(ip) <- NULL
ip <- ip[is.na(ip$Priority),1:2,drop=FALSE]
write.csv(ip, "package_list.csv")
print(ip, row.names=FALSE)