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
### Keybase proof
I hereby claim:
* I am MarkEdmondson1234 on github.
* I am marked (https://keybase.io/marked) on keybase.
* I have a public key whose fingerprint is 5D7E 6B62 C8C4 9CAB 9E8C 9004 C15F A69E 22CA F569
To claim this, I am signing this object:
@MarkEdmondson1234
MarkEdmondson1234 / casualImpact_shiny.r
Last active August 29, 2015 14:15
CausalImpact in Shiny
## in server.r of a shiny app
casualImpactData <- reactive({
## only if we have the data ready
validate(
need(chartData(), "Need data")
)
data <- chartData()
# secrets.R
options(
mysql = list(
"host" = "YOUR SQL IP",
"port" = 3306,
"user" = "YOUR SQL USER",
"password" = "YOUR USER PW",
"databaseName" = "onlinegashiny"),
rga = list(
"profile_id" = "The GA View ID",
## functions.R
library(rga)
library(dygraphs)
library(zoo)
library(tidyr)
library(lubridate)
library(d3heatmap)
library(dplyr)
library(stringr)
library(DT)
@MarkEdmondson1234
MarkEdmondson1234 / url_short.R
Last active August 29, 2015 14:27
Demo using googleAuthR to create a Google API package
library(googleAuthR)
## change the native googleAuthR scopes to the one needed.
options("googleAuthR.scopes.selected" =
c("https://www.googleapis.com/auth/urlshortener"))
#' Shortens a url using goo.gl
#'
#' @param url URl to shorten with goo.gl
#'
@MarkEdmondson1234
MarkEdmondson1234 / shiny_url_short.R
Created August 19, 2015 07:47
Demo using Shiny with googleAuthR
## in global.R
library(googleAuthR)
options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/urlshortener"))
shorten_url <- function(url){
body = list(
longUrl = url
)
install.packages("googleAuthR")
library(googleAnalyticsR_public)
gar_auth(new_user=T)
## your profile view Id
id <- "XXXXXX"
## 61607 results
## 30049 unique Ids
## 185 Sku's
## function to get plot data format
getCompareTable <- function (test_data, prediction) {
require(dplyr)
## plot real vs model bought Sku
actual_freq <- table(model_data$boughtSku)
predicted_freq <- table(prediction)
actual_freq <- actual_freq[order(actual_freq)]
predicted_freq <- predicted_freq[order(predicted_freq)]
## Finding number of components
pc <- princomp(model_data)
plot(pc, type="l")
# look for dimension that is ~ 85% variance
summary(pc)
loadings(pc)
# run more convenient pca needed for k-means
pc <- prcomp(k_data)