This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We simulate draws from two different timing distributions representing different processes | |
payment_failures <- rexp(1000, rate = 1/90) | |
intentional_churn <- rexp(1000, rate = 1/120) | |
### proportion of payment failures to intentional churn at 90 day cutoff | |
pf_90 <- (payment_failures < 90) %>% sum | |
if_90 <- (intentional_churn < 90) %>% sum | |
pf_90 / (if_90 + pf_90) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# draw from an exponential distribution with mean 90 | |
payment_failures <- rexp(1000, rate = 1/90) | |
# number of payment failures after 90 days | |
pf_90 <- (payment_failures < 90) %>% sum | |
# number of payment failures after 60 days (assuming same distribution) | |
pf_60 <- (payment_failures < 60) %>% sum | |
# number of 90 day payment failures observed relative to 60 day payment failures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(corrplot) | |
playstation_data <- matrix(0, nrow = 6, ncol = 5) | |
rownames(playstation_data) <- c("Connoisseurs", "Connectors", "Rivals", "Indulgers", "Escapers", "Dabblers") | |
colnames(playstation_data) <- c("Periphery", "Hit", "Mid-Core", "Core", "Occasionals") | |
playstation_data[1, ] <- c(10, 5, 3, 101, 18) | |
playstation_data[2, ] <- c(38, 10, 72, 18, 68) | |
playstation_data[3, ] <- c(10, 110, 22, 28, 15) | |
playstation_data[4, ] <- c(80, 10, 9, 44, 70) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# normalize sequences | |
tx_sample <- | |
tx_sample %>% | |
mutate( | |
order_date = order_date - first_date | |
) | |
# create TraMineRextras object | |
tx_seq <- seqecreate( | |
id = tx_sample$customer_id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
korresp_som <- trainSOM(a, scaling = "chi2", type = "korresp", dimension = c(2,2)) | |
row_num <- korresp_som$parameters$the.grid$dim[[1]] | |
col_num <- korresp_som$parameters$the.grid$dim[[2]] | |
korresp_clusters <- | |
korresp_som$clustering %>% | |
as.data.frame %>% | |
set_colnames(c("cluster")) %>% | |
mutate(entity = rownames(.)) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
indexation <- function(A) | |
{ | |
A / ((rowSums(A)/sum(rowSums(A))) %*% | |
t(colSums(A)/sum(colSums(A))) * | |
sum(A)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model { | |
for(i in 1:n_obs){ | |
hrc_votes[i] ~ dbin(p[i], n_votes[i]) | |
p[i] ~ dbeta(alpha[i], beta[i]) | |
# reparameterization of the beta distribution taken from this site | |
# http://bit.ly/2i880Oj | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Betas # | |
samples <- coda.samples(jags, c('beta_age', | |
'beta_percent_white', | |
'beta_uninsured', | |
'beta_unemployed', | |
'beta_percent_degree', | |
'beta_income', | |
'beta_health'), 10000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RColorBrewer) | |
library(fields) #to use designer.colors | |
library(reshape2) | |
library(dplyr) | |
gradient_heatmap <- | |
function( | |
df, | |
num_percentiles = 10, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ca) | |
library(ggplot2) | |
library(ggrepel) | |
library(stringr) | |
library(scales) | |
library(magrittr) | |
library(factoextra) | |
repel_ca_from_table <- | |
function( |