From 369e775fd33cdedf619f1c02aa0b9615641486b0 Mon Sep 17 00:00:00 2001 From: mjgaughan Date: Wed, 8 May 2024 18:58:43 -0500 Subject: [PATCH] messing with figuring out postVar --- R/readmeRDDAnalysis.R | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/R/readmeRDDAnalysis.R b/R/readmeRDDAnalysis.R index e59496b..777d7e5 100644 --- a/R/readmeRDDAnalysis.R +++ b/R/readmeRDDAnalysis.R @@ -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