/*
fdrisk dialog version 1.1 , 24.12.2020, Sven-Kristjan Bormann
for fdrisk version 1.1 

To install in User Statistics menu via Stata commands:
  
  . window menu append item "stUserStatistics" "SGPV False Confirmation/Discovery Risk (&fdrisk)" "db fdrisk"

  . window menu refresh

To permanently install, place the commands in your -profile.do- file.
*/

VERSION 12.0
POSITION . . 420 470
INCLUDE _std_large

*INCLUDE header
OK ok1,      label("OK")
CANCEL can1, label("Cancel")
SUBMIT sub1, label("Submit") 
HELP hlp1,   view("help fdrisk")  
RESET res1
COPY copy1
INCLUDE levels_list

SCRIPT INIT
BEGIN
	main.sp_level.disable
	main.ed_likelihood.disable
END


DIALOG main, label("Fdrisk 1.1 - False discovery/confirmation risk (Fdr/Fcr)") tabtitle("Main")
BEGIN


	GROUPBOX gb_null	   _lft  _top   270     110, label("Null-Hypothesis Interval")
	TEXT tx_nulllo 		   +10   _ss    80       ., label("Lower Bound") 
	EXP ex_nulllo		    @     _ss   250      ., label("Expression")  option(nulllo) ///
													tooltip("Set lower bound of the null-hypothesis interval") error(Lower Bound null-hypothesis interval)
										   
	TEXT tx_nullhi 		    20   +20     80      ., label("Upper Bound")
	EXP ex_nullhi	 	    @	 _ss    250      ., label("Expression") option(nullhi) ///
													tooltip("Set upper bound of the null-hypothesis interval") error(Upper Bound null-hypothesis interval)
	
	CHECKBOX ck_fcr           300  -40    140  	 ., label("Calculate the FCR") option(fcr) tooltip("Calculate the False Confirmatory Risk instead of the default False Discovery Risk when the observed SGPV is 1.")

	TEXT tx_se			    300   _ss   80      ., label("Standard Error")
	EDIT ed_se			    @     _ss     @     ., option(stderr) default(1) numonly error(Standard error) tooltip("Standard error of the point estimate")
	
	TEXT tx_nullspace      10    	_xls    200    ., label("Null hypothesis parameter space:")
	EXP ex_nullspace       @    _ss    400    ., option(nullspace) error(Nullspace) label("Expression") ///
												tooltip("Support of the null probability distribution.")
												
	GROUPBOX gb_nullweights     10    _ls    180    50, label("Null hypothesis distribution:")
	CHECKBOX ck_nulltruncnormal 20 	_ss 	150 	., label("Truncated Normal") option(nulltruncnormal) tooltip("Use the Truncated-Normal-distribution instead of the Uniform-distribution as the probability distribution for the null parameter space.")												
	
	TEXT tx_altspace     	10   _ls     200    ., label("Alternative hypothesis parameter space:")
	EXP ex_altspace        	@   _ss      400    ., option(altspace) error(Altspace) label("Expression") tooltip("Support for the alternative probability distribution.")
	
	GROUPBOX gb_altweights      @   _ls      180    50, label("Alternative hypothesis distribution:")
	CHECKBOX ck_alttruncnormal 20 	_ss 	150 	., label("Truncated Normal") option(alttruncnormal) tooltip("Use the Truncated-Normal-distribution instead of the Uniform-distribution as the probability distribution for the alternative parameter space.")
	
	CHECKBOX ck_level       	10  _xxls      150    ., label("Confidence Interval Level:")  onclickon(script confidence_on) onclickoff(script confidence_off)
	COMBOBOX  sp_level    	10      _ss      _spwd   .,   label(resource LBL_TX_LEVEL) default(c(level)) option(level) contents(levels) dropdown /// 
														 
	
	CHECKBOX ck_likelihood		 10  _ls      170    ., label("Likelihood support interval level:") onclickon(script likelihood_on) onclickoff(script likelihood_off)
	EDIT ed_likelihood         10  _ss      @    ., option(likelihood) error(No Interval level for the Likelihood-Support-Interval set) tooltip("Set the interval level for the Likelihood-Support-Interval(LSI).")
	
	TEXT tx_pi0           +250  -70     120   ., label("Prior probability of H0:")
	EDIT ed_pi0              @  _ss     100   ., option(pi0) default(0.5) numonly tooltip("This value can be only between 0 and 1 (exclusive).")
	
END

SCRIPT confidence_on
BEGIN
	main.sp_level.enable
	main.ck_likelihood.disable
END

SCRIPT confidence_off
BEGIN
	main.sp_level.disable
	main.ck_likelihood.enable
END


SCRIPT likelihood_on
BEGIN
	main.ed_likelihood.enable
	main.ck_level.disable
END

SCRIPT likelihood_off
BEGIN
	main.ed_likelihood.disable
	main.ck_level.enable
END


PROGRAM command
BEGIN
	put "fdrisk "
	beginoptions
		require main.ex_nulllo
		optionarg main.ex_nulllo
		
		require main.ex_nullhi
		optionarg main.ex_nullhi
		
		require main.ed_se
		optionarg main.ed_se
		
		require main.ex_nullspace
		optionarg main.ex_nullspace
		
		option main.ck_nulltruncnormal
		
		require main.ex_altspace
		optionarg main.ex_altspace
		
		option main.ck_alttruncnormal
		
		optionarg main.sp_level /hidedefault
		optionarg main.ed_likelihood
	
		optionarg main.ed_pi0
		option main.ck_fcr
	endoptions
END