Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Finishing up 2020

Nicholas Tierney njtierney

:octocat:
Finishing up 2020
View GitHub Profile
View example PCA
# turn the data into a correlation matrix
cor(mydata)
# perform the PCA, using `principal`
pca.fit <- principal(mydata,
nfactors = ncol(mydata), # the number of factors = the number of columns in my data
rotate = "varimax", # I want to perform varimax rotation on the factors
residuals = TRUE, # report the residuals
scores = TRUE) # find the component scores
@njtierney
njtierney / alt-gen-MCAR-fun
Last active Aug 29, 2015
create MCAR data (from package `mi`).
View alt-gen-MCAR-fun
mi:::.create.missing
function (data, pct.mis = 10)
{
n <- nrow(data)
J <- ncol(data)
if (length(pct.mis) == 1) {
n.mis <- rep((n * (pct.mis/100)), J)
}
else {
if (length(pct.mis) < J)
@njtierney
njtierney / knitr set up
Created Mar 9, 2015
This code is my standard setup for rmarkdown in knitr.
View knitr set up
```{r global_options, include=FALSE, cache=FALSE}
library(knitr)
# Set basic options. You usually do not want your code, messages, warnings etc.
# to show in your actual manuscript however for the first run or two these will
# be set on.
opts_chunk$set(echo=FALSE,
warning=FALSE,
message=FALSE,
cache = TRUE,
include = FALSE,
View bob-data.csv
Serial study of factors influencing changes in cardiac output during human pregnancy 557 1989
Bayesian inference for a discretely observed stochastic kinetic model 172 2008
159 1992
151 1996
150 1987
127 1992
126 1992
97 1996
95 2003
94 1991
View gist:e5da929db3d31bf91f49
# assuming data has columns named something like: "lat", "long", and "timestamp"
library(ggmaps)
library(ggplot2)
ggplot(data = data,
aes(x = lat,
y = long)) +
geom_point() +
View gist:89c3ce38ea27ea94a7dc
layout title
post
Another test post

OK so here is my idea about How these post snippets could work. could work.

What problem are you addressing.

In this snippet we address the problem: ...

View array_distance
#' meteo_distance
#'
#' @description
#'
#' @param data a dataframe. Expects col headers with names latName and longName
#' @param lat Latitude to centre search at
#' @param long Longitude to centre search at
#' @param latName Name of latitude header name in data, Default = 'latitude'
#' @param longName Name of longitude header name in data. Default = 'longitude'
#' @param units Units of the latitude and longitude values: degrees 'deg', radians 'rad', d/m/s 'dms'. Default = 'deg'
View visdat-messy-test
context("Test names with spaces")
messy_names <- data_frame(`Sepal Width` = iris$Sepal.Width,
`Sepal Length` = iris$Sepal.Length,
`Petal Length` = iris$Petal.Length,
`Species Names` = iris$Species)
test_that("vis_dat works on dataframes with irregular variable names", {
expect_success(
vis_dat(messy_names)
@njtierney
njtierney / find_previous_smoker.R
Created May 24, 2016
smoking data: Has there been a smoker in the past
View find_previous_smoker.R
# calculate if there has been a smoker in the past
# "smoked_previously"
data_prac <- data_frame(ID = c(1, 1, 1, 1,
201, 201,
342, 342, 342,
613, 613, 613, 613, 613),
time = c(1, 2, 3, 4,
1, 2,
@njtierney
njtierney / microbm_visdat_wakefield.md
Created May 29, 2016
benchmark for vis_dat and table_heat
View microbm_visdat_wakefield.md
library(microbenchmark)
library(wakefield)
library(visdat)

mb1 <-
microbenchmark(vis_dat(airquality),
               table_heat(airquality))

boxplot(mb1)