Skip to content

Commit ca0f1d3

Browse files
committed
-make range of values more constrained in shiny app
-make app color coding fixed and same as in the paper -fix issue with plots in the demo
1 parent 85c26bb commit ca0f1d3

File tree

2 files changed

+69
-58
lines changed

2 files changed

+69
-58
lines changed

apps & wrappers/BRMS demo.Rmd

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,22 @@ fit_eip_HRDT <-
196196
prior = empirically_informed_priors_HRDT
197197
)
198198
199-
fit_wip_HRDT <-
200-
brm(
201-
bff_HRDT,
202-
data=sim_data_HRDT,
203-
chains = 4,
204-
cores = 4,
205-
seed = seed,
206-
backend = "cmdstan",
207-
warmup=2000,
208-
iter=4000,
209-
control=list(
210-
adapt_delta=0.9,
211-
max_treedepth = 10
212-
),
213-
prior = weakly_informative_priors_HRDT
214-
)
199+
# fit_wip_HRDT <-
200+
# brm(
201+
# bff_HRDT,
202+
# data=sim_data_HRDT,
203+
# chains = 4,
204+
# cores = 4,
205+
# seed = seed,
206+
# backend = "cmdstan",
207+
# warmup=2000,
208+
# iter=4000,
209+
# control=list(
210+
# adapt_delta=0.9,
211+
# max_treedepth = 10
212+
# ),
213+
# prior = weakly_informative_priors_HRDT
214+
# )
215215
```
216216

217217
## Model diagnosing
@@ -296,15 +296,24 @@ sprintf(
296296
We can then construct plots that show the posterior distribution for the group-level differences in threshold and slope. We will also add a line range materializing the 95% CI.
297297

298298
```{r}
299+
summary_stats_HRDT_plot<-
300+
summary_stats_HRDT %>%
301+
filter(grepl('diff',summary_stats_HRDT$name)) %>%
302+
mutate(name=factor(name,c('mean_alpha_diff','mean_beta_diff'),c('Threshold','Log(Slope)')))
303+
304+
299305
as_draws_df(fit_eip_HRDT) %>%
300306
select(b_alpha_conditiontreatment,b_beta_conditiontreatment) %>%
307+
rename(
308+
mean_alpha_diff=b_alpha_conditiontreatment,
309+
mean_beta_diff=b_beta_conditiontreatment
310+
) %>%
301311
pivot_longer(everything()) %>%
302-
full_join(summary_stats_HRDT) %>%
303-
mutate(name=factor(name,c('b_alpha_conditiontreatment','b_beta_conditiontreatment'),c('Threshold','Log(Slope)'))) %>%
312+
mutate(name=factor(name,c('mean_alpha_diff','mean_beta_diff'),c('Threshold','Log(Slope)'))) %>%
304313
ggplot()+
305314
geom_histogram(aes(x=value),color='black')+
306315
geom_vline(aes(xintercept = 0),linetype='dotted',color='grey',linewidth=1)+
307-
geom_pointrange(aes(x=m,xmin=LB,xmax=UB,y=-20,group = name),linewidth=1)+
316+
geom_pointrange(data=summary_stats_HRDT_plot,aes(x=m,xmin=LB,xmax=UB,y=-20,group = name),linewidth=1)+
308317
labs(
309318
title='Group mean differences between conditions',
310319
subtitle='HRDT',
@@ -645,22 +654,22 @@ fit_eip_RRST <-
645654
prior = empirically_informed_priors_RRST
646655
)
647656
648-
fit_wip_RRST <-
649-
brm(
650-
bff_RRST,
651-
data=sim_data_RRST,
652-
chains = 4,
653-
cores = 4,
654-
seed = seed,
655-
backend = "cmdstan",
656-
warmup=1000,
657-
iter=2000,
658-
control=list(
659-
adapt_delta=0.99,
660-
max_treedepth = 10
661-
),
662-
prior = weakly_informative_priors_RRST
663-
)
657+
# fit_wip_RRST <-
658+
# brm(
659+
# bff_RRST,
660+
# data=sim_data_RRST,
661+
# chains = 4,
662+
# cores = 4,
663+
# seed = seed,
664+
# backend = "cmdstan",
665+
# warmup=1000,
666+
# iter=2000,
667+
# control=list(
668+
# adapt_delta=0.99,
669+
# max_treedepth = 10
670+
# ),
671+
# prior = weakly_informative_priors_RRST
672+
# )
664673
```
665674

666675
## Model diagnosing
@@ -780,6 +789,7 @@ spread_diffs<-
780789
spread_diffs_stats<-
781790
spread_diffs %>%
782791
summarise(
792+
name='spread_difference',
783793
m=mean(difference),
784794
LB=quantile(difference,0.025),
785795
UB=quantile(difference,0.975),
@@ -833,28 +843,25 @@ sprintf(
833843
We can then construct plots that show the posterior distribution for the group-level differences in threshold and spread. We will also add a linerange materializing the 95% CI.
834844

835845
```{r}
836-
spread_differences_long<-
846+
spread_differences<-
837847
spread_diffs %>%
838-
select(difference) %>%
839-
rename(value=difference) %>%
840-
mutate(
841-
name='spread_difference',
842-
m=spread_diffs_stats$m,
843-
LB=spread_diffs_stats$LB,
844-
UB=spread_diffs_stats$UB,
845-
p_larger_than_0=spread_diffs_stats$p_larger_than_0,
846-
pseudo_p_value=spread_diffs_stats$pseudo_p_value
847-
)
848+
select(difference)
849+
summary_RRST_plot<-
850+
summary_stats_RRST %>%
851+
filter(name=='mean_alpha_diff') %>%
852+
full_join(spread_diffs_stats) %>%
853+
mutate(name=factor(name,c('mean_alpha_diff','spread_difference'),c('Log(Threshold)','Spread')))
854+
848855
as_draws_df(fit_eip_RRST) %>%
856+
select(b_alpha_conditiontreatment) %>%
857+
rename(mean_alpha_diff=b_alpha_conditiontreatment) %>%
858+
mutate(spread_difference=spread_differences$difference) %>%
849859
pivot_longer(everything()) %>%
850-
full_join(summary_stats_RRST) %>%
851-
filter(name=='b_alpha_conditiontreatment') %>%
852-
full_join(spread_differences_long) %>%
853-
mutate(name=factor(name,c('b_alpha_conditiontreatment','spread_difference'),c('Log(Threshold)','Spread'))) %>%
860+
mutate(name=factor(name,c('mean_alpha_diff','spread_difference'),c('Log(Threshold)','Spread'))) %>%
854861
ggplot()+
855862
geom_histogram(aes(x=value),color='black')+
856863
geom_vline(aes(xintercept = 0),linetype='dotted',color='grey',linewidth=1)+
857-
geom_pointrange(aes(x=m,xmin=LB,xmax=UB,y=-10,group = name))+
864+
geom_pointrange(data=summary_RRST_plot,aes(x=m,xmin=LB,xmax=UB,y=-10,group = name))+
858865
labs(
859866
title='Group mean differences between conditions',
860867
subtitle='RRST',

apps & wrappers/shiny app.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ ui <- navbarPage("Bayesian Power Simulation Explorer",
2222
sidebarPanel(
2323
selectInput("parameter", "Parameter:", choices = c("Threshold", "Slope")),
2424
numericInput("es", "Effect size (d):", value = 0.5, min = 0, max = 1, step = 0.01),
25-
sliderInput("subjects", "N subjects:", min = 5, max = 150, value = c(10, 60), step = 1),
26-
sliderInput("trials", "N trials:", min = 10, max = 150, value = c(10, 60), step = 1),
25+
sliderInput("subjects", "N subjects:", min = 15, max = 120, value = c(10, 60), step = 1),
26+
sliderInput("trials", "N trials:", min = 30, max = 90, value = c(10, 60), step = 1),
2727
radioButtons(
2828
inputId = "powerlevel",
2929
label = "Desired power level:",
@@ -33,7 +33,8 @@ ui <- navbarPage("Bayesian Power Simulation Explorer",
3333
)
3434
),
3535
mainPanel(
36-
plotOutput("gridPlot")
36+
plotOutput("gridPlot"),
37+
p(em('Disclaimer: power lines may fall out of the displayed range. If none is visible, try changing the values'))
3738
)
3839
)
3940
),
@@ -43,8 +44,8 @@ ui <- navbarPage("Bayesian Power Simulation Explorer",
4344
sidebarLayout(
4445
sidebarPanel(
4546
selectInput("parameter2", "Parameter:", choices = c("Threshold", "Slope")),
46-
sliderInput("subjects2", "N subjects:", min = 5, max = 150, value = 30, step = 1),
47-
sliderInput("trials2", "N trials:", min = 10, max = 150, value = 30, step = 1),
47+
sliderInput("subjects2", "N subjects:", min = 15, max = 120, value = 30, step = 1),
48+
sliderInput("trials2", "N trials:", min = 30, max = 90, value = 30, step = 1),
4849
radioButtons(
4950
inputId = "powerlevel2",
5051
label = "Desired power level:",
@@ -63,8 +64,8 @@ ui <- navbarPage("Bayesian Power Simulation Explorer",
6364
sidebarLayout(
6465
sidebarPanel(
6566
selectInput("parameter3", "Parameter:", choices = c("Threshold", "Slope")),
66-
numericInput("manual_subjects", "Number of subjects:", value = 30, min = 1, max = 150, step = 1),
67-
numericInput("manual_trials", "Number of trials:", value = 40, min = 1, max = 150, step = 1),
67+
numericInput("manual_subjects", "Number of subjects:", value = 30, min = 15, max = 120, step = 1),
68+
numericInput("manual_trials", "Number of trials:", value = 40, min = 30, max = 90, step = 1),
6869
numericInput("manual_es", "Effect size (d):", value = 0.5, min = 0, max = 1, step = 0.01),
6970
actionButton("manual_submit", "Submit")
7071
),
@@ -97,6 +98,7 @@ server <- function(input, output, session) {
9798
ylim = c(input$subjects[1], input$subjects[2])) +
9899
scale_x_continuous(breaks = scales::pretty_breaks(n = 3)) +
99100
scale_y_continuous(breaks = scales::pretty_breaks(n = 3)) +
101+
scale_color_manual(labels=c('Hierarchical','Simple t-test','Uncertainty prop. t-test'),values =c('#D55E00','#CC79A7','#0072B2'))+
100102
theme(text = element_text(size = 16))
101103
})
102104

@@ -274,6 +276,8 @@ server <- function(input, output, session) {
274276
labs(x = "Effect size (d)", y = "Power",colour='Test type',fill='Test type') +
275277
scale_y_continuous(limits = c(0, 1)) +
276278
scale_x_continuous(limits = c(0, 1)) +
279+
scale_color_manual(labels=c('Hierarchical','Simple t-test','Uncertainty prop. t-test'),values =c('#D55E00','#CC79A7','#0072B2'))+
280+
scale_fill_manual(labels=c('Hierarchical','Simple t-test','Uncertainty prop. t-test'),values =c('#D55E00','#CC79A7','#0072B2'))+
277281
theme(text = element_text(size = 16))+
278282
geom_hline(yintercept = 0.05, linetype = 2)+
279283
geom_hline(yintercept = as.numeric(desired_power), linetype = 2)

0 commit comments

Comments
 (0)