Skip to content

Instantly share code, notes, and snippets.

View honake's full-sized avatar

honake honake

View GitHub Profile
Company TV Ad Budget Impressions
MILLERLITE 50.1 32.1
PEPSI 74.1 99.6
STROH'S 19.3 11.7
FED'LEXPRESS 22.9 21.9
BURGERKING 82.4 60.8
COCO-COLA 40.1 78.6
MCDONALD'S 185.9 92.4
MCI 26.9 50.7
DIETCOLA 20.4 21.4
@honake
honake / spuriousRegression.r
Created October 16, 2018 13:12
Spurious Regression in R
library(tidyverse)
library(ggplot2)
set.seed(123)
sample_num <- 1000
sigma <- 1
# Generate Two Unit Root Processes
x <- c(0,cumsum(rnorm(sample_num-1, mean=0, sd=sigma)))
y <- c(0,cumsum(rnorm(sample_num-1, mean=0, sd=sigma)))
@honake
honake / adstock.r
Last active April 9, 2021 08:46
Calculate the optimal Ad Stock in R
optimizeAdStock <- function(grp,sales){
rmax <- 0
corrmax <- -1
rates <- seq(0.00, 1.00, by = 0.01)
corrs <- vector()
for(r in rates){
adstock <- stats::filter(grp, filter=r, method = "recursive")
corr <- cor(adstock,sales)
@honake
honake / adstock.py
Last active November 17, 2022 06:54
Calculate the optimal Ad Stock
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def broadbent_adstock(grp, r):
adstock = np.zeros(len(grp))
adstock[0] = grp[0]
for i in range(1,len(grp)):
adstock[i] = grp[i] + r*adstock[i-1]
return adstock
@honake
honake / noise_detection.py
Last active April 24, 2020 22:52
pyaudio detects great cheers and sends a signal to Arduino
import audioop
import math
import numpy as np
import pyaudio
import pyfirmata
import sys
import time
import serial
import wave
@honake
honake / europeanCallOption.cpp
Last active October 21, 2016 05:48
compare MC and BS
#include <iostream>
#include <cmath>
#include "UTRandom1.h"
#include "UTNormals.h"
using namespace std;
double SimpleMonteCarlo1(double Expiry,
double Strike,
double Spot,
@honake
honake / kind_of_fair_combination.rb
Created June 21, 2016 15:12
kind_of_fair_combination.rb
class Array
def fair_combination
arr = []
n = length
m = (n / 2).floor
# Divide by interval
(1..m - 1).each do |j|
subarr = (0..n - 1).to_a
sub1 = []