diff --git a/R/.Rhistory b/R/.Rhistory index a4c3e0d..18b8514 100644 --- a/R/.Rhistory +++ b/R/.Rhistory @@ -1,512 +1,512 @@ -# need to calculate inter-class correlation coefficient? -library(merTools) -ICC(outcome="count", group="upstream_vcs_link", data=all_actions_data) -ICC(outcome="count", group="week", data=all_actions_data) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 + D * I(week - 26) + age_of_project |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -describe(all_actions_data) -hist(all_actions_data$count) -mean(all_actions_data$count) -median(all_actions_data$count) -mean(all_actions_data$count) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1+week|upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1+D * I(week - 26)|upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1+ upstream_vcs_link|upstream_vcs_link), REML=FALSE, data=all_actions_data) -draft_all_model <- lmer(count ~ (1 | D * I(week - 26) + age_of_project) + (1 |upstream_vcs_link), REML=FALSE, data=all_actions_data) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 + I(week - 26) |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 + week |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 + I(week - 26) |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_all_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -draft_mrg_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), REML=FALSE, data=mrg_actions_data) -summary(draft_mrg_model) -draft_all_model <- lmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -flat_all_model <- lmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project, REML=FALSE, data=all_actions_data) -flat_all_model <- lm(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project, REML=FALSE, data=all_actions_data) -summary(flat_all_model) -draft_all_model <- lmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(draft_all_model) -#find some EDA to identify which types of models might be the best for this -mean(all_actions_data$count) -median(all_actions_data$count) -table(all_actions_data$count) -dist(all_actions_data$count) -var(all_actions_data$count) -sd(all_actions_data$count) -qqplot(all_actions_data$count, all_actions_data$week) -qqnorm(all_actions_data$count) -y <- qunif(ppoints(length(all_actions_data$count))) -qqplot(all_actions_data$count, y) -qqnorm(all_actions_data$count) -qqnorm(log(all_actions_data$count) -qqnorm(log(all_actions_data$count)) -qqnorm(log(all_actions_data$count)) -qqplot(log(all_actions_data$count), y) -qqnorm(all_actions_data$count) -qqnorm(root(all_actions_data$count)) -qqnorm(log(all_actions_data$count)) -qqplot(log(all_actions_data$count), y) -qqplot(all_actions_data$count, y) -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -summary(draft_all_model) -# Performance: -draft_mrg_model <- lmer(count ~ D * I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), REML=FALSE, data=mrg_actions_data) -summary(draft_mrg_model) -lmer_residuals <- residuals(lmer_all_model) -lmer_all_model <- lmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(lmer_all_model) -lmer_residuals <- residuals(lmer_all_model) -qqnorm(lmer_residuals) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -summary(poisson_all_model) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log"), nAGQ = 100) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -# this is the file with the lmer multi-level rddAnalysis -library(tidyverse) -library(plyr) -# 0 loading the readme data in -try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path))) -readme_df <- read_csv("../final_data/deb_readme_did.csv") -# 1 preprocessing -#colnames(readme_df) <- c("upstream_vcs_link", "event_date", "event_hash", "before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct", "before_auth_new", "after_commit_new", "after_auth_new", "before_commit_new") -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") -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 -expanded_data <- expanded_data |> -filter(week >= (26 - window_num) & week <= (26 + window_num)) |> -mutate(D = ifelse(week > 26, 1, 0)) -#separate out the cleaning d -all_actions_data <- expanded_data[which(expanded_data$observation_type == "all"),] -mrg_actions_data <- expanded_data[which(expanded_data$observation_type == "mrg"),] -#find some EDA to identify which types of models might be the best for this -mean(all_actions_data$count) -median(all_actions_data$count) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log"), nAGQ = 100) -summary(poisson_all_model) -# 3 rdd in lmer analysis -# rdd: https://rpubs.com/phle/r_tutorial_regression_discontinuity_design -# lmer: https://www.youtube.com/watch?v=LzAwEKrn2Mc -library(lme4) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log"), nAGQ = 100) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log"), nAGQ = 100) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + age_of_project + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scale(age_of_project) + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -qqnorm(poisson_residuals) -qqnorm(poisson_residuals) -#scale the age numbers -expanded_data$scaled_project_age <- scale(expanded_data$age_of_project) -#separate out the cleaning d -all_actions_data <- expanded_data[which(expanded_data$observation_type == "all"),] -mrg_actions_data <- expanded_data[which(expanded_data$observation_type == "mrg"),] -#find some EDA to identify which types of models might be the best for this -mean(all_actions_data$count) -median(all_actions_data$count) -table(all_actions_data$count) -var(all_actions_data$count) -qqnorm(all_actions_data$count) -y <- qunif(ppoints(length(all_actions_data$count))) -qqplot(all_actions_data$count, y) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -# this is the file with the lmer multi-level rddAnalysis -library(tidyverse) -library(plyr) -# 0 loading the readme data in -try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path))) -readme_df <- read_csv("../final_data/deb_readme_did.csv") -# 1 preprocessing -#colnames(readme_df) <- c("upstream_vcs_link", "event_date", "event_hash", "before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct", "before_auth_new", "after_commit_new", "after_auth_new", "before_commit_new") -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") -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") -# 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 -expanded_data <- expanded_data |> -filter(week >= (26 - window_num) & week <= (26 + window_num)) |> -mutate(D = ifelse(week > 26, 1, 0)) -# this is the file with the lmer multi-level rddAnalysis -library(tidyverse) -library(plyr) -# 0 loading the readme data in -try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path))) -readme_df <- read_csv("../final_data/deb_readme_did.csv") -# 1 preprocessing -#colnames(readme_df) <- c("upstream_vcs_link", "event_date", "event_hash", "before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct", "before_auth_new", "after_commit_new", "after_auth_new", "before_commit_new") -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") -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 >= (26 - window_num) & week <= (26 + window_num)) |> -mutate(D = ifelse(week > 26, 1, 0)) -#scale the age numbers -windowed_data$scaled_project_age <- scale(windowed_data$age_of_project) -#separate out the cleaning d -all_actions_data <- windowed_data[which(windowed_data$observation_type == "all"),] -mrg_actions_data <- windowed_data[which(windowed_data$observation_type == "mrg"),] -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -# 3 rdd in lmer analysis -# rdd: https://rpubs.com/phle/r_tutorial_regression_discontinuity_design -# lmer: https://www.youtube.com/watch?v=LzAwEKrn2Mc -library(lme4) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -#logistic regression mixed effects -log_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link),data=all_actions_data, family = binomial) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(scale(count) ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log"), control=glmerControl(optimizer="bobyqa")) -#logistic regression mixed effects -log_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link),data=all_actions_data, family = binomial) -qqnorm(poisson_residuals) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -#logistic regression mixed effects (doesn't work) -log_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + upstream_vcs_link |upstream_vcs_link),data=all_actions_data, family = binomial) -#logistic regression mixed effects (doesn't work) -log_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link),data=all_actions_data, family = binomial) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + upstream_vcs_link |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D ||upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -lmer_all_model <- lmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D ||upstream_vcs_link), REML=FALSE, data=all_actions_data) -summary(lmer_all_model) -lmer_residuals <- residuals(lmer_all_model) -qqnorm(lmer_residuals) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D ||upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -#if I'm reading the residuals right, the poisson is better? -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -# this is the file with the lmer multi-level rddAnalysis -library(tidyverse) -library(plyr) -# 0 loading the readme data in -try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path))) -readme_df <- read_csv("../final_data/deb_readme_did.csv") -# 1 preprocessing -#colnames(readme_df) <- c("upstream_vcs_link", "event_date", "event_hash", "before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct", "before_auth_new", "after_commit_new", "after_auth_new", "before_commit_new") -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") -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 >= (26 - window_num) & week <= (26 + window_num)) |> -mutate(D = ifelse(week > 26, 1, 0)) -#scale the age numbers -windowed_data$scaled_project_age <- scale(windowed_data$age_of_project) -#separate out the cleaning d -all_actions_data <- windowed_data[which(windowed_data$observation_type == "all"),] -mrg_actions_data <- windowed_data[which(windowed_data$observation_type == "mrg"),] -#if I'm reading the residuals right, the poisson is better? -# there's a conversation to be had between whether (D |upstream_vcs_link) or (D || upstream_vcs_link) -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_test_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_test_model) -summary(poisson_all_model) -summary(poisson_test_model) -poisson_test_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D ||upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_test_model) -summary(poisson_all_model) -summary(poisson_test_model) -summary(poisson_all_model) -summary(poisson_test_model) -poisson_testing_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 | upstream_vcs_link) + (0 + D |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_testing_model) -#| label: packages -#| echo: true -library(tidyverse) -library(tidytext) -library(textdata) -library(textstem) -library(tidymodels) -#| label: packages -#| echo: true -library(tidyverse) -library(tidytext) -library(textdata) -library(textstem) -library(tidymodels) -#| label: data 1 -#| echo: true -#| -reviews_df <- read_csv("data/rotten_tomatoes_critic_reviews.csv") -reviews_df |> head(2) |> kableExtra::kable() -summary(poisson_test_model) -summary(poisson_all_model) -summary(poisson_all_model) -summary(poisson_test_model) -#if I'm reading the residuals right, the poisson is better? -# there's a conversation to be had between whether (D |upstream_vcs_link) or (D || upstream_vcs_link) -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (week |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -poisson_test_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (week ||upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_test_model) -summary(poisson_all_model) -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (1 + week |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (week |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -ICC(outcome="count", group="week", data=all_actions_data) -library(merTools) -ICC(outcome="count", group="week", data=all_actions_data) -# this is the file with the lmer multi-level rddAnalysis -library(tidyverse) -library(plyr) -# 0 loading the readme data in -try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path))) -readme_df <- read_csv("../final_data/deb_readme_did.csv") -# 1 preprocessing -#colnames(readme_df) <- c("upstream_vcs_link", "event_date", "event_hash", "before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct", "before_auth_new", "after_commit_new", "after_auth_new", "before_commit_new") -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") -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 >= (26 - window_num) & week <= (26 + window_num)) |> -mutate(D = ifelse(week > 26, 1, 0)) -#scale the age numbers -windowed_data$scaled_project_age <- scale(windowed_data$age_of_project) -#separate out the cleaning d -all_actions_data <- windowed_data[which(windowed_data$observation_type == "all"),] -mrg_actions_data <- windowed_data[which(windowed_data$observation_type == "mrg"),] -# for visualization, may have to run model for each project and then identify top 5 projects for RDD graphs -# -# -poisson_mrg_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (week |upstream_vcs_link), data=mrg_actions_data, family = poisson(link = "log")) -summary(poisson_mrg_model) -poisson_mrg_residuals <- residuals(poisson_mrg_model) -qqnorm(poisson_mrg_residuals) -# this is the file with the lmer multi-level rddAnalysis -library(tidyverse) -library(plyr) -# 0 loading the readme data in -try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path))) -readme_df <- read_csv("../final_data/deb_readme_did.csv") -# 1 preprocessing -#colnames(readme_df) <- c("upstream_vcs_link", "event_date", "event_hash", "before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct", "before_auth_new", "after_commit_new", "after_auth_new", "before_commit_new") -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") -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 >= (26 - window_num) & week <= (26 + window_num)) |> -mutate(D = ifelse(week > 26, 1, 0)) -#scale the age numbers -windowed_data$scaled_project_age <- scale(windowed_data$age_of_project) -#separate out the cleaning d -all_actions_data <- windowed_data[which(windowed_data$observation_type == "all"),] -mrg_actions_data <- windowed_data[which(windowed_data$observation_type == "mrg"),] -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -# (1 |upstream_vcs_link) or (week | upstream_vcs_link) -poisson_all_model <- glmer(count ~ (D + I(week - 26) + D:I(week - 26) + scaled_project_age | upstream_vcs_link) + (1 |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -# 3 rdd in lmer analysis -# rdd: https://rpubs.com/phle/r_tutorial_regression_discontinuity_design -# lmer: https://www.youtube.com/watch?v=LzAwEKrn2Mc -library(lme4) -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -# (1 |upstream_vcs_link) or (week | upstream_vcs_link) -poisson_all_model <- glmer(count ~ (D + I(week - 26) + D:I(week - 26) + scaled_project_age | upstream_vcs_link) + (1 |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -# (1 |upstream_vcs_link) or (week | upstream_vcs_link) -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D + I(week - 26) + D:I(week - 26) + scaled_project_age | upstream_vcs_link) + (1 |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar -# (1 |upstream_vcs_link) or (week | upstream_vcs_link) -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (D | upstream_vcs_link) + (1 |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) +p # https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar # (D |upstream_vcs_link) or (week | upstream_vcs_link) -poisson_all_model <- glmer(count ~ D + I(week - 26) + D:I(week - 26) + scaled_project_age + (week | upstream_vcs_link) + (1 |upstream_vcs_link), data=all_actions_data, family = poisson(link = "log")) -summary(poisson_all_model) -poisson_residuals <- residuals(poisson_all_model) -qqnorm(poisson_residuals) +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset) |upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D |upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 8), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (26 - window_num) & week <= (26 + window_num)) |> +mutate(D = ifelse(week > 26, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 26 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (week_offset|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +guides(fill="none") + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme(legend.position="none") + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link)) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw(legend.position="none") +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw(legend.position="none") +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link)) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (26 - window_num) & week <= (26 + window_num)) |> +mutate(D = ifelse(week > 26, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 26 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (week_offset|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (week_offset|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +## +all_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE) +summary(all_model) +## +all_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (week_offset| upstream_vcs_link), data=all_actions_data, REML=FALSE) +summary(all_model) +## +all_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE) +summary(all_model) +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +# this is the file with the lmer multi-level rddAnalysis +library(tidyverse) +library(plyr) +# 0 loading the readme data in +try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path))) +readme_df <- read_csv("../final_data/deb_readme_did.csv") +# 1 preprocessing +#colnames(readme_df) <- c("upstream_vcs_link", "event_date", "event_hash", "before_all_ct", "before_mrg_ct", "after_all_ct", "after_mrg_ct", "before_auth_new", "after_commit_new", "after_auth_new", "before_commit_new") +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") +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)) +#scale the age numbers +windowed_data$scaled_project_age <- scale(windowed_data$age_of_project) +windowed_data$week_offset <- windowed_data$week - 27 +#separate out the cleaning d +all_actions_data <- windowed_data[which(windowed_data$observation_type == "all"),] +mrg_actions_data <- windowed_data[which(windowed_data$observation_type == "mrg"),] +# 3 rdd in lmer analysis +# rdd: https://rpubs.com/phle/r_tutorial_regression_discontinuity_design +# lmer: https://www.youtube.com/watch?v=LzAwEKrn2Mc +library(lme4) +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +## +all_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE) +summary(all_model) +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (week_offset|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (week_offset|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), group=upstream_vcs_link), show.legend = FALSE) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +# for visualization, may have to run model for each project and then identify top 5 projects for RDD graphs +mrg_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=mrg_actions_data, REML=FALSE) +summary(mrg_model) +summary(all_model) +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)||upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=mean(predict(test_model)), show.legend = FALSE)) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model), show.legend = FALSE)) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=mean(predict(test_model))), show.legend = FALSE) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=median(predict(test_model))), show.legend = FALSE) + +theme_bw() +p +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset) + scaled_project_age|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 22), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar +#making some random data +sampled_data <- readme_df[sample(nrow(readme_df), 220), ] +expanded_sample_data <- expand_timeseries(sampled_data[1,]) +for (i in 2:nrow(sampled_data)){ +expanded_sample_data <- rbind(expanded_sample_data, expand_timeseries(sampled_data[i,])) +} +windowed_sample_data <- expanded_sample_data |> +filter(week >= (27 - window_num) & week <= (27 + window_num)) |> +mutate(D = ifelse(week > 27, 1, 0)) +windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) +windowed_sample_data$week_offset <- windowed_sample_data$week - 27 +all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +#test model +test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +summary(test_model) +#plot results +p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + +geom_point(size=3, show.legend = FALSE) + +geom_line(aes(y=predict(test_model)), show.legend = FALSE) + +theme_bw() +p +summary(all_model) +all_residuals <- residuals(all_model) +qqnorm(all_residuals) +mrg_residuals <- residuals(mrg_model) +qqnorm(mrg_residuals) +summary(all_model) +##end of the model testing and plotting section +all_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=TRUE) +summary(all_model) +##end of the model testing and plotting section +all_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE) +summary(all_model) diff --git a/R/readmeRDDAnalysis.R b/R/readmeRDDAnalysis.R index bde791e..84200e5 100644 --- a/R/readmeRDDAnalysis.R +++ b/R/readmeRDDAnalysis.R @@ -43,13 +43,15 @@ windowed_data$week_offset <- windowed_data$week - 27 all_actions_data <- windowed_data[which(windowed_data$observation_type == "all"),] mrg_actions_data <- windowed_data[which(windowed_data$observation_type == "mrg"),] #find some EDA to identify which types of models might be the best for this -mean(all_actions_data$count) +hist(log(all_actions_data$count)) median(all_actions_data$count) table(all_actions_data$count) var(all_actions_data$count) qqnorm(all_actions_data$count) y <- qunif(ppoints(length(all_actions_data$count))) qqplot(all_actions_data$count, y) +all_actions_data$logged_count <- log(all_actions_data$count) +all_actions_data$log1p_count <- log1p(all_actions_data$count) # 3 rdd in lmer analysis # rdd: https://rpubs.com/phle/r_tutorial_regression_discontinuity_design # lmer: https://www.youtube.com/watch?v=LzAwEKrn2Mc @@ -67,8 +69,9 @@ windowed_sample_data <- expanded_sample_data |> windowed_sample_data$scaled_project_age <- scale(windowed_sample_data$age_of_project) windowed_sample_data$week_offset <- windowed_sample_data$week - 27 all_actions_sample_data <- windowed_sample_data[which(windowed_sample_data$observation_type == "all"),] +all_actions_sample_data$log1p_count <- log1p(all_actions_sample_data$count) #test model -test_model <- lmer(count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) +test_model <- lmer(log1p_count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link), data=all_actions_sample_data, REML=FALSE) summary(test_model) #plot results p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_vcs_link), show.legend = FALSE) + @@ -77,7 +80,7 @@ p <- ggplot(all_actions_sample_data, aes(x=week_offset, y=count, color=upstream_ theme_bw() p ##end of the model testing and plotting section -all_model <- lmer(count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE) +all_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE) summary(all_model) all_residuals <- residuals(all_model) qqnorm(all_residuals) @@ -87,7 +90,6 @@ summary(mrg_model) mrg_residuals <- residuals(mrg_model) qqnorm(mrg_residuals) # Performance: - library(merTools) ICC(outcome="count", group="week", data=all_actions_data) #testing for different types of models