Skip to content

Instantly share code, notes, and snippets.

View MarkEdmondson1234's full-sized avatar
🦑
Tappity tap tap

Mark Edmondson MarkEdmondson1234

🦑
Tappity tap tap
View GitHub Profile
@MarkEdmondson1234
MarkEdmondson1234 / server.r
Created February 16, 2014 10:22
Cascading Menu System for Shiny
library(shiny)
## test dataframe
df <- data.frame(option1 = c("A","A","B","B","C","C"),
option2 = c("A1","A2","B3","B1","C2","C3"),
option3 = c(T,F,T,F,T,F),
option4 = c("a","b","c","d","e","f"))
shinyServer(function(input, output, session) {
@MarkEdmondson1234
MarkEdmondson1234 / HWplot.R
Created June 18, 2014 21:29
A function to plot a holtWinters timeseries in ggplot2
#HWplot.R
library(ggplot2)
library(reshape)
HWplot<-function(ts_object, n.ahead=4, CI=.95, error.ribbon='green', line.size=1){
hw_object<-HoltWinters(ts_object)
@MarkEdmondson1234
MarkEdmondson1234 / auth.r
Last active February 24, 2020 22:25
Authenticate a Twitter app in R
# Refer to https://rtweet.info/
@MarkEdmondson1234
MarkEdmondson1234 / processTweets.r
Last active August 29, 2015 14:02
A couple of functions used to process Tweets after fetching
### tweetdata.r
### Fetch Twitter data and Data Transformations
### Requires you have authenticated in auth.R
### 15th June 2014
### Mark Edmondson @HoloMarkeD
###
### For use with Twitter API, processTweets() takes the df$tweetDF data.frame as input
### And calculates/transforms data for the plots
processTweets <- function(tweetDF,
### plotTweets.r
### Plot out tweets
### Requires you have authenticated in auth.R and processed in tweetdata.R
### 15th June 2014
### Mark Edmondson @HoloMarkeD
###
library(ggplot2)
######################################################################
@MarkEdmondson1234
MarkEdmondson1234 / r-installation-debain-wheezy
Last active February 10, 2016 14:43
Installation of R, Rstudio, OpenCPU on GCE Debain Wheezy image, details on how to in the blogpost http://markedmondson.me/run-r-rstudio-and-opencpu-on-google-compute-engine-free-vm-image
### r-installation-debain-wheezy
#### setup commands to setup R, RStudio and OpenCPU on a Google Compute Engine Wheezy instance
#### Mark Edmondson 29 June 2014
##
## No original work, all taken from these sources:
## https://github.com/jeroenooms/opencpu-deb/blob/master/build-on-debian.md
## https://support.rstudio.com/hc/communities/public/questions/200651456-RStudio-server-not-installable-on-Debian-Wheezy-just-released-this-week-
## http://cran.r-project.org/bin/linux/debian/README.html
# need to be sudo for all below
@MarkEdmondson1234
MarkEdmondson1234 / grabCSVColumn.sh
Created October 15, 2014 10:45
Input in a csv and a column, get out another file with just that column
#!/bin/bash
INPUT=
OUTPUT="output.txt"
COL=1
while [ $# -gt 0 ]
do
case "$1" in
-f) INPUT="$2"; shift;;
@MarkEdmondson1234
MarkEdmondson1234 / setup.R
Created November 2, 2014 10:41
Setup rga() and CausalImpact() packages
## Setup
## below only needed first time if you haven't the packages installed
# install.packages("devtools")
# library(devtools)
# devtools::install_github("google/CausalImpact")
## load the libraries
library(CausalImpact)
library(rga)
@MarkEdmondson1234
MarkEdmondson1234 / getGAdata.R
Last active August 29, 2015 14:08
Get the GA data for a profile
## pull in the GA data
# get list of profiles
profiles <- ga$getProfiles()
# View the profiles table, and pick the profile you want and put in the profile ID below
UA <- "XXXXXXX"
# choose the dates you want to pull in data for
date_before = "2014-09-01"
@MarkEdmondson1234
MarkEdmondson1234 / causalImpactOnGA.R
Last active August 29, 2015 14:08
Apply CausalImpact package to the GA output.
## do the causalImpact
# here the effect took place on the 200th day of the data imported, so the pre.period = 200
# Data is examined and compared in the post perid to day 244
impact <- CausalImpact(data = gadata$visits,
pre.period = c(1,200),
post.period = c(201,244),
model.args = NULL,
bsts.model = NULL,
post.period.response = NULL,
alpha = 0.05)