messing with figuring out postVar

This commit is contained in:
mjgaughan 2024-05-08 18:58:43 -05:00
parent 618f225c38
commit 369e775fd3

View File

@ -61,13 +61,22 @@ 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)
summary_of_all <- 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)
all_model_ranef_condvar <- ranef(all_model, condVar = TRUE)
all_model_ranef <- ranef(all_model, condVar = FALSE)
attr(all_model_ranef_condvar$upstream_vcs_link, "postVar")
all_coefficients <- coef(all_model)
all_standard_errors <- sqrt(diag(vcov(all_model)))[1]
#all_conf_intervals <- cbind(all_coefficients - 1.96 * all_standard_errors,
# all_coefficients + 1.96 * all_standard_errors)
df_ranefs <- as.data.frame(all_model_ranef_condvar)
df_rn_no_cv <- as.data.frame(all_model_ranef)
D_df_ranef <- df_ranefs[which(df_ranefs$term == "D"),]
#below this groups the ranefs
"""
has_zero <- function(condval, condsd){
bounds <- condsd * 1.96
return(ifelse(((condval - bounds) < 0),ifelse(((condval + bounds) > 0), 1, 0), 2))
@ -75,14 +84,17 @@ has_zero <- function(condval, condsd){
df_ranefs <- df_ranefs |>
mutate(ranef_grouping = has_zero(condval, condsd)) |>
mutate(rank = rank(condval))
D_df_ranef <- df_ranefs[which(df_ranefs$term == "D"),]
D_df_ranef <- df_ranefs[which(df_ranefs$term == ),]
D_df_ranef <- D_df_ranef |>
mutate(rank = rank(condval))
hist(D_df_ranef$ranef_grouping)
#plot the ranefs
library(ggplot2)
D_df_ranef |>
ggplot(aes(x=rank, y=condval, col = as.factor(ranef_grouping))) +
geom_linerange(aes(ymin= condval - (1.96 * condsd), ymax= condval + (1.96 * condsd))) +
geom_bw()
theme_bw()
"""
#d_effect_ranef_all <- all_model_ranef$upstream_vcs_link
#d_effect_ranef_all$quartile <- ntile(d_effect_ranef_all$condval, 4)
#model residuals