diff --git a/R/.Rhistory b/R/.Rhistory index 90631e7..5426cf6 100644 --- a/R/.Rhistory +++ b/R/.Rhistory @@ -1,198 +1,3 @@ -hist(contrib_df$event_gap) -median(contrib_df$event_gap) -1786.431 / 265 -1786.431 / 365 -sd(contrib_df$event_gap) -sd(contrib_df$event_gap) -max(readme_df$event_gap) -#all_gmodel <- glmer.nb(log1p_count ~ D * week_offset + scaled_project_age + scaled_event_gap + (D * week_offset | upstream_vcs_link), -# control=glmerControl(optimizer="bobyqa", -# optCtrl=list(maxfun=2e5)), nAGQ=0, data=all_actions_data) -all_gmodel <- readRDS("0710_contrib_all.rda") -summary(all_gmodel) -library(tidyverse) -library(texreg) -readme_rdd <- readRDS("final_models/0624_readme_all_rdd.rda") -contrib_rdd <- readRDS("final_models/0710_contrib_all.rda") -contrib_rdd <- readRDS("final_models/0710_contrib_all_rdd.rda") -texreg(list(readme_rdd, contrib_rdd), stars=NULL, digits=3, use.packages=FALSE, -custom.model.names=c( 'README','CONTRIBUTING'), -custom.coef.names=c('(Intercept)', 'Indtroduction', 'Week (Time)', 'Project Age', 'Introduction:Week', 'Event Gap'), -table=FALSE, ci.force = TRUE) -source("~/Desktop/git/24_deb_gov/R/contribCrescAnalysis.R") -#all_gmodel <- readRDS("0710_contrib_all.rda") -summary(all_gmodel) -saveRDS(all_gmodel, "0710_contrib_cresc.rda") -range(all_actions_data$log1p_count) -source("~/Desktop/git/24_deb_gov/R/contribRDDAnalysis.R") -source("~/Desktop/git/24_deb_gov/R/contribRDDAnalysis.R") -all_gmodel <- readRDS("0711_contrib_all.rda") -summary(all_gmodel) -library(tidyverse) -library(texreg) -library(tidyverse) -library(texreg) -readme_rdd <- readRDS("final_models/0624_readme_all_rdd.rda") -contrib_rdd <- readRDS("final_models/0711_contrib_all_rdd.rda") -summary(readme_rdd) -texreg(list(readme_rdd, contrib_rdd), stars=NULL, digits=3, use.packages=FALSE, -custom.model.names=c( 'README','CONTRIBUTING'), -custom.coef.names=c('(Intercept)', 'Indtroduction', 'Week (Time)', 'Project Age', 'Introduction:Week', 'Event Gap'), -table=FALSE, ci.force = TRUE) -contrib_rdd <- readRDS("final_models/0711_contrib_all_rdd.rda") -contrib_rdd <- readRDS("final_models/0711_contrib_all_rdd.rda") -texreg(list(readme_rdd, contrib_rdd), stars=NULL, digits=3, use.packages=FALSE, -custom.model.names=c( 'README','CONTRIBUTING'), -custom.coef.names=c('(Intercept)', 'Indtroduction', 'Week (Time)', 'Project Age', 'Introduction:Week', 'Event Gap'), -table=FALSE, ci.force = TRUE) -texreg(list(readme_rdd, contrib_rdd), stars=NULL, digits=3, use.packages=FALSE, -custom.model.names=c( 'README','CONTRIBUTING'), -custom.coef.names=c('(Intercept)', 'Indtroduction', 'Week (Time)', 'Project Age', 'Introduction:Week'), -table=FALSE, ci.force = TRUE) -readme_groupings <- read.csv('../final_data/deb_readme_interaction_groupings.csv') -contrib_groupings <- read.csv('../final_data/0711_contrib_inter_groupings.csv') -subdirColors <- -setNames( c('firebrick1', 'forestgreen', 'cornflowerblue') -, c(0,1,2) ) -readme_g <- readme_groupings |> -ggplot(aes(x=rank, y=estimate, col = as.factor(ranef_grouping))) + -geom_linerange(aes(ymin= conf.low, ymax= conf.high)) + -scale_color_manual(values = subdirColors) + -guides(fill="none", color="none")+ -theme_bw() -readme_g -contrib_g <- contrib_groupings |> -ggplot(aes(x=rank, y=estimate, col = as.factor(ranef_grouping))) + -geom_linerange(aes(ymin= conf.low, ymax= conf.high)) + -scale_color_manual(values = subdirColors) + -theme_bw() + -theme(legend.position = "top") -contrib_g -library(gridExtra) -grid.arrange(contrib_g, readme_g, nrow = 1) -source("~/Desktop/git/24_deb_gov/R/contribRDDAnalysis.R") -source("~/Desktop/git/24_deb_gov/R/documentReadabilityAnalysis.R") -contrib_pop_df <- read_csv("../final_data/deb_contrib_pop_change.csv") -contrib_df <- read_csv("../final_data/deb_contrib_did.csv") -View(contrib_pop_df) -contrib_readability_df <- read_csv('../text_analysis/dwo_readability_contributing.csv') -View(contrib_readability_df) -View(contrib_pop_df) -View(contrib_readability_df) -View(contrib_pop_df) -View(contrib_readability_df) -View(contrib_pop_df) -View(contrib_pop_df) -View(contrib_df) -View(contrib_pop_df) -View(contrib_readability_df) -View(contrib_pop_df) -#concat dataframes into central data -contrib_df_total <- contrib_pop_df |> -mutate(project_name = str_split(upstream_vcs_link, pattern="/")[-1]) -View(contrib_pop_df) -View(contrib_readability_df) -View(contrib_readability_df) -contrib_df_total <- contrib_readability_df |> -mutate(project_name = str_split(filename, pattern="_")[-2]) -View(contrib_readability_df) -contrib_df_total <- contrib_readability_df |> -mutate(project_name = str_split(filename, pattern="_")) -View(contrib_df_total) -contrib_df_total <- contrib_readability_df |> -mutate(project_name = str_split(filename, pattern="_")[0]) -contrib_df_total <- contrib_readability_df |> -mutate(project_name = str_split(filename, pattern="_")[1]) -View(contrib_df_total) -contrib_df_total <- contrib_readability_df |> -mutate(project_name = str_split(filename, pattern="_")[1] |> -sapply("[[", 1)) -View(contrib_df_total) -contrib_df_total <- contrib_readability_df |> -mutate(project_name = str_split(filename, pattern="_")) -View(contrib_df_total) -contrib_df_total <- contrib_readability_df |> -mutate(project_name_array = str_split(filename, pattern="_")) |> -mutate(projes_name = project_name_array[1]) -View(contrib_df_total) -View(contrib_readability_df) -View(contrib_pop_df) -#concat dataframes into central data -contrib_pop_df <- contrib_pop_df %>% -mutate(first_element = map_chr(upstream_vcs_link, ~ { -parts <- str_split(.x, pattern = "/")[[1]] -if (length(parts) >= 1) { -parts[1] # Extract the first element after splitting -} else { -NA_character_ -} -})) -View(contrib_pop_df) -contrib_df_total <- contrib_readability_df |> -mutate(project_name = map_chr(filename, ~ { -parts <- str_split(.x, pattern = "_")[[1]] -if (length(parts) >= 1) { -parts[1] -} else { -NA_character_ -} -})) -contrib_df <- read_csv("../final_data/deb_contrib_did.csv") -contrib_pop_df <- read_csv("../final_data/deb_contrib_pop_change.csv") -contrib_readability_df <- read_csv('../text_analysis/dwo_readability_contributing.csv') -contrib_df_total <- contrib_readability_df |> -mutate(project_name = map_chr(filename, ~ { -parts <- str_split(.x, pattern = "_")[[1]] -if (length(parts) >= 1) { -parts[1] -} else { -NA_character_ -} -})) -View(contrib_df_total) -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[-1] -} else { -NA_character_ -} -})) -parts[length(parts)] -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_ -} -})) -View(contrib_pop_df) -source("~/Desktop/git/24_deb_gov/R/docChar_outcomes.R") -source("~/Desktop/git/24_deb_gov/R/docChar_outcomes.R") -contrib_total_df <- contrib_pop_df |> -left_join(contrib_readability_df, by="project_name") -View(contrib_total_df) -# test regressions -lm1 <- glm.nb(after_contrib_new ~ word_count, data = contrib_total_df) -# test regressions -library(MASS) -lm1 <- glm.nb(after_contrib_new ~ word_count, data = contrib_total_df) -summary(lm1) -View(contrib_total_df) -contrib_total_df <- contrib_pop_df |> -join(contrib_readability_df, by="project_name") -View(contrib_total_df) -View(contrib_readability_df) -qqnorm(residuals(lm1)) -source("~/Desktop/git/24_deb_gov/R/docChar_outcomes.R") -lm1 <- glm.nb(after_contrib_new ~ linsear_write, data = contrib_total_df) -lm1 <- glm.nb(after_contrib_new ~ linsear, data = contrib_total_df) -View(contrib_total_df) -lm1 <- glm.nb(after_contrib_new ~ linsear_write_formula, data = contrib_total_df) -qqnorm(residuals(lm1)) summary(lm1) lm1 <- glm.nb(after_contrib_new ~ reading_time, data = contrib_total_df) qqnorm(residuals(lm1)) @@ -510,3 +315,198 @@ summary(lm1) lm1 <- glm.nb(summed_count ~ reading_time + linsear_write_formula + flesch_reading_ease + mcalpine_eflaw + word_count, data = contrib_total_df) qqnorm(residuals(lm1)) summary(lm1) +contrib_topics_df <- read_csv("../text_analysis/contrib_file_topic_distributions.csv") +library(tidyverse) +contrib_topics_df <- read_csv("../text_analysis/contrib_file_topic_distributions.csv") +View(contrib_topics_df) +source("~/Desktop/git/24_deb_gov/R/contrib_topic_outcomes.R") +source("~/Desktop/git/24_deb_gov/R/contrib_topic_outcomes.R") +source("~/Desktop/git/24_deb_gov/R/contrib_docChar_outcomes.R") +source("~/Desktop/git/24_deb_gov/R/contrib_topic_outcomes.R") +source("~/Desktop/git/24_deb_gov/R/contrib_topic_outcomes.R") +source("~/Desktop/git/24_deb_gov/R/contrib_topic_outcomes.R") +lm1 <- glm.nb(summed_count ~ t0 + t1 + t2 + t3, data = contrib_total_df) +#running regressions +library(MASS) +lm1 <- glm.nb(summed_count ~ t0 + t1 + t2 + t3, data = contrib_total_df) +source("~/Desktop/git/24_deb_gov/R/contrib_topic_outcomes.R") +library(stringr) +library(plyr) +contrib_topics_df <- read_csv("../text_analysis/contrib_file_topic_distributions.csv") +contrib_df <- read_csv("../final_data/deb_contrib_did.csv") +contrib_pop_df <- read_csv("../final_data/deb_contrib_pop_change.csv") +#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_topic_df <- contrib_topic_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_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) +#running regressions +library(MASS) +lm1 <- glm.nb(summed_count ~ t0 + t1 + t2 + t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +View(contrib_total_df) +lm1 <- glm.nb(summed_count ~ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(summed_count ~ t3 + t2 + t1, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(summed_count ~ t3 + t2 + t1 + t0, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(summed_count ~ t0 + t1 + t2 + t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- lm(summed_count ~ t0 + t1 + t2 + t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(summed_count ~ t0 + t1 + t2 + t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(summed_count ~ t1 + t2 + t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(summed_count ~ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t1 + t2 +t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t2, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t1, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +source("~/Desktop/git/24_deb_gov/R/readme_topic_outcomes.R") +#outcome variable that is number of commits by number of new readmeutors +readme_total_df$commit_by_contrib = readme_total_df$summed_count *readme_total_df$after_contrib_new +readme_total_df$logged_outcome = log1p(readme_total_df$commit_by_readme) +#running regressions +library(MASS) +lm1 <- glm.nb(commit_by_readme ~ t3, data = readme_total_df) +lm1 <- glm.nb(commit_by_contrib ~ t3, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t1, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t7, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+t1+t7, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+t1+t2+t7, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+t1+t2+t7+t3, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+t1+t2+t7+t3 + t4, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+t1+t2+t7+t3 +t4 + t5 + t6, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+t1+t2+t7+t3 +t4 + t5, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +source("~/Desktop/git/24_deb_gov/R/contrib_topic_outcomes.R") +lm1 <- glm.nb(commit_by_contrib ~ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+ t1+ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t0+ t1+ t2+ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t1+ t2+ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t1+ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) +lm1 <- glm.nb(commit_by_contrib ~ t2+ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) diff --git a/R/contrib_topic_outcomes.R b/R/contrib_topic_outcomes.R new file mode 100644 index 0000000..fdc0c97 --- /dev/null +++ b/R/contrib_topic_outcomes.R @@ -0,0 +1,80 @@ + +library(stringr) +library(plyr) +contrib_topics_df <- read_csv("../text_analysis/contrib_file_topic_distributions.csv") +contrib_df <- read_csv("../final_data/deb_contrib_did.csv") +contrib_pop_df <- read_csv("../final_data/deb_contrib_pop_change.csv") + +#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) +#running regressions +library(MASS) +lm1 <- glm.nb(commit_by_contrib ~ t2+ t3, data = contrib_total_df) +qqnorm(residuals(lm1)) +summary(lm1) diff --git a/R/readme_docChar_outcomes.R b/R/readme_docChar_outcomes.R index b9451c9..bf2e4b8 100644 --- a/R/readme_docChar_outcomes.R +++ b/R/readme_docChar_outcomes.R @@ -99,3 +99,5 @@ library(MASS) lm1 <- glm.nb(logged_outcome~ reading_time + linsear_write_formula + flesch_reading_ease + mcalpine_eflaw + word_count, data = readme_total_df) qqnorm(residuals(lm1)) summary(lm1) + + diff --git a/R/readme_topic_outcomes.R b/R/readme_topic_outcomes.R new file mode 100644 index 0000000..1d1882d --- /dev/null +++ b/R/readme_topic_outcomes.R @@ -0,0 +1,80 @@ + +library(stringr) +library(plyr) +readme_topics_df <- read_csv("../text_analysis/readme_file_topic_distributions.csv") +readme_df <- read_csv("../final_data/deb_readme_did.csv") +readme_pop_df <- read_csv("../final_data/deb_readme_pop_change.csv") + +#get the readmeution 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") +readme_df <- readme_df[,col_order] +readme_df$ct_before_all <- str_split(gsub("[][]","", readme_df$before_all_ct), ", ") +readme_df$ct_after_all <- str_split(gsub("[][]","", readme_df$after_all_ct), ", ") +readme_df$ct_before_mrg <- str_split(gsub("[][]","", readme_df$before_mrg_ct), ", ") +readme_df$ct_after_mrg <- str_split(gsub("[][]","", readme_df$after_mrg_ct), ", ") +drop <- c("before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct") +readme_df = readme_df[,!(names(readme_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(readme_df[1,]) +for (i in 2:nrow(readme_df)){ + expanded_data <- rbind(expanded_data, expand_timeseries(readme_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 +readme_pop_df <- readme_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_ + } + })) + +readme_topics_df <- readme_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_ + } + })) + +readme_total_df <- readme_pop_df |> + join(readme_topics_df, by="project_name") + +readme_total_df <- readme_total_df|> + join(summed_data, by="upstream_vcs_link") + +#outcome variable that is number of commits by number of new readmeutors +readme_total_df$commit_by_contrib = readme_total_df$summed_count *readme_total_df$after_contrib_new +readme_total_df$logged_outcome = log1p(readme_total_df$commit_by_readme) +#running regressions +library(MASS) +lm1 <- glm.nb(commit_by_contrib ~ t0+t1+t2+t7+t3 +t4 + t5, data = readme_total_df) +qqnorm(residuals(lm1)) +summary(lm1)