library(tidyverse)
library(texreg)

readme_rdd <- readRDS("mlm/models/020325_readme_model.rda")
contrib_rdd <- readRDS("mlm/models/020125_contributing_model.rda")

texreg(list(readme_rdd, contrib_rdd), stars=NULL, digits=3, use.packages=FALSE, 
       custom.model.names=c( 'README','CONTRIBUTING'),
       custom.coef.names=c('(Intercept)', 'Indtroduction', 'Week (Time)', 'Project Age', 'Introduction:Week'), 
       table=FALSE, ci.force = TRUE)

readme_groupings <- read.csv('mlm/data/0203_readme_dweek_ranefs.csv')
contrib_groupings <- read.csv('mlm/data/0201_contributing_dweek_ranefs.csv')

subdirColors <-
  setNames( c('#31449c', '#4a7c85', '#c5db68')
            , c(0,1,2)  )

readme_g <- readme_groupings |> 
  ggplot(aes(x=rank, y=estimate, col = as.factor(ranef_grouping))) +
  geom_linerange(aes(ymin= conf.low, ymax= conf.high)) +
  scale_color_manual(values = subdirColors) + 
  guides(fill="none", color="none")+
  theme_bw() + 
  labs(x="RE Coefficient Rank", y="RE Coefficient Estimate", color="Estimate Grouping")
readme_g


contrib_g <- contrib_groupings |> 
  ggplot(aes(x=rank, y=estimate, col = as.factor(ranef_grouping))) +
  geom_linerange(aes(ymin= conf.low, ymax= conf.high)) +
  scale_color_manual(values = subdirColors, labels=c('CI < 0', '0 in CI', '0 < CI')) + 
  theme_bw() +
  theme(legend.position = "top")  +
  labs(x="RE Coefficient Rank", y="RE Coefficient Estimate", color="Estimate Grouping")
contrib_g

#ggsave(filename = "plots/cr-0203-contributing-blup.png", plot = contrib_g, width = 9, height = 9, dpi = 800)


texreg(list(readme_commits_, commits_), stars=NULL, digits=3, use.packages=FALSE, 
       custom.model.names=c( 'README','Contributing'),
       custom.coef.names=c('Topic 1', 'Topic 2', 'Topic 3', 'Topic 4', 'Topic 5', 'Topic 6', 'Topic 7', 'Topic 8'), 
       table=FALSE, ci.force = TRUE)

