/*
  mi impute poisson

*!  VERSION 1.0.1  23may2011

  keyword:  mi impute

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 390
INCLUDE header

HELP hlp1, view("help mi impute poisson")
RESET res1

SCRIPT PREINIT
BEGIN
	program  parseMessage
	create STRING _mi_ivars
	create LIST   _mi_IVARS_LIST
END

PROGRAM parseMessage
BEGIN
	if __MESSAGE.contains("__MONO__") {
		call script main_mono_on
	}
	if __MESSAGE.contains("__MONO_CUST__") {
		call script main_mono_custom_on
	}
	if __MESSAGE.contains("__CHAIN__") {
		call script main_chain_on
	}
END

SCRIPT POSTINIT
BEGIN
	_mi_ivars.setvalue char _dta[_mi_ivars]

	_mi_IVARS_LIST.Arrdropall
	_mi_ivars.tokenize _mi_IVARS_LIST
	main.cb_ivar.repopulate
	main.cb_ivars.repopulate
END

DIALOG main, tabtitle("Main")	///
	label("")
BEGIN
  TEXT     tx_ivar	_lft	_topph	_vnwd	.,			///
	label("Imputed variable:")
  COMBOBOX cb_ivar	@ 	_ss	@	.,			///
	dropdown							///
	contents(_mi_IVARS_LIST)					///
	label("Imputed variable")
  COMBOBOX cb_ivars	@ 	@	480	.,			///
	append								///
	dropdown							///
	contents(_mi_IVARS_LIST)					///
	label("Imputed variables")

  TEXT     tx_iv	_vlx	_topph	160	.,			///
	label("Independent variables:")
  VARLIST  vl_iv	@	_ss	_vlwd	.,			///
	fv								///
	label("Independent variables")

  DEFINE _x _lft
  DEFINE _cx _iwd
  DEFINE _y _ls
  INCLUDE _mi_impute_chained_cust_opts

  CHECKBOX ck_nocons	@	_ms	@	.,			///
	label("Suppress constant term")					///
	option(noconstant)

  RADIO rb_expose 	_lft	_ls	_cwd3_2	., first		///
	onclickon(main.vn_expose.enable)				///
	onclickoff(main.vn_expose.disable)				///
	label("Exposure variable:")
  RADIO rb_offset	_lft3_2	@	@	., last			///
	onclickon(main.vn_offset.enable)				///
	onclickoff(main.vn_offset.disable)				///
	label("Offset variable:")

  VARNAME vn_expose	_lft	_ss	@	.,			///
	option(exposure)						///
	label("Exposure variable")
  VARNAME vn_offset	_lft3_2	@	@	.,			///
	option(offset)							///
	label("Offset variable")

  DEFINE _x _lft
  DEFINE _cx _iwd
  DEFINE _y _ls
  INCLUDE _mi_impute_uni_cond_boot
  
  DEFINE _x _lft
  DEFINE _cx _iwd
  DEFINE _y _ms
  INCLUDE _mi_impute_noisily
END

INCLUDE _mi_impute_chained_cust_opts_sc

SCRIPT main_mono_on
BEGIN
	script main_chain_hide
	script main_mono_custom_off
	main.ck_nocons.setposition 10 70 400 .
	main.rb_expose.setposition . 100
	main.rb_offset.setposition . 100
	main.vn_expose.setposition . 120
	main.vn_offset.setposition . 120
	main.tx_cond.setposition . 150
	main.ex_cond.setposition . 170
	main.ck_bootstrap.setposition . 200
	main.ck_noisily.setposition . 225
END

SCRIPT main_mono_custom_on
BEGIN
	script main_chain_hide
	main.ck_nocons.setposition 150 60 260 .
	main.rb_expose.setposition . 90
	main.rb_offset.setposition . 90
	main.vn_expose.setposition . 110
	main.vn_offset.setposition . 110
	main.tx_cond.setposition . 140
	main.ex_cond.setposition . 160
	main.ck_bootstrap.setposition . 190
	main.ck_noisily.setposition . 215
	main.tx_iv.show
	main.vl_iv.show
	main.cb_ivars.hide
	main.cb_ivar.show
END

SCRIPT main_mono_custom_off
BEGIN
	main.tx_iv.hide
	main.vl_iv.hide
	main.cb_ivar.hide
	main.cb_ivars.show
	main.tx_ivar.setlabel "Imputed variables:"
END

SCRIPT main_chain_on
BEGIN
	script main_chain_show
	script main_mono_custom_off
	main.ck_nocons.setposition 10 180 400 .
	main.rb_expose.setposition . 210
	main.rb_offset.setposition . 210
	main.vn_expose.setposition . 230
	main.vn_offset.setposition . 230
	main.tx_cond.setposition . 260
	main.ex_cond.setposition . 280
	main.ck_bootstrap.setposition . 310
	main.ck_noisily.setposition . 335
END

INCLUDE if
INCLUDE max_ml

PROGRAM command_output
BEGIN
	if main.vl_iv.isvisible() {
		put "poisson"
		varlist main.cb_ivar
		if main.vl_iv {
			put " " main.vl_iv
		}
	}
	else {
		put "poisson"
		if main.cb_ivar.isvisible() {
			varlist main.cb_ivar
		}
	}
	put " " /program if_output
	beginoptions
		put " " /program main_chained_output
		option main.ck_nocons
		optionarg main.vn_expose
		optionarg main.vn_offset
		INCLUDE _mi_impute_uni_cond_boot_pr
		option main.ck_noisily
		put " " /program max_output
	endoptions
END

PROGRAM command
BEGIN
	put " ("
	put /program command_output
	put ") "
	if main.cb_ivars.isvisible() {
		varlist main.cb_ivars
	}
END
