Skip to content

Commit

Permalink
code: minor updates for revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
jessexknight committed Nov 24, 2021
1 parent f03069a commit 5597d4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 5 additions & 4 deletions code/analysis/meta.r
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ P = list(# stuff to plot
),
dist = c('api.prev','api.inc','art.rbeta','act.n','age.n','hiv.n',
'act.HRW.p','act.HRM.p','act.HRW.cr','act.HR.pr',
'api.prev.cat','api.phase','Risk','pt.def')
'api.prev.cat','api.phase','Risk','pt.def'),
# TODO: api.inc, api.chi from XA
eff.sub = c('Sex','Risk','act.turn.any','pt.def')
)
D = list(# definitions
api.prev = 'HIV prevalence at $t_0$ (\\%)',
Expand Down Expand Up @@ -146,7 +147,7 @@ D = list(# definitions
age.mix = 'Type of age mixing',

act.kp = 'Activity groups \\& key populations',
Risk = 'Summary of risk heterogeneity',
Risk = 'Risk Stratification \\& ART cascade differences',
Sex = 'Sex stratification \\& any ART cascade differences',
act.HRW.p = 'Proportion of women in the highest female activity group',
act.HRM.p = 'Proportion of men in the client or highest activity male group',
Expand Down Expand Up @@ -174,9 +175,9 @@ R = list(# Rename stuff
'HTC Behav. Change' = 'bc.any',
'Sex Stratification' = 'act.def.sex',
'Any ART Diff. by Sex' = 'diff.any.sex',
'Sex Strat. & ART' = 'Sex',
'Sex Stratif. & Cascade Diff.' = 'Sex',
'Activity Turnover' = 'act.turn.any',
'Risk Definition' = 'Risk'),
'Risk Stratif. & Cascade Diff.' = 'Risk'),
t.cat = list(
'0-10'='0',
'11-20'='10',
Expand Down
3 changes: 3 additions & 0 deletions code/analysis/numeric.r
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,16 @@ numeric.api = function(XA){
} else {
tabstr = strfun('%.0f & %.0f & ( %.0f , %.0f ) & \\textsc{ref} & ',nums[1:4])
}
save.tex(strfun('%.0f~(%.0f,~%.0f)',nums[5:7]),namefun(var,level,'eff'),dir=dir)
save.tex(tabstr,namefun(var,level,'xtab'),dir=dir)
}
}
}
names(model) = c('IR','CIA')
g = plot.effects(model,group='Outcome')
save.plot(g,'effects',dir='api',w=6,h=10)
g = plot.effects(model,group='Outcome',subset=c(P$eff.sub,'(Intercept)'))
save.plot(g,'effects-subset',dir='api',w=6,h=4)
}
save.distr = function(x,name,dir='',d=2,funs=NULL,lt=NULL){
fun.list = list(
Expand Down
8 changes: 5 additions & 3 deletions code/analysis/plot.r
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,30 @@ gen.effects = function(model,name=NULL,group=''){
if (var=='(Intercept)'){ varlvls = var; i = TRUE; } else { i = FALSE; }
E.var = coef[varlvls,c('Estimate','low','high')]
lvl.ref = paste0('\n REF = ',rename.lvl(lvls[is.na(E.var$Estimate)],var))
E.var$var = paste0(rename.lvl(var,'vars'),ifelse(i,'',lvl.ref))
E.var$var = var
E.var$lvl = rename.lvl(lvls,var)
E.var$grp = paste0(rename.lvl(var,'vars'),ifelse(i,'',lvl.ref))
return(E.var)
}))
E[[group]] = name
E = E[!is.na(E$Estimate),]
return(E)
}

plot.effects = function(model,group='.'){
plot.effects = function(model,group='.',subset=NULL){
if ('coefficients' %in% names(model)){
E = gen.effects(model,name='',group=group)
} else {
E = do.call(rbind,lapply(names(model),function(name){
gen.effects(model[[name]],name=name,group=group) }))
}
if (!is.null(subset)){ E = E[E$var %in% subset,] }
pos = position_dodge(width=.6)
g = ggplot(E,aes_string(x='Estimate',y='lvl',xmin='low',xmax='high',color=group)) +
geom_point(position=pos) +
geom_linerange(position=pos) +
scale_color_viridis(option='inferno',discrete=TRUE,begin=.3,end=.7) +
facet_grid(rows=vars(E$var),scales='free_y',space='free_y',switch='y') +
facet_grid(rows=vars(E$grp),scales='free_y',space='free_y',switch='y') +
labs(x='Effect',y='Factor') +
theme_light() +
theme(legend.position='top',
Expand Down

0 comments on commit 5597d4c

Please sign in to comment.