95 lines
3.9 KiB
R
95 lines
3.9 KiB
R
|
|
library(stringr)
|
|
library(plyr)
|
|
contrib_topics_df <- read_csv("../text_analysis/contrib_file_topic_distributions.csv")
|
|
colMeans(subset(contrib_topics_df, select = -filename))
|
|
contrib_df <- read_csv("../final_data/deb_contrib_did.csv")
|
|
contrib_pop_df <- read_csv("../final_data/deb_contrib_pop_change.csv")
|
|
|
|
median(contrib_df$age_in_days)
|
|
|
|
#get the contribution count
|
|
#some preprocessing and expansion
|
|
col_order <- c("upstream_vcs_link", "age_in_days", "first_commit", "first_commit_dt", "event_gap", "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))
|
|
|
|
summed_data <- windowed_data |>
|
|
filter(D==1) |>
|
|
group_by(upstream_vcs_link) |>
|
|
summarise_at(vars(count), list(summed_count=sum))
|
|
|
|
#concat dataframes into central data
|
|
contrib_pop_df <- contrib_pop_df |>
|
|
mutate(project_name = map_chr(upstream_vcs_link, ~ {
|
|
parts <- str_split(.x, pattern = "/")[[1]]
|
|
if (length(parts) >= 1) {
|
|
parts[length(parts)]
|
|
} else {
|
|
NA_character_
|
|
}
|
|
}))
|
|
|
|
contrib_topics_df <- contrib_topics_df |>
|
|
mutate(project_name = map_chr(filename, ~ {
|
|
parts <- str_split(.x, pattern = "_")[[1]]
|
|
if (length(parts) >= 1) {
|
|
paste(head(parts, -1), collapse="_")
|
|
} else {
|
|
NA_character_
|
|
}
|
|
}))
|
|
|
|
contrib_total_df <- contrib_pop_df |>
|
|
join(contrib_topics_df, by="project_name")
|
|
|
|
contrib_total_df <- contrib_total_df|>
|
|
join(summed_data, by="upstream_vcs_link")
|
|
|
|
#outcome variable that is number of commits by number of new contributors
|
|
contrib_total_df$commit_by_contrib = contrib_total_df$summed_count * contrib_total_df$after_contrib_new
|
|
contrib_total_df$logged_outcome = log1p(contrib_total_df$commit_by_contrib)
|
|
contrib_total_df$logged_contrib = log1p(contrib_total_df$after_contrib_new)
|
|
contrib_total_df$logged_commits = log1p(contrib_total_df$summed_count)
|
|
#running regressions
|
|
library(MASS)
|
|
contrib_ <- glm.nb(logged_contrib ~ t0 + t1 + t2 + t3, data = contrib_total_df)
|
|
commits_ <- glm.nb(logged_commits ~ t0 + t1 + t2 + t3, data = contrib_total_df)
|
|
qqnorm(residuals(lm1))
|
|
summary(contrib_)
|
|
summary(commits_)
|
|
texreg(list(contrib_, commits_), stars=NULL, digits=3, use.packages=FALSE,
|
|
custom.model.names=c( 'Contributions','Commits'),
|
|
custom.coef.names=c('(Intercept)', 'Topic 1', 'Topic 2', 'Topic 3'),
|
|
table=FALSE, ci.force = TRUE)
|
|
|
|
saveRDS(commits_, "0731_topic_commitoutcome_contrib.rda")
|
|
saveRDS(contrib_, "0731_topic_contriboutcome_contrib.rda")
|