2024-04-25 01:55:56 +00:00
|
|
|
library(tidyverse)
|
|
|
|
library(plyr)
|
|
|
|
#get the contrib data instead
|
|
|
|
try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path)))
|
|
|
|
contrib_df <- read_csv("../final_data/deb_contrib_did.csv")
|
|
|
|
#some preprocessing and expansion
|
|
|
|
col_order <- c("upstream_vcs_link", "age_of_project", "event_date", "event_hash", "before_all_ct", "after_all_ct", "before_mrg_ct", "after_mrg_ct", "before_auth_new", "after_auth_new", "before_commit_new", "after_commit_new")
|
|
|
|
contrib_df <- contrib_df[,col_order]
|
|
|
|
contrib_df$ct_before_all <- str_split(gsub("[][]","", contrib_df$before_all_ct), ", ")
|
|
|
|
contrib_df$ct_after_all <- str_split(gsub("[][]","", contrib_df$after_all_ct), ", ")
|
|
|
|
contrib_df$ct_before_mrg <- str_split(gsub("[][]","", contrib_df$before_mrg_ct), ", ")
|
|
|
|
contrib_df$ct_after_mrg <- str_split(gsub("[][]","", contrib_df$after_mrg_ct), ", ")
|
|
|
|
drop <- c("before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct")
|
|
|
|
contrib_df = contrib_df[,!(names(contrib_df) %in% drop)]
|
|
|
|
# 2 some expansion needs to happens for each project
|
|
|
|
expand_timeseries <- function(project_row) {
|
|
|
|
longer <- project_row |>
|
|
|
|
pivot_longer(cols = starts_with("ct"),
|
|
|
|
names_to = "window",
|
|
|
|
values_to = "count") |>
|
|
|
|
unnest(count)
|
|
|
|
longer$observation_type <- gsub("^.*_", "", longer$window)
|
|
|
|
longer <- ddply(longer, "observation_type", transform, week=seq(from=0, by=1, length.out=length(observation_type)))
|
|
|
|
longer$count <- as.numeric(longer$count)
|
|
|
|
#longer <- longer[which(longer$observation_type == "all"),]
|
|
|
|
return(longer)
|
|
|
|
}
|
|
|
|
expanded_data <- expand_timeseries(contrib_df[1,])
|
|
|
|
for (i in 2:nrow(contrib_df)){
|
|
|
|
expanded_data <- rbind(expanded_data, expand_timeseries(contrib_df[i,]))
|
|
|
|
}
|
|
|
|
#filter out the windows of time that we're looking at
|
|
|
|
window_num <- 8
|
|
|
|
windowed_data <- expanded_data |>
|
|
|
|
filter(week >= (27 - window_num) & week <= (27 + window_num)) |>
|
|
|
|
mutate(D = ifelse(week > 27, 1, 0))
|
2024-05-13 04:22:14 +00:00
|
|
|
#scale the age numbers and calculate the week offset here
|
2024-04-25 01:55:56 +00:00
|
|
|
windowed_data$scaled_project_age <- scale(windowed_data$age_of_project)
|
|
|
|
windowed_data$week_offset <- windowed_data$week - 27
|
2024-05-13 04:22:14 +00:00
|
|
|
#break out the different type of commit actions
|
2024-04-25 01:55:56 +00:00
|
|
|
all_actions_data <- windowed_data[which(windowed_data$observation_type == "all"),]
|
|
|
|
mrg_actions_data <- windowed_data[which(windowed_data$observation_type == "mrg"),]
|
2024-05-13 04:22:14 +00:00
|
|
|
#logging
|
2024-04-27 19:30:20 +00:00
|
|
|
all_actions_data$logged_count <- log(all_actions_data$count)
|
|
|
|
all_actions_data$log1p_count <- log1p(all_actions_data$count)
|
2024-06-13 18:40:27 +00:00
|
|
|
#EDA
|
|
|
|
range(all_actions_data$log1p_count) # 0.000000 6.745236
|
|
|
|
mean(all_actions_data$log1p_count) # 1.200043
|
|
|
|
var(all_actions_data$log1p_count) # 1.753764
|
|
|
|
median(all_actions_data$log1p_count) # 0.6931472
|
2024-04-27 19:30:20 +00:00
|
|
|
# now for merge
|
|
|
|
mrg_actions_data$logged_count <- log(mrg_actions_data$count)
|
|
|
|
mrg_actions_data$log1p_count <- log1p(mrg_actions_data$count)
|
2024-04-25 01:55:56 +00:00
|
|
|
#imports for models
|
|
|
|
library(lme4)
|
|
|
|
library(optimx)
|
2024-05-07 23:40:38 +00:00
|
|
|
library(lattice)
|
2024-05-13 04:22:14 +00:00
|
|
|
#model
|
2024-05-12 19:06:18 +00:00
|
|
|
all_gmodel <- glmer.nb(log1p_count ~ D * week_offset + scaled_project_age + (D * week_offset | upstream_vcs_link),
|
|
|
|
control=glmerControl(optimizer="bobyqa",
|
|
|
|
optCtrl=list(maxfun=2e5)), nAGQ=0, data=all_actions_data)
|
|
|
|
summary(all_gmodel)
|
|
|
|
saveRDS(all_gmodel, "0512_contrib_all.rda")
|
|
|
|
all_residuals <- residuals(all_gmodel)
|
|
|
|
qqnorm(all_residuals)
|
2024-04-25 01:55:56 +00:00
|
|
|
#identifying the quartiles of effect for D
|
2024-05-12 19:06:18 +00:00
|
|
|
test_condvals <- broom.mixed::tidy(all_gmodel, effects = "ran_vals", conf.int = TRUE)
|
|
|
|
test_glmer_ranef_D <- test_condvals [which(test_condvals $term == "D"),]
|
|
|
|
has_zero <- function(estimate, low, high){
|
|
|
|
return(ifelse((low < 0),ifelse((high > 0), 1, 0), 2))
|
2024-05-08 14:33:03 +00:00
|
|
|
}
|
2024-05-12 19:06:18 +00:00
|
|
|
test_glmer_ranef_D <- test_glmer_ranef_D |>
|
|
|
|
mutate(ranef_grouping = has_zero(estimate, conf.low, conf.high)) |>
|
|
|
|
mutate(rank = rank(estimate))
|
|
|
|
g <- test_glmer_ranef_D |>
|
|
|
|
ggplot(aes(x=rank, y=estimate, col = as.factor(ranef_grouping))) +
|
|
|
|
geom_linerange(aes(ymin= conf.low, ymax= conf.high)) +
|
2024-05-08 14:33:03 +00:00
|
|
|
theme_bw()
|
2024-05-12 19:06:18 +00:00
|
|
|
g
|
|
|
|
write.csv(test_glmer_ranef_D, "051224_contrib_grouped.csv")
|
2024-05-13 04:22:14 +00:00
|
|
|
#NOTE: The merge action model below this has not been used but this is what it would be if it was
|
2024-04-27 19:30:20 +00:00
|
|
|
mrg_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (week_offset | upstream_vcs_link), data=mrg_actions_data, REML=FALSE, control = lmerControl(
|
2024-04-25 01:55:56 +00:00
|
|
|
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
|
|
|
|
summary(mrg_model)
|
|
|
|
#identifying the quartiles of effect for D
|
2024-05-07 23:40:38 +00:00
|
|
|
mrg_model_ranef <- ranef(mrg_model)
|
|
|
|
dotplot(mrg_model_ranef)
|
2024-04-25 01:55:56 +00:00
|
|
|
d_effect_ranef_mrg <- mrg_model_ranef[mrg_model_ranef$term=="D",]
|
|
|
|
d_effect_ranef_mrg$quartile <- ntile(d_effect_ranef_mrg$condval, 4)
|
|
|
|
#merge model residuals
|
|
|
|
mrg_residuals <- residuals(mrg_model)
|
2024-05-07 23:40:38 +00:00
|
|
|
qqnorm(mrg_residuals)
|