updating rdd scripts w pop level
This commit is contained in:
		
							parent
							
								
									1184069921
								
							
						
					
					
						commit
						c8313a904f
					
				
							
								
								
									
										806
									
								
								R/.Rhistory
									
									
									
									
									
								
							
							
						
						
									
										806
									
								
								R/.Rhistory
									
									
									
									
									
								
							@ -1,233 +1,11 @@
 | 
			
		||||
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)
 | 
			
		||||
library(ggplot2)
 | 
			
		||||
data1 <- read_csv('../power_data_111023_mmt.csv',show_col_types = FALSE)
 | 
			
		||||
data2 <- read_csv('../inst_all_packages_full_results.csv')
 | 
			
		||||
data1 <- read_csv('../kk_final_expanded_data_final.csv',show_col_types = FALSE)
 | 
			
		||||
library(readr)
 | 
			
		||||
library(ggplot2)
 | 
			
		||||
library(tidyverse)
 | 
			
		||||
data1 <- read_csv('../kk_final_expanded_data_final.csv',show_col_types = FALSE)
 | 
			
		||||
# this is the file with the lmer multi-level rddAnalysis
 | 
			
		||||
library(tidyverse)
 | 
			
		||||
library(plyr)
 | 
			
		||||
@ -272,155 +50,200 @@ 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"),]
 | 
			
		||||
#find some EDA to identify which types of models might be the best for this
 | 
			
		||||
hist(all_actions_data$count)
 | 
			
		||||
#find some EDA to identify which types of models might be the best for this
 | 
			
		||||
hist(log1p(all_actions_data$count))
 | 
			
		||||
#find some EDA to identify which types of models might be the best for this
 | 
			
		||||
hist(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
 | 
			
		||||
library(lme4)
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
all_model <- lmer(log(count) ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE)
 | 
			
		||||
all_actions_data$logged_count <- log(all_actions_data$count)
 | 
			
		||||
all_actions_data$log1p_count <- log1p(all_actions_data$count)
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
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)
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
all_model <- lmer(logged_count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE)
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
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)
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
all_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (week_offset| upstream_vcs_link), data=all_actions_data, REML=FALSE)
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
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)
 | 
			
		||||
# 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(log1p_count ~ D * I(week_offset) + scaled_project_age + (D * I(week_offset)|upstream_vcs_link),  data=all_actions_sample_data, REML=FALSE)
 | 
			
		||||
all_actions_sample_data$log1p_count <- log1p(all_actions_sample_data$count)
 | 
			
		||||
#test model
 | 
			
		||||
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) +
 | 
			
		||||
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=predict(test_model)), show.legend = FALSE) +
 | 
			
		||||
theme_bw()
 | 
			
		||||
p
 | 
			
		||||
library(merTools)
 | 
			
		||||
ICC(outcome="count", group="week", data=all_actions_data)
 | 
			
		||||
ICC(outcome="count", group="upstream_vcs_link", data=all_actions_data)
 | 
			
		||||
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 >= (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"),]
 | 
			
		||||
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
 | 
			
		||||
library(lme4)
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
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)
 | 
			
		||||
(
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
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, control = lmerControl(optimizer ="Nelder_Mead"))
 | 
			
		||||
##end of the model testing and plotting section
 | 
			
		||||
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, control = lmerControl(optimizer ="Nelder_Mead"))
 | 
			
		||||
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, control = lmerControl(optimizer="optimx",
 | 
			
		||||
optCtrl=list(method="nlminb")))
 | 
			
		||||
library(optimx)
 | 
			
		||||
library(lattice)
 | 
			
		||||
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, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(all_model)
 | 
			
		||||
all0_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(all0_model)
 | 
			
		||||
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, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
all_model.ranef <- ranef(all_model)
 | 
			
		||||
str(all_model.ranef)
 | 
			
		||||
head(all_model.ranef)
 | 
			
		||||
all_actions_data$D_effect_quart <- ntile(all_model.ranef$D, 4)
 | 
			
		||||
head(all_model.ranef)
 | 
			
		||||
all_model.ranef <- random.effects(all_model)
 | 
			
		||||
head(as.data.frame(all_model.ranef))
 | 
			
		||||
head(all_model_ranef)
 | 
			
		||||
all_model_ranef <- as.data.frame(ranef(all_model))
 | 
			
		||||
head(all_model_ranef)
 | 
			
		||||
d_effect_ranef_all <- subset(all_model_ranef, term="D")
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef[all_model_ranef$term="D",]
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- as.data.frame(ranef(all_model, condVar=TRUE))
 | 
			
		||||
View(all_model_ranef)
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef[all_model_ranef$term=="D",]
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef[all_model_ranef$term=="D",]
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef['upstream_vcs_link']['D']
 | 
			
		||||
View(all_model_ranef)
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef[upstream_vcs_link,2]
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef['upstream_vcs_link',2]
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef$upstream_vcs_link
 | 
			
		||||
View(d_effect_ranef_all)
 | 
			
		||||
d_effect_ranef_all$quartile <- ntile(d_effect_ranef_all$condval, 4)
 | 
			
		||||
View(d_effect_ranef_all)
 | 
			
		||||
# mrg behavior for this
 | 
			
		||||
mrg_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE, control = lmerControl(
 | 
			
		||||
dotplot(all_model_ranef)[["D"]]
 | 
			
		||||
dotplot(all_model_ranef)[["upstream_vcs_link"]]
 | 
			
		||||
dotplot(all_model_ranef)[["upstream_vcs_link"]["D"]]
 | 
			
		||||
dotplot(all_model_ranef)$D
 | 
			
		||||
View(all_model_ranef)
 | 
			
		||||
for (j in 1:nschool) {
 | 
			
		||||
jj <- order(all_model_ranef)[j]
 | 
			
		||||
lines (x=c(j,j),y=c(ranef.lower[jj],ranef.upper[jj]))
 | 
			
		||||
}
 | 
			
		||||
for (j in 1:upstream_vcs_link) {
 | 
			
		||||
jj <- order(all_model_ranef)[j]
 | 
			
		||||
lines (x=c(j,j),y=c(ranef.lower[jj],ranef.upper[jj]))
 | 
			
		||||
}
 | 
			
		||||
View(all_model_ranef)
 | 
			
		||||
df_ranefs <- as.data.frame(all_model_ranef)
 | 
			
		||||
View(df_ranefs)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)$upstream_vcs_link[[2]]
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)$upstream_vcs_link
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
# 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"),]
 | 
			
		||||
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
 | 
			
		||||
library(lme4)
 | 
			
		||||
# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar
 | 
			
		||||
library(optimx)
 | 
			
		||||
library(lattice)
 | 
			
		||||
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, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(mrg_model)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
dotplot(all_model_ranef)$g[1]
 | 
			
		||||
re <- ranef(all_model,postVar = TRUE)
 | 
			
		||||
re$g$'(Intercept)' <- NULL
 | 
			
		||||
re$g$'D:I(week_offset)' <- NULL
 | 
			
		||||
re <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
re$g$'(Intercept)' <- NULL
 | 
			
		||||
re$g$'D:I(week_offset)' <- NULL
 | 
			
		||||
dotplot(re)
 | 
			
		||||
dotplot(re)
 | 
			
		||||
re <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
re$upstream_vcs_link$'(Intercept)' <- NULL
 | 
			
		||||
re$upstream_vcs_link$'D:I(week_offset)' <- NULL
 | 
			
		||||
View(re)
 | 
			
		||||
re$upstream_vcs_link$'I(week_offset)' <- NULL
 | 
			
		||||
dotplot(re)
 | 
			
		||||
View(re)
 | 
			
		||||
View(all_model_ranef)
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
re <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
re$upstream_vcs_link$'(Intercept)' <- NULL
 | 
			
		||||
re$upstream_vcs_link$'D:I(week_offset)' <- NULL
 | 
			
		||||
re$upstream_vcs_link$'I(week_offset)' <- NULL
 | 
			
		||||
dotplot(re)
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
# 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"),]
 | 
			
		||||
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
 | 
			
		||||
library(lme4)
 | 
			
		||||
# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar
 | 
			
		||||
library(optimx)
 | 
			
		||||
library(lattice)
 | 
			
		||||
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, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(all_model)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
df_ranefs <- as.data.frame(all_model_ranef)
 | 
			
		||||
View(df_ranefs)
 | 
			
		||||
D_df_ranef <- df_ranefs[term == "D"]
 | 
			
		||||
D_df_ranef <- df_ranefs[df_ranefs$term == "D"]
 | 
			
		||||
library(tidyverse)
 | 
			
		||||
library(plyr)
 | 
			
		||||
#get the contrib data instead
 | 
			
		||||
@ -464,49 +287,226 @@ 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"),]
 | 
			
		||||
#EDA?
 | 
			
		||||
hist(log(all_actions_data$count))
 | 
			
		||||
all_actions_data$logged_count <- log(all_actions_data$count)
 | 
			
		||||
all_actions_data$log1p_count <- log1p(all_actions_data$count)
 | 
			
		||||
# now for merge
 | 
			
		||||
mrg_actions_data$logged_count <- log(mrg_actions_data$count)
 | 
			
		||||
mrg_actions_data$log1p_count <- log1p(mrg_actions_data$count)
 | 
			
		||||
#TKTK ---------------------
 | 
			
		||||
#imports for models
 | 
			
		||||
library(lme4)
 | 
			
		||||
library(optimx)
 | 
			
		||||
#models -- TKTK need to be fixed
 | 
			
		||||
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, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
#EDA?
 | 
			
		||||
hist(log(all_actions_data$count))
 | 
			
		||||
all_actions_data$logged_count <- log(all_actions_data$count)
 | 
			
		||||
all_actions_data$log1p_count <- log1p(all_actions_data$count)
 | 
			
		||||
#models -- TKTK need to be fixed
 | 
			
		||||
all_model <- lmer(logged_count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
#models -- TKTK need to be fixed
 | 
			
		||||
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, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(all_model)
 | 
			
		||||
library(lattice)
 | 
			
		||||
#models -- TKTK need to be fixed
 | 
			
		||||
all_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (week_offset| upstream_vcs_link), data=all_actions_data, REML=FALSE, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(all_model)
 | 
			
		||||
#models -- TKTK need to be fixed
 | 
			
		||||
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)
 | 
			
		||||
week_offset
 | 
			
		||||
#models -- TKTK need to be fixed
 | 
			
		||||
all_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (week_offset| upstream_vcs_link), data=all_actions_data, REML=FALSE, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(all_model)
 | 
			
		||||
# mrg behavior for this
 | 
			
		||||
mrg_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (D * I(week_offset)| upstream_vcs_link), data=all_actions_data, REML=FALSE, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
# mrg behavior for this
 | 
			
		||||
mrg_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (week_offset | upstream_vcs_link), data=all_actions_data, REML=FALSE, control = lmerControl(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(mrg_model)
 | 
			
		||||
# mrg behavior for this
 | 
			
		||||
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(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
# now for merge
 | 
			
		||||
mrg_actions_data$logged_count <- log(mrg_actions_data$count)
 | 
			
		||||
mrg_actions_data$log1p_count <- log1p(mrg_actions_data$count)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- as.data.frame(ranef(all_model))
 | 
			
		||||
View(all_model_ranef)
 | 
			
		||||
# mrg behavior for this
 | 
			
		||||
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(
 | 
			
		||||
optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(mrg_model)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
mrg_model_ranef <- ranef(mrg_model)
 | 
			
		||||
View(mrg_model_ranef)
 | 
			
		||||
dotplot(mrg_model_ranef)
 | 
			
		||||
#load in data
 | 
			
		||||
contrib_df <- read_csv("../final_data/deb_contrib_pop_change.csv")
 | 
			
		||||
readme_df <- read_csv("../final_data/deb_readme_pop_change.csv")
 | 
			
		||||
View(readme_df)
 | 
			
		||||
#some expansion needs to happens for each project
 | 
			
		||||
expand_timeseries <- function(project_row) {
 | 
			
		||||
longer <- project_row |>
 | 
			
		||||
pivot_longer(cols = ends_with("new"),
 | 
			
		||||
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,])
 | 
			
		||||
View(expand_timeseries)
 | 
			
		||||
View(expanded_data)
 | 
			
		||||
longer <- project_row |>
 | 
			
		||||
pivot_longer(cols = ends_with("new"),
 | 
			
		||||
names_to = "window",
 | 
			
		||||
values_to = "count") |>
 | 
			
		||||
unnest(count) |>
 | 
			
		||||
mutate(after_doc = str_detect(window, "after"))
 | 
			
		||||
#some expansion needs to happens for each project
 | 
			
		||||
expand_timeseries <- function(project_row) {
 | 
			
		||||
longer <- project_row |>
 | 
			
		||||
pivot_longer(cols = ends_with("new"),
 | 
			
		||||
names_to = "window",
 | 
			
		||||
values_to = "count") |>
 | 
			
		||||
unnest(count) |>
 | 
			
		||||
mutate(after_doc = str_detect(window, "after"))
 | 
			
		||||
return(longer)
 | 
			
		||||
}
 | 
			
		||||
expanded_data <- expand_timeseries(readme_df[1,])
 | 
			
		||||
longer <- project_row |>
 | 
			
		||||
pivot_longer(cols = ends_with("new"),
 | 
			
		||||
names_to = "window",
 | 
			
		||||
values_to = "count") |>
 | 
			
		||||
unnest(count) |>
 | 
			
		||||
mutate(after_doc = as.numeric(str_detect(window, "after")))
 | 
			
		||||
return(longer)
 | 
			
		||||
#some expansion needs to happens for each project
 | 
			
		||||
expand_timeseries <- function(project_row) {
 | 
			
		||||
longer <- project_row |>
 | 
			
		||||
pivot_longer(cols = ends_with("new"),
 | 
			
		||||
names_to = "window",
 | 
			
		||||
values_to = "count") |>
 | 
			
		||||
unnest(count) |>
 | 
			
		||||
mutate(after_doc = as.numeric(str_detect(window, "after")))
 | 
			
		||||
return(longer)
 | 
			
		||||
}
 | 
			
		||||
expanded_data <- expand_timeseries(readme_df[1,])
 | 
			
		||||
#some expansion needs to happens for each project
 | 
			
		||||
expand_timeseries <- function(project_row) {
 | 
			
		||||
longer <- project_row |>
 | 
			
		||||
pivot_longer(cols = ends_with("new"),
 | 
			
		||||
names_to = "window",
 | 
			
		||||
values_to = "count") |>
 | 
			
		||||
unnest(count) |>
 | 
			
		||||
mutate(after_doc = as.numeric(str_detect(window, "after"))) |>
 | 
			
		||||
mutate(is_collab = as.numeric(str_detect(window, "collab")))
 | 
			
		||||
return(longer)
 | 
			
		||||
}
 | 
			
		||||
expanded_data <- expand_timeseries(readme_df[1,])
 | 
			
		||||
for (i in 2:nrow(readme_df)){
 | 
			
		||||
expanded_readme_data <- rbind(expanded_readme_data, expand_timeseries(readme_df[i,]))
 | 
			
		||||
}
 | 
			
		||||
expanded_readme_data <- expand_timeseries(readme_df[1,])
 | 
			
		||||
for (i in 2:nrow(readme_df)){
 | 
			
		||||
expanded_readme_data <- rbind(expanded_readme_data, expand_timeseries(readme_df[i,]))
 | 
			
		||||
}
 | 
			
		||||
expanded_contrib_data <- expand_timeseries(contrib_df[1,])
 | 
			
		||||
for (i in 2:nrow(contrib_df)){
 | 
			
		||||
expanded_contrib_data <- rbind(expanded_contrib_data, expand_timeseries(contrib_df[i,]))
 | 
			
		||||
}
 | 
			
		||||
View(expanded_contrib_data)
 | 
			
		||||
readme_model <- lmer(count ~ after_doc + (1| upstream_vcs_link), data=expanded_readme_data, REML=FALSE)
 | 
			
		||||
summary(readme_model)
 | 
			
		||||
readme_model <- lmer(count ~ after_doc + ( after_doc | upstream_vcs_link), data=expanded_readme_data, REML=FALSE)
 | 
			
		||||
summary(readme_model)
 | 
			
		||||
contrib_model <- lmer(count ~ after_doc + ( after_doc | upstream_vcs_link), data=expanded_contrib_data, REML=FALSE)
 | 
			
		||||
summary(contrib_model)
 | 
			
		||||
collab_readme_model <- lmer(count ~ after_doc + ( after_doc | upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
#breaking out the types of population counts
 | 
			
		||||
collab_pop_readme <- expanded_readme_data[which(expanded_readme_data$is_collab == 1),]
 | 
			
		||||
contrib_pop_readme <- expanded_readme_data[which(expanded_readme_data$is_collab == 0),]
 | 
			
		||||
collab_pop_contrib <- expanded_contrib_data[which(expanded_contrib_data$is_collab == 1),]
 | 
			
		||||
contrib_pop_contrib <- expanded_contrib_data[which(expanded_contrib_data$is_collab == 0),]
 | 
			
		||||
collab_readme_model <- lmer(count ~ after_doc + ( after_doc | upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
collab_readme_model <- lmer(count ~ after_doc + (1| upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
summary(collab_readme_model)
 | 
			
		||||
contrib_readme_model <- lmer(count ~ after_doc + ( 1| upstream_vcs_link), data=contrib_pop_readme, REML=FALSE)
 | 
			
		||||
summary(contrib_readme_model)
 | 
			
		||||
collab_readme_model <- lmer(count ~ after_doc + (after_doc| upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
collab_readme_model <- lmer(count ~ after_doc + (1| upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
summary(collab_readme_model)
 | 
			
		||||
contrib_readme_model <- lmer(count ~ after_doc + ( 1| upstream_vcs_link), data=contrib_pop_readme, REML=FALSE)
 | 
			
		||||
summary(contrib_readme_model)
 | 
			
		||||
collab_contrib_model <- lmer(count ~ after_doc + ( 1 | upstream_vcs_link), data=collab_pop_contrib, REML=FALSE)
 | 
			
		||||
summary(collab_contrib_model)
 | 
			
		||||
contrib_contrib_model <- lmer(count ~ after_doc + ( 1 | upstream_vcs_link), data=contrib_pop_contrib, REML=FALSE)
 | 
			
		||||
summary(contrib_contrib_model)
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = count, col = is_collab)) +
 | 
			
		||||
geom_point()
 | 
			
		||||
ggplot(aes(x = after_doc, y = count, col = as.factor(is_collab)) +
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = count, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point()
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = count, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point()
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = as.factor(after_doc), y = count, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point()
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = as.factor(after_doc), y = scale(count), col = as.factor(is_collab))) +
 | 
			
		||||
geom_point()
 | 
			
		||||
expanded_readme_data$log1pcount <- log1p(expanded_readme_data$count)
 | 
			
		||||
expanded_contrib_data$log1pcount <- log1p(expanded_contrib_data$count)
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = as.factor(after_doc), y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point()
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = as.factor(after_doc), y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F)
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F)
 | 
			
		||||
expanded_contrib_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F)
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = count, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
expanded_readme_data$logcount <- log(expanded_readme_data$count)
 | 
			
		||||
expanded_contrib_data$logcount <- log(expanded_contrib_data$count)
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = logcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
expanded_contrib_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F)
 | 
			
		||||
expanded_contrib_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
expanded_contrib_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = count, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = logcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
collab_readme_model <- lmer(logcount ~ after_doc + (1| upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
#breaking out the types of population counts
 | 
			
		||||
collab_pop_readme <- expanded_readme_data[which(expanded_readme_data$is_collab == 1),]
 | 
			
		||||
contrib_pop_readme <- expanded_readme_data[which(expanded_readme_data$is_collab == 0),]
 | 
			
		||||
collab_pop_contrib <- expanded_contrib_data[which(expanded_contrib_data$is_collab == 1),]
 | 
			
		||||
contrib_pop_contrib <- expanded_contrib_data[which(expanded_contrib_data$is_collab == 0),]
 | 
			
		||||
collab_readme_model <- lmer(logcount ~ after_doc + (1| upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
collab_readme_model <- lmer(log1pcount ~ after_doc + (1| upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
summary(collab_readme_model)
 | 
			
		||||
contrib_readme_model <- lmer(log1pcount ~ after_doc + ( 1| upstream_vcs_link), data=contrib_pop_readme, REML=FALSE)
 | 
			
		||||
summary(contrib_readme_model)
 | 
			
		||||
collab_contrib_model <- lmer(log1pcount ~ after_doc + ( 1 | upstream_vcs_link), data=collab_pop_contrib, REML=FALSE)
 | 
			
		||||
summary(collab_contrib_model)
 | 
			
		||||
contrib_contrib_model <- lmer(log1pcount ~ after_doc + ( 1 | upstream_vcs_link), data=contrib_pop_contrib, REML=FALSE)
 | 
			
		||||
summary(contrib_contrib_model)
 | 
			
		||||
library(ggplot2)
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = logcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
expanded_contrib_data |>
 | 
			
		||||
ggplot(aes(x = after_doc, y = count, col = as.factor(is_collab))) +
 | 
			
		||||
geom_point() +
 | 
			
		||||
geom_smooth(method = 'lm', se = F) + geom_jitter()
 | 
			
		||||
 | 
			
		||||
@ -51,12 +51,13 @@ mrg_actions_data$log1p_count <- log1p(mrg_actions_data$count)
 | 
			
		||||
#imports for models 
 | 
			
		||||
library(lme4)
 | 
			
		||||
library(optimx)
 | 
			
		||||
library(lattice)
 | 
			
		||||
#models -- TKTK need to be fixed
 | 
			
		||||
all_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (week_offset| upstream_vcs_link), data=all_actions_data, REML=FALSE, control = lmerControl(
 | 
			
		||||
  optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(all_model)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- as.data.frame(ranef(all_model))
 | 
			
		||||
all_model_ranef <- ranef(all_model)
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef[all_model_ranef$term=="D",]
 | 
			
		||||
d_effect_ranef_all$quartile <- ntile(d_effect_ranef_all$condval, 4)
 | 
			
		||||
#model residuals
 | 
			
		||||
@ -67,12 +68,10 @@ mrg_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (week_o
 | 
			
		||||
  optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(mrg_model)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
mrg_model_ranef <- as.data.frame(ranef(mrg_model))
 | 
			
		||||
mrg_model_ranef <- ranef(mrg_model)
 | 
			
		||||
dotplot(mrg_model_ranef)
 | 
			
		||||
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)
 | 
			
		||||
qqnorm(mrg_residuals)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										55
									
								
								R/popRDDAnalyssis.R
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								R/popRDDAnalyssis.R
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,55 @@
 | 
			
		||||
library(tidyverse)
 | 
			
		||||
library(plyr) 
 | 
			
		||||
library(stringr)
 | 
			
		||||
try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path)))
 | 
			
		||||
#load in data
 | 
			
		||||
contrib_df <- read_csv("../final_data/deb_contrib_pop_change.csv")
 | 
			
		||||
readme_df <- read_csv("../final_data/deb_readme_pop_change.csv")
 | 
			
		||||
#some expansion needs to happens for each project 
 | 
			
		||||
expand_timeseries <- function(project_row) {
 | 
			
		||||
  longer <- project_row |> 
 | 
			
		||||
    pivot_longer(cols = ends_with("new"),
 | 
			
		||||
                 names_to = "window",
 | 
			
		||||
                 values_to = "count") |>
 | 
			
		||||
    unnest(count) |>
 | 
			
		||||
    mutate(after_doc = as.numeric(str_detect(window, "after"))) |>
 | 
			
		||||
    mutate(is_collab = as.numeric(str_detect(window, "collab")))
 | 
			
		||||
  return(longer)
 | 
			
		||||
}
 | 
			
		||||
expanded_readme_data <- expand_timeseries(readme_df[1,])
 | 
			
		||||
for (i in 2:nrow(readme_df)){
 | 
			
		||||
  expanded_readme_data <- rbind(expanded_readme_data, expand_timeseries(readme_df[i,]))
 | 
			
		||||
}
 | 
			
		||||
expanded_contrib_data <- expand_timeseries(contrib_df[1,])
 | 
			
		||||
for (i in 2:nrow(contrib_df)){
 | 
			
		||||
  expanded_contrib_data <- rbind(expanded_contrib_data, expand_timeseries(contrib_df[i,]))
 | 
			
		||||
}
 | 
			
		||||
expanded_readme_data$log1pcount <- log1p(expanded_readme_data$count)
 | 
			
		||||
expanded_contrib_data$log1pcount <- log1p(expanded_contrib_data$count)
 | 
			
		||||
expanded_readme_data$logcount <- log(expanded_readme_data$count)
 | 
			
		||||
expanded_contrib_data$logcount <- log(expanded_contrib_data$count)
 | 
			
		||||
#breaking out the types of population counts
 | 
			
		||||
collab_pop_readme <- expanded_readme_data[which(expanded_readme_data$is_collab == 1),]
 | 
			
		||||
contrib_pop_readme <- expanded_readme_data[which(expanded_readme_data$is_collab == 0),]
 | 
			
		||||
collab_pop_contrib <- expanded_contrib_data[which(expanded_contrib_data$is_collab == 1),]
 | 
			
		||||
contrib_pop_contrib <- expanded_contrib_data[which(expanded_contrib_data$is_collab == 0),]
 | 
			
		||||
#import models 
 | 
			
		||||
library(lme4)
 | 
			
		||||
library(optimx)
 | 
			
		||||
collab_readme_model <- lmer(log1pcount ~ after_doc + (1| upstream_vcs_link), data=collab_pop_readme, REML=FALSE)
 | 
			
		||||
summary(collab_readme_model)
 | 
			
		||||
contrib_readme_model <- lmer(log1pcount ~ after_doc + ( 1| upstream_vcs_link), data=contrib_pop_readme, REML=FALSE)
 | 
			
		||||
summary(contrib_readme_model)
 | 
			
		||||
collab_contrib_model <- lmer(log1pcount ~ after_doc + ( 1 | upstream_vcs_link), data=collab_pop_contrib, REML=FALSE)
 | 
			
		||||
summary(collab_contrib_model)
 | 
			
		||||
contrib_contrib_model <- lmer(log1pcount ~ after_doc + ( 1 | upstream_vcs_link), data=contrib_pop_contrib, REML=FALSE)
 | 
			
		||||
summary(contrib_contrib_model)
 | 
			
		||||
 | 
			
		||||
library(ggplot2)
 | 
			
		||||
expanded_readme_data |>
 | 
			
		||||
  ggplot(aes(x = after_doc, y = log1pcount, col = as.factor(is_collab))) +
 | 
			
		||||
  geom_point() + geom_jitter()
 | 
			
		||||
 | 
			
		||||
expanded_contrib_data |>
 | 
			
		||||
  ggplot(aes(x = after_doc, y = count, col = as.factor(is_collab))) +
 | 
			
		||||
  geom_point() + geom_jitter()
 | 
			
		||||
@ -58,13 +58,17 @@ all_actions_data$log1p_count <- log1p(all_actions_data$count)
 | 
			
		||||
library(lme4)
 | 
			
		||||
# https://www.bristol.ac.uk/cmm/learning/videos/random-intercepts.html#exvar
 | 
			
		||||
library(optimx)
 | 
			
		||||
library(lattice)
 | 
			
		||||
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, control = lmerControl(
 | 
			
		||||
  optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(all_model)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
all_model_ranef <- as.data.frame(ranef(all_model))
 | 
			
		||||
d_effect_ranef_all <- all_model_ranef[all_model_ranef$term=="D",]
 | 
			
		||||
d_effect_ranef_all$quartile <- ntile(d_effect_ranef_all$condval, 4)
 | 
			
		||||
all_model_ranef <- ranef(all_model, condVar=TRUE)
 | 
			
		||||
dotplot(all_model_ranef)
 | 
			
		||||
df_ranefs <- as.data.frame(all_model_ranef)
 | 
			
		||||
#D_df_ranef <- df_ranefs[df_ranefs$term == "D"]
 | 
			
		||||
#d_effect_ranef_all <- all_model_ranef$upstream_vcs_link
 | 
			
		||||
#d_effect_ranef_all$quartile <- ntile(d_effect_ranef_all$condval, 4)
 | 
			
		||||
#model residuals
 | 
			
		||||
all_residuals <- residuals(all_model)
 | 
			
		||||
qqnorm(all_residuals)
 | 
			
		||||
@ -73,12 +77,11 @@ mrg_model <- lmer(log1p_count ~ D * I(week_offset)+ scaled_project_age + (D * I(
 | 
			
		||||
  optimizer ='optimx', optCtrl=list(method='L-BFGS-B')))
 | 
			
		||||
summary(mrg_model)
 | 
			
		||||
#identifying the quartiles of effect for D
 | 
			
		||||
mrg_model_ranef <- as.data.frame(ranef(mrg_model))
 | 
			
		||||
mrg_model_ranef <- ranef(mrg_model, condVar=TRUE)
 | 
			
		||||
dotplot(mrg_model_ranef)
 | 
			
		||||
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)
 | 
			
		||||
qqnorm(mrg_residuals)
 | 
			
		||||
# Performance: 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user