Skip to content

Instantly share code, notes, and snippets.

@daynebatten
daynebatten / PassThePigsAI.js
Last active August 29, 2015 14:12
Calculate win probabilities from any Pass the Pigs game state
function calculate() {
for (i=0; i<=99; i++) {
probs[i]=[];
for (j=0; j<=99; j++) {
probs[i][j]=[];
for (k=0; k<=99; k++){
probs[i][j][k]=.5;
}
@daynebatten
daynebatten / Mouse Distance.bb
Last active August 29, 2015 14:13
Tells you how far your mouse moves. I wrote this in high school, so it's pretty terrible. You've been warned.
AppTitle "Mouse Distance"
file=ReadFile("distance.ini")
Global custom=ReadLine(file)
Global width=ReadLine(file)
Global height=ReadLine(file)
Global writedelay=ReadLine(file)
Global inches#=ReadLine(file)
Global feet=ReadLine(file)
Global miles=ReadLine(file)
female time churned
0 273 0
0 360 0
0 8 0
0 211 0
# Use the survival library
library(survival)
# Read in the NetLixx data... yes, I use Windows.
net_lixx <- read.csv('C:/Users/dayne/Desktop/NetLixx.csv')
# Create a "survival object" for each observation, using time and churn data.
# Run basic setup again
library(survival)
net_lixx <- read.csv('C:/Users/dayne/Desktop/NetLixx.csv')
net_lixx$survival <- Surv(net_lixx$time, net_lixx$churned == 1)
# Fit survival curves based on the female binary
fit <- survfit(survival ~ female, data = net_lixx)
Call:
survdiff(formula = survival ~ female, data = net_lixx)
N Observed Expected (O-E)^2/E (O-E)^2/V
female=0 6722 830 778 3.48 12.4
female=1 2532 251 303 8.94 12.4
Chisq= 12.4 on 1 degrees of freedom, p= 0.000422
female age coupon churned time
0 64 0 1 158
0 22 0 0 25
0 37 0 0 150
0 55 0 0 311
# Load the survival library
library(survival)
# Read in the data and create a "survival object"
netlixx_cox <- read.csv('C:/Users/dayne/Desktop/NetLixxCox.csv')
netlixx_cox$survival <- Surv(netlixx_cox$followtime, netlixx_cox$churn == 1)
# Run a cox regression of survival on female, age, and coupon status
coxph(formula = survival ~ female + age + coupon, data = netlixx_cox)
coef exp(coef) se(coef) z p
female -0.03749 0.963 0.09098 -0.412 6.8e-01
age -0.00561 0.994 0.00176 -3.191 1.4e-03
coupon 0.58709 1.799 0.08104 7.245 4.3e-13
Likelihood ratio test=58.3 on 3 df, p=1.37e-12 n= 5124, number of events= 743
# Run a test for non-proportional hazards on our cox regression results
cox.zph(results)