info      MACRO
) MacAnova macros that are gui related
)
)
) Written by Gary Oehlert, School of Statistics, University of Minnesota,
) (gary@stat.umn.edu)
) guiabout       Display the about dialog (03/15/2005)
) guicoefs       Display coefficients/effects from an anova (07/30/05)
) guicontrast    Do contrasts from an anova (07/30/05)
) guidelete      Delete variables chosen from a dialog (06/28/2005)
) guifilepath    Set files and paths in search lists (06/24/2005)
) guihelp        Get html help   (03/15/2005)
) guilistxml     generate xml fragments for use in choose variables (06/28/2005)
) guilistctrl    generate xml for a variable choice control (06/28/2005)
) guilistdlg     generate xml for a variable choice dialog (06/28/2005)
) guipatterned   Build patterned data (06/24/2005)
) guireadfile    Read data from various file/clipboard formats (06/24/2005)
) guirandom      Generate random data (06/24/2005)
) guirsample     Subsample a variable (06/24/2005)
) guitypein      Type in data (06/24/2005)
) guibasicstat   Core macro to do simple statistics (07/23/05)
) guianova       Macro to do basic anova (07/27/05)
) guiboxplot     macro to do boxplots (08/02/05)
) guiappropt     utility macro to do graphics appearance options
) guiaxisopt     utility macro to do graphics axis options
) guirandtest    does randomization t-test or sign test (08/02/05)
) guihist        does histograms (08/03/05)
) guiplotresid   set up residual plots (08/04/05)
) guiglmtable    front end for glmtable (08/05/05)
) guitabs        front end for tabs (08/06/05)
) guipairwise    front end for pairwise (08/06/05)
) guisampsize    front end for findsampsize (08/06/05)
) guipower       front end for findpower (08/07/05)
) guintrctplt    front end for interactplot (08/12/05)
) guimakecols    front end for makecols (08/13/05)
) guimakefact    front end for makefactor (08/14/05)
) guibldanvmdl   macro to build an anova model (08/14/05)
) guigetmdlwts   macro to select model weights (08/14/05)
) guiems         front end for ems (08/14/05)
) guivarcomp     front end for varcomp (08/14/05)
) guimixed       front end for mixed (08/14/05)
) guicumprob     does various cumulative probabilities (08/15/05)
) guiinvprob     does various percent points (08/15/05)
) guiallK        front end for all[34]anova (08/16/05)
) guisidebside   front end for sidebyside (08/16/05)
) guireml        front end for reml (08/16/05)
%info%

====> guiabout <====
guiabout MACRO DOLLARS
@banner <- findfile("Welcome.gif")
@copying <- findfile("Copying.txt")
@copyright <- findfile("docs/html/base_copyright.htm")
@documents <- findfile("Documentation.htm")
@news <- findfile("News.htm")
@version <- findfile("Version.htm")
@resource <- matread("Gui.dat.txt","GUIAboutRes",notfoundok:T)
if(isnull(@resource)) {
	alert("Cannot find about dialog resource")
	return(NULL)
}
if(!isnull(@banner)) {
	@resource <- replacestr(@resource,"BANNERFILE",@banner)
}
if(!isnull(@copying)) {
	@resource <- replacestr(@resource,"COPYINGFILE",@copying)
}
if(!isnull(@copyright)) {
	@resource <- replacestr(@resource,"COPYRIGHTFILE",@copyright)
}
if(!isnull(@documents)) {
	@resource <- replacestr(@resource,"DOCUMENTSFILE",@documents)
}
if(!isnull(@news)) {
	@resource <- replacestr(@resource,"NEWSFILE",@news)
}
if(!isnull(@version)) {
	@resource <- replacestr(@resource,"VERSIONFILE",@version)
}
setmdialog(@resource,"about_dialog")
return(NULL)
%guiabout%

====> guidelete <====
guidelete MACRO DOLLARS
@out <- guilistdlg(attrchar:T,attrgraph:F,\
	attrlogic:T,attrmacro:F,attrreal:T,attrstruc:T,\
	requlock:T)
if(!isnull(@out)) {
	@command <- paste("delete(",@out[1])
	if(length(@out) > 1) {
		for(@i,run(2,length(@out))) {
			@command <- paste(@command,",",@out[@i])
		}
	}
	@command <- paste(@command,")")
	pushcommand(@command)
}
;;
%guidelete%



====> guifilepath <====
guifilepath MACRO DOLLARS
# types are "setdatafile", "addmacrofile", "addhelpfile", "addpath"
@type <- keyvalue($K,"type","char scalar",default:"setdatafile")
if(@type == "addpath") {
	@path <- getdirname()
	if(isnull(@path)) {
		error("Path selection cancelled")
	}
	@command <- paste("adddatapath(\"",@path,"\")",sep:"")
	pushcommand(@command)
	return(NULL)
}
@name <- getfilename()
# getfilename has an error if cancelled
if(@type == "setdatafile") {
	@command <- paste("DATAFILE <- \"",@name,"\"",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@type == "addmacrofile") {
	@command <- paste("addmacrofile(\"",@name,"\")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@type == "addhelpfile") {
	@command <- paste("addhelpfile(\"",@name,"\")",sep:"")
	pushcommand(@command)
	return(NULL)
}
%guifilepath%


====> guihelp <====
guihelp     MACRO DOLLARS
if($v == 0) {
	@fp <- findfile("docs/html/help.htm")
	if(!isnull(@fp)) {
		doguihelp(@fp)
		return(NULL)
	}
	alert("No html help found")
	return(NULL)
}
@topic <- $A[1]
@fp <- findfile(paste("docs/html/",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/base_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/arima_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/design_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/graphics_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/gui_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/math_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/mulvar_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/regress_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/tser_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
@fp <- findfile(paste("docs/html/user_",@topic,".htm",sep:""))
if(!isnull(@fp)) {
	doguihelp(@fp)
	return(NULL)
}
alert(paste("No html help found for topic:",@topic))
return(NULL)
%guihelp%


====> guilistxml <====
guilistxml MACRO DOLLARS
# selection attributes in control
# keys (all logical) are attrchar, attrfunc, attrgraph, attrlogic,
# attrmacro, attrreal, attrfactr, attrvart, attrscalr, attrvect,
# attrmatrx, attrarray, attrstruc, attrlockd, attrulock, attrbinary
# attrnsvart, attrnsfact, attrsystem
# useonly:vector of names
# omit:vector of names
@selectors <- vector("ischar","isfunction","isgraph",\
	"islogic","ismacro","isreal","isfactor",\
	"isvariate","isscalar","isvector","ismatrix",\
	"isarray","isstruc","islocked","isulocked","isbinary",\
	"issystem","isnonsystem","isnsvart","isnsfactr","is1d","is2d",\
	"isns1d","isns2d","isnsstruc")
@codes <- vector("char","func","graph","logic","macro",\
	"real","factr","vart","scalr","vect","matrx",\
	"array","struc","lockd","ulock","binary",\
	"system","nonsys","nsvart","nsfact","1d","2d",\
	"ns1d","ns2d","nsstrc")
@longcode <- vector("Character","Function","Graph","Logical",\
	"Macro","Numeric","Factor","Variate","Scalar","Vector",\
	"Matrix","Array","Structure","Locked","Unlocked","Binary",\
	"System","Non-system","Variate","Factor","Vector","Matrix",\
	"Vector","Matrix","Structure")
is1d <- macro("alltrue(!isstruc(\\$1),ndims(\\$1)==1)",inline:F)
is2d <- macro("alltrue(!isstruc(\\$1),ndims(\\$1)==2)",inline:F)
isulocked <- macro("(!islocked(\\$1))",inline:F)
isvariate <- macro("(is1d(\\$1)&&isreal(\\$1)&&!isfactor(\\$1))",inline:F)
isbinary <- macro("alltrue(isreal(\\$1),(sum(vector(\\$1)==0)+sum(vector(\\$1)==1))==sum(vector(!ismissing(\\$1))))",inline:F)
issystem <- macro("@name <- nameof(\\$1)
	@chars <- vecread(string:@name,bychars:T)
	if(alltrue(length(@chars) > 1,@chars[1] == \"g\",@chars[2] == \"_\")) {
		return(T)
	}
	@nc <- length(@chars)
	@caps<-vector(\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\",\
	\"H\",\"I\",\"J\",\"K\",\"L\",\"M\",\"N\",\"O\",\"P\",\"Q\",\
	\"R\",\"S\",\"T\",\"U\",\"V\",\"W\",\"X\",\"Y\",\"Z\")
	@allcaps <- min(match(@chars,@caps,-1)) > 0
	(@allcaps && (@nc > 1 || @name == \"E\"))",dollars:T,inline:F)
isnonsystem <- macro("(!issystem(\\$1))",inline:F)
isnsvart <- macro("(isvariate(\\$1) && !issystem(\\$1))",dollars:T,inline:F)
isnsfactr <- macro("(isfactor(\\$1) && !issystem(\\$1))",dollars:T,inline:F)
isns1d <- macro("((!issystem(\\$1))&&is1d(\\$1))",inline:F)
isns2d <- macro("((!issystem(\\$1))&&is2d(\\$1))",inline:F)
isnsstruc <- macro("(!issystem(\\$1)&&isstruc(\\$1))",inline:F)
@attrstr <- " "
@attrindx <- NULL

for(@i,run(length(@codes))) {
	if(!isnull(@thiskey<-keyvalue($K,paste("attr",@codes[@i],sep:""),\
	  "logic scalar"))) {
		@attrindx <- vector(@attrindx,@i)
		@attrstr <- paste(@attrstr,"<item>\n<name>",\
			@longcode[@i],"</name>\n",sep:"")
		if(@thiskey) {
			@attrstr <- paste(@attrstr,"<checked>1</checked>\n")
		}
		@attrstr <- paste(@attrstr,"</item>\n")
	}
}

@reqindx <- NULL
		
for(@i,run(length(@codes))) {
	if(!isnull(keyvalue($K,paste("req",@codes[@i],sep:""),\
	  "logic scalar"))) {
		@reqindx <- vector(@reqindx,@i)
	}
}
@reqnrows <- keyvalue($K,"reqnrows","count scalar")
@reqndims <- keyvalue($K,"reqndims","count scalar")


@useindx <- NULL
for(@i,run(length(@codes))) {
	if(!isnull(@tmp <- keyvalue($K,paste("use",@codes[@i],sep:""),\
	  "logic scalar"))) {
		@useindx <- vector(@useindx,@i)
	}
}

@matchrows <- keyvalue($K,"matchrows","logic scalar",default:F)

@vars <- keyvalue($K,"useonly","char vector")
if(isnull(@vars)) {
	@vars <- list(keep:T)
}
@omit <- keyvalue($K,"omit","char vector",default:" ")

@keptvars <- NULL
@itemstr <- " "

for(@i,run(length(@vars))) {
	if(match(@vars[@i],@omit,-1) > 0) {
		next
	}
	@usethis <- T
	if(!isnull(@reqindx)) {
		for(@j,run(length(@reqindx))) {
			if(!<<@selectors[@reqindx[@j]]>>(<<@vars[@i]>>)) {
				@usethis <- F
			}
		}
	}
	if(!@usethis) {
		next
	}
	if(!isnull(@reqnrows)) {
		if(abs(nrows(<<@vars[@i]>>) - @reqnrows) > .1) {
			next
		}
	}
	if(!isnull(@reqndims)) {
		if(abs(ndims(<<@vars[@i]>>) - @reqndims) > .1){
			next
		}
	}
	if(!isnull(@useindx)) {
		@usethis <- F
		for(@j,run(length(@useindx))) {
			if(<<@selectors[@useindx[@j]]>>(<<@vars[@i]>>)) {
				@usethis <- T
			}
		}
		if(!@usethis) {
			next
		}
	}
	@thisitem <- paste("<item>\n  <label>",@vars[@i],"</label>\n",sep:"")
	if(@matchrows) {
		@thisitem <- paste(@thisitem,"  <dimension>",\
			nrows(<<@vars[@i]>>),"</dimension>\n",sep:"")
	}
	if(isnull(@attrindx)) {
		@usethis <- T
	} else {
		@thisitem<-paste(@thisitem,"  <attributes>\n",sep:"")
		@usethis <- F
		for(@j,run(length(@attrindx))) {
			@thisitem <- paste(@thisitem,"    <attr>",sep:"")
			if(<<@selectors[@attrindx[@j]]>>(<<@vars[@i]>>)) {
				@usethis <- T
				@thisitem <- paste(@thisitem,"1</attr>\n",sep:"")
			} else {
				@thisitem <- paste(@thisitem,"0</attr>\n",sep:"")
			} 
		}
		@thisitem<-paste(@thisitem,"  </attributes>\n",sep:"")
	}
	@thisitem<-paste(@thisitem,"</item>\n",sep:"")
	if(@usethis) {
		@keptvars <- vector(@keptvars,@vars[@i])
		@itemstr <- paste(@itemstr,@thisitem,sep:"")
	}
}
structure(keptvars:@keptvars,attrstr:@attrstr,itemstr:@itemstr)
%guilistxml%

====> guilistctrl <====
guilistctrl MACRO DOLLARS
@stuff <- guilistxml($0)
@max <- keyvalue($K,"maxselect","count",default:0)
@maxout <- paste("<maxselected>",@max,"</maxselected>\n",sep:"")
@xmlbase <- matread("Gui.dat.txt","guilistcbase",silent:T)
@xmlbase <- replacestr(@xmlbase,"ATTRIBUTELIST",@stuff$attrstr)
@xmlbase <- replacestr(@xmlbase,"ITEMLIST",@stuff$itemstr)
@xmlbase <- replacestr(@xmlbase,"MAXSELECTED",@maxout)
structure(vars:@stuff$keptvars,xml:@xmlbase)
%guilistctrl%

====> guilistdlg <====
guilistdlg MACRO DOLLARS
@stuff <- guilistctrl($0)
if(!ischar(g_listdbase)) {
	g_listdbase <- matread("Gui.dat.txt","g_listdbase",silent:T)
}
@xmlbase <- replacestr(g_listdbase,"LISTCONTROL",@stuff$xml)
@title <- keyvalue($K,"title","char scalar",default:"Choose Variables")
@prompt <- keyvalue($K,"prompt","char scalar",default:"Choose Variable(s)")
@xmlbase <- replacestr(@xmlbase,"PROMPT",@prompt)
@xmlbase <- replacestr(@xmlbase,"TITLE",@title)
@out <- setmdialog(@xmlbase,"listdbase")
if(isnull(@out)) {
	error("Variable selection cancelled")
}
@out <- vecread(string:@out[2][1])
if(isnull(@out)) {
	return(NULL)
} else {
	return(@stuff$vars[@out+1])
}
%guilistdlg%


====> guipatterned <====
guipatterned MACRO DOLLARS
if(!ischar(g_patterned)) {
	g_patterned <- matread("Gui.dat.txt","g_patterned",silent:T)
}
@out <- setmdialog(g_patterned,"patterned_dialog")
if(isnull(@out)) {
	error("Patterned data cancelled")
}
@max <- vecread(string:@out[2][1])[1]
@each <- vecread(string:@out[2][2])[1]
@all <- vecread(string:@out[2][3])[1]
@dofactor <- (@out[2][4] == "checked")
@variable <- @out[2][5]
if(alltrue(@variable != "",!isname(@variable))) {
	alert("Illegal variable name specified")
	error("Illegal variable name specified")
}
@command <- paste("rep(rep(run(",@max,"),rep(",@each,",",@max,")),",@all,")")
if(@dofactor) {
	@command <- paste("factor(",@command,")")
}
if(@variable != "") {
	@command <- paste(@variable, "<-", @command)
}
pushcommand(@command)
return(NULL)
%guipatterned%


====> guirandom <====
guirandom MACRO DOLLARS
# distributions are "uniform", "normal", "binomial", "poisson",
# "F", "beta", "student", "gamma", "chisq"
@dist <- keyvalue($K,"dist","char scalar",default:"uniform")
if(@dist == "uniform") {
	if(!ischar(g_random1)) {
		g_random1 <- matread("Gui.dat.txt","g_random1",silent:T)
	}
	@out <- setmdialog(g_random1,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@lower <- @out[2][2]
	@upper <- @out[2][3]
	@variable <- @out[2][4]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(!isnumber(@lower)) {
		alert("Lower limit is not a number");
		error("Lower limit is not a number");
	}
	if(!isnumber(@upper)) {
		alert("Upper limit is not a number");
		error("Upper limit is not a number");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, @lower, "+ (",@upper, "-", @lower, ")*runi(",\
		@count, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "normal") {
	if(!ischar(g_random2)) {
		g_random2 <- matread("Gui.dat.txt","g_random2",silent:T)
	}
	@out <- setmdialog(g_random2,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@mean <- @out[2][2]
	@sd <- @out[2][3]
	@variable <- @out[2][4]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(!isnumber(@mean)) {
		alert("Mean is not a number");
		error("Mean is not a number");
	}
	if(!isnumber(@sd)) {
		alert("SD is not a number");
		error("SD is not a number");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, @mean, "+",@sd, "*rnorm(", @count, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "binomial") {
	if(!ischar(g_random3)) {
		g_random3 <- matread("Gui.dat.txt","g_random3",silent:T)
	}
	@out <- setmdialog(g_random3,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@N <- @out[2][2]
	@p <- @out[2][3]
	@variable <- @out[2][4]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(anytrue(!isnumber(@N),vecread(string:@N) <= 0, \
			abs(vecread(string:@N)-round(vecread(string:@N))) > 1e-7)) {
		alert("Sample size is not a positive integer");
		error("Sample size is not a positive integer");
	}
	if(anytrue(!isnumber(@p),vecread(string:@p) < 0, \
			vecread(string:@p) > 1)) {
		alert("P is not a number between 0 and 1");
		error("P is not a number between 0 and 1");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "rbin(", @count, ",", @N, ",", @p, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "poisson") {
	if(!ischar(g_random4)) {
		g_random4 <- matread("Gui.dat.txt","g_random4",silent:T)
	}
	@out <- setmdialog(g_random4,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@mean <- @out[2][2]
	@variable <- @out[2][3]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(anytrue(!isnumber(@mean),vecread(string:@mean) < 0)) {
		alert("Mean is not positive");
		error("Mean is not positive");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "rpoi(", @count, ",", @mean, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "F") {
	if(!ischar(g_random5)) {
		g_random5 <- matread("Gui.dat.txt","g_random5",silent:T)
	}
	@out <- setmdialog(g_random5,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@numdf <- @out[2][2]
	@dendf <- @out[2][3]
	@variable <- @out[2][4]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(anytrue(!isnumber(@numdf),vecread(string:@numdf) <= 0)) {
		alert("Numerator df is not positive");
		error("Numerator df is not positive");
	}
	if(anytrue(!isnumber(@dendf),vecread(string:@dendf) <= 0)) {
		alert("Denominator df is not positive");
		error("Denominator df is not positive");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "invF(runi(", @count, "),", @numdf, ",", @dendf, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "beta") {
	if(!ischar(g_random6)) {
		g_random6 <- matread("Gui.dat.txt","g_random6",silent:T)
	}
	@out <- setmdialog(g_random6,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@alpha1 <- @out[2][2]
	@alpha2 <- @out[2][3]
	@variable <- @out[2][4]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(anytrue(!isnumber(@alpha1),vecread(string:@alpha1) <= 0)) {
		alert("First power is not positive");
		error("First power is not positive");
	}
	if(anytrue(!isnumber(@alpha2),vecread(string:@alpha2) <= 0)) {
		alert("Second power is not positive");
		error("Second power is not positive");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "invbeta(runi(", @count, "),", @alpha1, ",", @alpha2, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "student") {
	if(!ischar(g_random7)) {
		g_random7 <- matread("Gui.dat.txt","g_random7",silent:T)
	}
	@out <- setmdialog(g_random7,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@df <- @out[2][2]
	@variable <- @out[2][3]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(anytrue(!isnumber(@df),vecread(string:@df) <= 0)) {
		alert("Df is not positive");
		error("Df is not positive");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "invstu(runi(", @count, "),", @df, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "chisq") {
	if(!ischar(g_random8)) {
		g_random8 <- matread("Gui.dat.txt","g_random8",silent:T)
	}
	@out <- setmdialog(g_random8,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@df <- @out[2][2]
	@variable <- @out[2][3]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(anytrue(!isnumber(@df),vecread(string:@df) <= 0)) {
		alert("Df is not positive");
		error("Df is not positive");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "invchi(runi(", @count, "),", @df, ")")
	pushcommand(@command)
	return(NULL)
}
if(@dist == "gamma") {
	if(!ischar(g_random9)) {
		g_random9 <- matread("Gui.dat.txt","g_random9",silent:T)
	}
	@out <- setmdialog(g_random9,"random_dialog")
	if(isnull(@out)) {
		error("Random data cancelled")
	}
	@count <- @out[2][1]
	@df <- @out[2][2]
	@variable <- @out[2][3]
	if(anytrue(!isnumber(@count),vecread(string:@count) <= 0, \
			abs(vecread(string:@count)-round(vecread(string:@count))) > 1e-7)) {
		alert("Variable count is not a positive integer");
		error("Variable count is not a positive integer");
	}
	if(anytrue(!isnumber(@df),vecread(string:@df) <= 0)) {
		alert("Df is not positive");
		error("Df is not positive");
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "invgamma(runi(", @count, "),", @df, ")")
	pushcommand(@command)
	return(NULL)
}
%guirandom%


====> guireadfile <====
guireadfile MACRO DOLLARS
# types are "matread", "matread/datafile", "vecread", "readdata/labelled", "readdata/unlabelled",
#           "vecread/matrix", "readdata/unlabelled/ragged", "readdata/labelled/ragged"
@useclip <- keyvalue($K,"useclip","logic scalar",default:F)
@readtype <- keyvalue($K,"type","char scalar",default:"matread")
if(!@useclip && @readtype != "matread/datafile") {
	@filename <- getfilename(type:"text")
	if(isnull(@filename)) {
		error("Data read cancelled")
	}
	if(@filename == "") {
		alert("No file selected")
		error("No file selected")
	}
}
if(@readtype == "matread") {
	if(!ischar(g_readfile1)) {
		g_readfile1 <- matread("Gui.dat.txt","g_readfile1",silent:T)
	}
	@out <- setmdialog(g_readfile1,"readfile1")
	if(isnull(@out)) {
		error("Data read cancelled")
	}
	@dataset <- @out[2][1]
	@variable <- ""
	if(@out[2][3] == "Selected") {
		@variable <- @dataset
	} elseif (@out[2][4] == "Selected") {
		@variable <- @out[2][5]
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	if(@useclip) {
		@command <- paste(@command, "matread(string:CLIPBOARD", sep:"")
	} else {
		@command <- paste(@command, "matread(\"", @filename, "\"", sep:"")
	}
	if(@dataset != "") {
		@command <- paste(@command, ",\"", @dataset, "\"",sep:"")
	}
	@command <- paste(@command,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@readtype == "matread/datafile") {
	if(!ischar(g_readfile1)) {
		g_readfile1 <- matread("Gui.dat.txt","g_readfile1",silent:T)
	}
	@out <- setmdialog(g_readfile1,"readfile1")
	if(isnull(@out)) {
		error("Data read cancelled")
	}
	@dataset <- @out[2][1]
	@variable <- ""
	if(@out[2][3] == "Selected") {
		@variable <- @dataset
	} elseif (@out[2][4] == "Selected") {
		@variable <- @out[2][5]
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	@command <- paste(@command, "getdata(", @dataset, ")", sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@readtype == "vecread") {
	if(!ischar(g_readfile2)) {
		g_readfile2 <- matread("Gui.dat.txt","g_readfile2",silent:T)
	}
	@out <- setmdialog(g_readfile2,"readfile2")
	if(isnull(@out)) {
		error("Data read cancelled")
	}
	@variable <- ""
	if(@out[2][2] == "Selected") {
		@variable <- @out[2][3]
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	if(@useclip) {
		@command <- paste(@command, "vecread(string:CLIPBOARD)", sep:"")
	} else {
		@command <- paste(@command, "vecread(\"", @filename, "\")", sep:"")
	}
	pushcommand(@command)
	return(NULL)
}
if(@readtype == "vecread/matrix") {
	if(!ischar(g_readfile3)) {
		g_readfile3 <- matread("Gui.dat.txt","g_readfile3",silent:T)
	}
	@out <- setmdialog(g_readfile3,"readfile3")
	if(isnull(@out)) {
		error("Data read cancelled")
	}
	@variable <- ""
	if(@out[2][2] == "Selected") {
		@variable <- @out[2][3]
	}
	if(alltrue(@variable != "",!isname(@variable))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	if(@out[2][4] == "Selected") {
		@ncols <- vecread(string:@out[2][5])[1]
		@trans <- "'"
	} else {
		@ncols <- vecread(string:@out[2][7])[1]
		@trans <- ""
	}
	@command <- ""
	if(@variable != "") {
		@command <- paste(@variable, "<-")
	}
	if(@useclip) {
		@command <- paste(@command, "matrix(vecread(string:CLIPBOARD),",@ncols,")",sep:"")
	} else {
		@command <- paste(@command, "matrix(vecread(\"", @filename, "\"),",@ncols,")",sep:"")
	}
	@command <- paste(@command,@trans,sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@readtype == "readdata/unlabelled") {
	if(!ischar(g_readfile4)) {
		g_readfile4 <- matread("Gui.dat.txt","g_readfile4",silent:T)
	}
	@out <- setmdialog(g_readfile4,"readfile4")
	if(isnull(@out)) {
		error("Data read cancelled")
	}
	@vars <- vecread(string:@out[2][1],bywords:T,silent:T)
	if(isnull(@vars)) {
		alert("No variable names specified")
		error("No variable names specified")
	}
	@nvars <- length(@vars)
	for(@i,run(@nvars)) {
		if(!isname(@vars[@i])) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
	}
	@command <- ""
	if(@useclip) {
		@command <- paste(@command, "readdata(string:CLIPBOARD", sep:"")
	} else {
		@command <- paste(@command, "readdata(\"", @filename, "\"", sep:"")
	}
	for(@i,run(@nvars)) {
		@command <- paste(@command,",",@vars[@i],sep:"")
	}
	@command <- paste(@command,")")
	pushcommand(@command)
	return(NULL)
}
if(@readtype == "readdata/labelled") {
	@command <- ""
	if(@useclip) {
		@command <- paste(@command, "readdata(string:CLIPBOARD)", sep:"")
	} else {
		@command <- paste(@command, "readdata(\"", @filename, "\")", sep:"")
	}
	pushcommand(@command)
	return(NULL)
}
%guireadfile%

====> guirsample <====
guirsample MACRO DOLLARS
if(!ischar(g_rsample)) {
	g_rsample <- matread("Gui.dat.txt","g_rsample",silent:T)
}
@out <- setmdialog(g_rsample,"rsample_dialog")
if(isnull(@out)) {
	error("Subsampled data cancelled")
}
@invar <- @out[2][1]
@n <- vecread(string:@out[2][2])[1]
@withrepl <- (@out[2][3] == "checked")
@variable <- @out[2][4]
if(alltrue(@variable != "",!isname(@variable))) {
	alert("Illegal variable name specified")
	error("Illegal variable name specified")
}
@command <- paste("rsample(",@invar,",",@n,",")
if(@withrepl) {
	@command <- paste(@command,"T)")
} else {
	@command <- paste(@command,"F)")
}
if(@variable != "") {
	@command <- paste(@variable, "<-", @command)
}
pushcommand(@command)
return(NULL)
%guirsample%


====> guitypein <====
guitypein MACRO DOLLARS
if(!ischar(g_typein)) {
	g_typein <- matread("Gui.dat.txt","g_typein",silent:T)
}
@out <- setmdialog(g_typein,"typein_dialog")
if(isnull(@out)) {
	error("Type in data cancelled")
}
@content <- @out[2][1]
@variable <- @out[2][2]
if(alltrue(@variable != "",!isname(@variable))) {
	alert("Illegal variable name specified")
	error("Illegal variable name specified")
}
@command <- ""
if(@variable != "") {
	@command <- paste(@variable, "<-")
}
@command <- paste(@command, "vecread(string:\"", @content, "\")",sep:"")
pushcommand(@command)
return(NULL)
%guitypein%


guibasicstat MACRO DOLLARS
# options are "descriptive", "tval", "t2val", "zval",
# "z2val", "tint", "t2int", "propval", "prop2val",
# "propint", "prop2int", "stemleaf", "correlation"
@what <- keyvalue($K,"what","char scalar",default:"descriptive")
if(@what == "descriptive") {
	if(!ischar(g_descriptv)) {
		g_descriptv <- matread("Gui.dat.txt","g_descriptv",silent:T)
	}
	@varxml <- guilistctrl(usereal:T,usestruc:T,maxselect:1,\
		attrns1d:T,attrns2d:T,attrnsstrc:F,attrsystem:F)
	@thisxml <- replacestr(g_descriptv,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"descriptv")
	if(isnull(@out)) {
		#alert("Descriptive statistics cancelled")
		error("Descriptive statistics cancelled")
	}
	if(@out[2][25]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	if(sum((@out[2][run(6,24)])[-3]=="checked") ==0) {
		alert("No statistics selected")
		error("No statistics selected")
	}
	@outvar <- ""
	if(@out[2][2] == "Selected") {
		@outvar <- @out[2][3]
	}
	if(alltrue(@outvar != "",!isname(@outvar))) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@varind <- vecread(string:@out[2][25])+1
	@whichstat <- @out[2][run(8,24)] == "checked"
	if(@out[2][6] == "checked") {
		@whichstat[vector(2,3,4,6,7,8,9,10)] <- T
	}
	if(@out[2][7] == "checked") {
		@whichstat <- rep(T,17)
	}
	@statind <- run(17)[@whichstat]
	@stats <- vector("excludeM:T","n:T","mean:T","var:T","stddev:T",\
		"min:T","q1:T","median:T","q3:T","max:T","iqr:T","range:T",\
		"m2:T","m3:T","m4:T","g1:T","g4:T")
	@usedstats <- paste(@stats[@statind],sep:",")
	@command <- paste("descriptive(",@varxml$vars[@varind[1]],sep:"")
	if(length(@varind) > 1) {
		for(@i,run(2,length(@varind))) {
			@command <- paste(@command,",",@varxml$vars[@varind[@i]],sep:"")
		}
	}
	@command <- paste(@command,",",@usedstats,")",sep:"")
	if(@outvar != "") {
		@command <- paste(@outvar,@command,sep:" <- ")
	}
	pushcommand(@command)
}
if(@what == "stemleaf") {
	if(!ischar(g_stemleaf)) {
		g_stemleaf <- matread("Gui.dat.txt","g_stemleaf",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:1)
	@thisxml <- replacestr(g_stemleaf,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"stemleaf")
	if(isnull(@out)) {
		error("Stem-leaf cancelled")
	}
	if(@out[2][7]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][7])+1
	if(length(@which) > 1) {
		alert("More than one variable selected")
		error("More than one No variable selected")
	}
	@command <- paste("stemleaf(",@varxml$vars[@which],sep:"")
	@stems <- vecread(string:@out[2][3])[1]
	if(@out[2][2]=="Selected") {
		@command <- paste(@command,",",@stems,sep:"")
	}
	if(@out[2][4] == "checked") {
		@command <- paste(@command,",outliers:F",sep:"")
	}
	if(@out[2][5] == "checked") {
		@command <- paste(@command,",depth:F",sep:"")
	}
	if(@out[2][6] == "checked") {
		@command <- paste(@command,",stats:T",sep:"")
	}
	@command <- paste(@command,")",sep:"")
	pushcommand(@command)
}
if(@what == "correlation") {
	if(!ischar(g_cor)) {
		g_cor <- matread("Gui.dat.txt","g_cor",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,attrns1d:T,\
		attrns2d:T,attrsystem:F)
	@thisxml <- replacestr(g_cor,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"cor")
	if(isnull(@out)) {
		error("Correlation cancelled")
	}
	if(@out[2][1]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][1])+1
	@command <- paste("cor(",@varxml$vars[@which[1]],sep:"")
	if(length(@which) > 1) {
		for(@i,run(2,length(@which))) {
			@command <- paste(@command,",",@varxml$vars[@which[@i]],sep:"")
		}
	}
	@command <- paste(@command,")",sep:"")
	pushcommand(@command)
}
if(@what == "tval") {
	if(!ischar(g_tval)) {
		g_tval <- matread("Gui.dat.txt","g_tval",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:1)
	@thisxml <- replacestr(g_tval,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"tval")
	if(isnull(@out)) {
		error("T-test cancelled")
	}
	if(@out[2][8]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][8])+1
	if(length(@which) > 1) {
		alert("More than one variable selected")
		error("More than one No variable selected")
	}
	if(!isnumber(@out[2][4])) {
		alert("Null value not numeric")
		error("Null value not numeric")
	}
	@command <- paste("ttest(",@varxml$vars[@which],sep:"")
	@command <- paste(@command,",null:",@out[2][4],sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",uppertail:T)",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T)",sep:"")
	}
	if(@out[2][6] == "Selected") {
		@savevar <- @out[2][7]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "t2val") {
	if(!ischar(g_t2val)) {
		g_t2val <- matread("Gui.dat.txt","g_t2val",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:2)
	@thisxml <- replacestr(g_t2val,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"t2val")
	if(isnull(@out)) {
		error("T-test cancelled")
	}
	if(@out[2][9]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][9])+1
	if(length(@which) != 2) {
		alert("You must select two variables")
		error("You must select two variables")
	}
	if(!isnumber(@out[2][4])) {
		alert("Null value not numeric")
		error("Null value not numeric")
	}
	@command <- paste("ttest(",@varxml$vars[@which[1]],",",\
		@varxml$vars[@which[2]],sep:"")
	@command <- paste(@command,",null:",@out[2][4],sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",uppertail:T",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T",sep:"")
	}
	if(@out[2][5] == "checked") {
		@command <- paste(@command,",pooled:T)",sep:"")
	} else {
		@command <- paste(@command,",pooled:F)",sep:"")
	} 
	if(@out[2][7] == "Selected") {
		@savevar <- @out[2][8]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "zval") {
	if(!ischar(g_zval)) {
		g_zval <- matread("Gui.dat.txt","g_zval",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:1)
	@thisxml <- replacestr(g_zval,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"zval")
	if(isnull(@out)) {
		error("Z-test cancelled")
	}
	if(@out[2][9]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][9])+1
	if(length(@which) > 1) {
		alert("More than one variable selected")
		error("More than one No variable selected")
	}
	if(!isnumber(@out[2][4])) {
		alert("Null value not numeric")
		error("Null value not numeric")
	}
	if(!isnumber(@out[2][5])) {
		alert("Variance not numeric")
		error("Variance not numeric")
	}
	@var <- vecread(string:@out[2][5])
	if(@var <= 0) {
		alert("Variance not positive")
		error("Variance not positive")
	}
	@command <- paste("ztest(",@varxml$vars[@which],sep:"")
	@command <- paste(@command,",null:",@out[2][4],sep:"")
	@command <- paste(@command,",var:",@out[2][5],sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",uppertail:T)",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T)",sep:"")
	}
	if(@out[2][7] == "Selected") {
		@savevar <- @out[2][8]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "z2val") {
	if(!ischar(g_z2val)) {
		g_z2val <- matread("Gui.dat.txt","g_z2val",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:2)
	@thisxml <- replacestr(g_z2val,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"z2val")
	if(isnull(@out)) {
		error("Z-test cancelled")
	}
	if(@out[2][10]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][10])+1
	if(length(@which) != 2) {
		alert("Two variables needed in z-test")
		error("Two variables needed in z-test")
	}
	if(!isnumber(@out[2][4])) {
		alert("Null value not numeric")
		error("Null value not numeric")
	}
	if(!isnumber(@out[2][5])) {
		alert("First variance not numeric")
		error("First variance not numeric")
	}
	@var1 <- vecread(string:@out[2][5])
	if(@var1 <= 0) {
		alert("First variance not positive")
		error("First variance not positive")
	}
	if(!isnumber(@out[2][6])) {
		alert("Second variance not numeric")
		error("Second variance not numeric")
	}
	@var2 <- vecread(string:@out[2][6])
	if(@var2 <= 0) {
		alert("Second variance not positive")
		error("Second variance not positive")
	}
	@command <- paste("ztest(",@varxml$vars[@which[1]],",",\
		@varxml$vars[@which[2]],sep:"")
	@command <- paste(@command,",null:",@out[2][4],sep:"")
	@command <- paste(@command,",var:vector(",@var1,\
		",",@var2,")",sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",uppertail:T)",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T)",sep:"")
	}
	if(@out[2][8] == "Selected") {
		@savevar <- @out[2][9]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "propval") {
	if(!ischar(g_propval)) {
		g_propval <- matread("Gui.dat.txt","g_propval",silent:T)
	}
	@varxml <- guilistctrl(reqbinary:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:1)
	@thisxml <- replacestr(g_propval,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"propval")
	if(isnull(@out)) {
		error("Test of proportions cancelled")
	}
	if(@out[2][9] == "Selected") {
		@succ <- @out[2][10]
		@trials <- @out[2][11]
		if(!isnumber(@succ)) {
			alert("Number of successes is non-numeric")
			error("Number of successes is non-numeric")
		}
		if(!isnumber(@trials)) {
			alert("Number of trials is non-numeric")
			error("Number of trials is non-numeric")
		}
		@trials <- vecread(string:@trials)
		if(@trials <=0 || (round(@trials) != @trials)) {
			alert("Number of trials must be a positive integer")
			error("Number of trials must be a positive integer")
		}
		@succ <- vecread(string:@succ)
		if(@succ < 0 || @succ > @trials || round(@succ) != @succ) {
			alert("Number of successes must be an integer between 0 and number of trials")
			error("Number of successes must be an integer between 0 and number of trials")
		}
		@command <- paste("proptest(",@succ,",",@trials,sep:"")
	} else {
		if(@out[2][13]=="") {
			alert("No variable selected")
			error("No variable selected")
		}
		@which <- vecread(string:@out[2][13])+1
		@command <- paste("proptest(",@varxml$vars[@which],sep:"")
	}
	if(!isnumber(@out[2][4])) {
		alert("Null value not numeric")
		error("Null value not numeric")
	}
	@null <- vecread(string:@out[2][4])
	if(@null < 0 || @null > 1) {
		alert("Null value must be between 0 and 1")
		error("Null value must be between 0 and 1")
	}
	@command <- paste(@command,",null:",@null,sep:"")
	if(@out[2][5] == "checked") {
		@command <- paste(@command,",contcor:T",sep:"")
	} else {
		@command <- paste(@command,",contcor:F",sep:"")
	}
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",uppertail:T)",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T)",sep:"")
	}
	if(@out[2][7] == "Selected") {
		@savevar <- @out[2][8]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command,sep:"")
	}
	pushcommand(@command)
}
if(@what == "prop2val") {
	if(!ischar(g_prop2val)) {
		g_prop2val <- matread("Gui.dat.txt","g_prop2val",silent:T)
	}
	@varxml <- guilistctrl(reqbinary:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:2)
	@thisxml <- replacestr(g_prop2val,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"prop2val")
	if(isnull(@out)) {
		error("Test of proportions cancelled")
	}
	if(@out[2][9] == "Selected") {
		@succ1 <- @out[2][10]
		@trials1 <- @out[2][11]
		if(!isnumber(@succ1)) {
			alert("Number of successes must be numeric")
			error("Number of successes must be numeric")
		}
		if(!isnumber(@trials1)) {
			alert("Number of trials must be numeric")
			error("Number of trials must be numeric")
		}
		@trials1 <- vecread(string:@trials1)
		if(@trials1 <=0 || (round(@trials1) != @trials1)) {
			alert("Number of trials must be a positive integer")
			error("Number of trials must be a positive integer")
		}
		@succ1 <- vecread(string:@succ1)
		if(@succ1 < 0 || @succ1 > @trials1 || round(@succ1) != @succ1) {
			alert("Number of successes must be an integer between 0 and number of trials")
			error("Number of successes must be an integer between 0 and number of trials")
		}
		@succ2 <- @out[2][12]
		@trials2 <- @out[2][13]
		if(!isnumber(@succ2)) {
			alert("Number of successes must be numeric")
			error("Number of successes must be numeric")
		}
		if(!isnumber(@trials2)) {
			alert("Number of trials must be numeric")
			error("Number of trials must be numeric")
		}
		@trials2 <- vecread(string:@trials2)
		if(@trials2 <=0 || (round(@trials2) != @trials2)) {
			alert("Number of trials must be a positive integer")
			error("Number of trials must be a positive integer")
		}
		@succ2 <- vecread(string:@succ2)
		if(@succ2 < 0 || @succ2 > @trials2 || round(@succ2) != @succ2) {
			alert("Number of successes must be an integer between 0 and number of trials")
			error("Number of successes must be an integer between 0 and number of trials")
		}
		@command <- paste("proptest(",@succ1,",",@trials1,",",@succ2,\
			",",@trials2,sep:"")
	} else {
		if(@out[2][15]=="") {
			alert("No variable selected")
			error("No variable selected")
		}
		@which <- vecread(string:@out[2][15])+1
		if(length(@which) != 2) {
			alert("You must select two variables")
			error("You must select two variables")
		}
		@command <- paste("proptest(",@varxml$vars[@which[1]],","\
			,@varxml$vars[@which[2]],sep:"")
	}
	if(@out[2][4] == "checked") {
		@command <- paste(@command,",contcor:T",sep:"")
	} else {
		@command <- paste(@command,",contcor:F",sep:"")
	}
	if(@out[2][5] == "checked") {
		@command <- paste(@command,",pooled:T",sep:"")
	} else {
		@command <- paste(@command,",pooled:F",sep:"")
	}
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",uppertail:T)",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T)",sep:"")
	}
	if(@out[2][7] == "Selected") {
		@savevar <- @out[2][8]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "tint") {
	if(!ischar(g_tint)) {
		g_tint <- matread("Gui.dat.txt","g_tint",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:1)
	@thisxml <- replacestr(g_tint,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"tint")
	if(isnull(@out)) {
		error("T confidence interval cancelled")
	}
	if(@out[2][8]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][8])+1
	if(length(@which) > 1) {
		alert("More than one variable selected")
		error("More than one No variable selected")
	}
	if(!isnumber(@out[2][4])) {
		alert("Coverage value not numeric")
		error("Coverage value not numeric")
	}
	@command <- paste("tinterval(",@varxml$vars[@which],sep:"")
	@command <- paste(@command,",cover:",@out[2][4],sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",lowerb:T)",sep:"")
	} else {
		@command <- paste(@command,",upperb:T)",sep:"")
	}
	if(@out[2][6] == "Selected") {
		@savevar <- @out[2][7]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "t2int") {
	if(!ischar(g_t2int)) {
		g_t2int <- matread("Gui.dat.txt","g_t2int",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:2)
	@thisxml <- replacestr(g_t2int,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"t2int")
	if(isnull(@out)) {
		error("T confidence interval cancelled")
	}
	if(@out[2][9]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][9])+1
	if(length(@which) != 2) {
		alert("You must select two variables")
		error("You must select two variables")
	}
	if(!isnumber(@out[2][4])) {
		alert("Coverage value not numeric")
		error("Coverage value not numeric")
	}
	@command <- paste("tinterval(",@varxml$vars[@which[1]],",",\
		@varxml$vars[@which[2]],sep:"")
	@command <- paste(@command,",cover:",@out[2][4],sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",lowerb:T",sep:"")
	} else {
		@command <- paste(@command,",upperb:T",sep:"")
	}
	if(@out[2][5] == "checked") {
		@command <- paste(@command,",pool:T)",sep:"")
	} else {
		@command <- paste(@command,",pool:F)",sep:"")
	} 
	if(@out[2][7] == "Selected") {
		@savevar <- @out[2][8]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "zint") {
	if(!ischar(g_zint)) {
		g_zint <- matread("Gui.dat.txt","g_zint",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:1)
	@thisxml <- replacestr(g_zint,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"zint")
	if(isnull(@out)) {
		error("Z confidence interval cancelled")
	}
	if(@out[2][9]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][9])+1
	if(length(@which) > 1) {
		alert("More than one variable selected")
		error("More than one variable selected")
	}
	if(!isnumber(@out[2][4])) {
		alert("Confidence value not numeric")
		error("Confidence value not numeric")
	}
	if(!isnumber(@out[2][5])) {
		alert("Variance not numeric")
		error("Variance not numeric")
	}
	@cover <- vecread(string:@out[2][4])
	if(@cover <= 0 || @cover >=1) {
		alert("Coverage not between 0 and 1")
		error("Coverage not between 0 and 1")
	}
	@var <- vecread(string:@out[2][5])
	if(@var <= 0) {
		alert("Variance not positive")
		error("Variance not positive")
	}
	@command <- paste("zinterval(",@varxml$vars[@which],sep:"")
	@command <- paste(@command,",cover:",@out[2][4],sep:"")
	@command <- paste(@command,",var:",@out[2][5],sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",uppertail:T)",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T)",sep:"")
	}
	if(@out[2][7] == "Selected") {
		@savevar <- @out[2][8]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "z2int") {
	if(!ischar(g_z2int)) {
		g_z2int <- matread("Gui.dat.txt","g_z2int",silent:T)
	}
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:2)
	@thisxml <- replacestr(g_z2int,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"z2int")
	if(isnull(@out)) {
		error("Z confidence interval cancelled")
	}
	if(@out[2][10]=="") {
		alert("No variable selected")
		error("No variable selected")
	}
	@which <- vecread(string:@out[2][10])+1
	if(length(@which) != 2) {
		alert("Two variables needed in z-test")
		error("Two variables needed in z-test")
	}
	if(!isnumber(@out[2][4])) {
		alert("Coverage value not numeric")
		error("Coverage value not numeric")
	}
	@cover <- vecread(string:@out[2][4])
	if(@cover <= 0 || @cover >= 1) {
		alert("Coverage rate must be between 0 and 1")
		error("Coverage rate must be between 0 and 1")
	}
	if(!isnumber(@out[2][5])) {
		alert("First variance not numeric")
		error("First variance not numeric")
	}
	@var1 <- vecread(string:@out[2][5])
	if(@var1 <= 0) {
		alert("First variance not positive")
		error("First variance not positive")
	}
	if(!isnumber(@out[2][6])) {
		alert("Second variance not numeric")
		error("Second variance not numeric")
	}
	@var2 <- vecread(string:@out[2][6])
	if(@var2 <= 0) {
		alert("Second variance not positive")
		error("Second variance not positive")
	}
	@command <- paste("zinterval(",@varxml$vars[@which[1]],",",\
		@varxml$vars[@which[2]],sep:"")
	@command <- paste(@command,",cover:",@out[2][4],sep:"")
	@command <- paste(@command,",var:vector(",@var1,\
		",",@var2,")",sep:"")
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",lowerb:T)",sep:"")
	} else {
		@command <- paste(@command,",upperb:T)",sep:"")
	}
	if(@out[2][8] == "Selected") {
		@savevar <- @out[2][9]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "propint") {
	if(!ischar(g_propint)) {
		g_propint <- matread("Gui.dat.txt","g_propint",silent:T)
	}
	@varxml <- guilistctrl(reqbinary:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:1)
	@thisxml <- replacestr(g_propint,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"propint")
	if(isnull(@out)) {
		error("Test of proportions cancelled")
	}
	if(@out[2][9] == "Selected") {
		@succ <- @out[2][10]
		@trials <- @out[2][11]
		if(!isnumber(@succ)) {
			alert("Number of successes is non-numeric")
			error("Number of successes is non-numeric")
		}
		if(!isnumber(@trials)) {
			alert("Number of trials is non-numeric")
			error("Number of trials is non-numeric")
		}
		@trials <- vecread(string:@trials)
		if(@trials <=0 || (round(@trials) != @trials)) {
			alert("Number of trials must be a positive integer")
			error("Number of trials must be a positive integer")
		}
		@succ <- vecread(string:@succ)
		if(@succ < 0 || @succ > @trials || round(@succ) != @succ) {
			alert("Number of successes must be an integer between 0 and number of trials")
			error("Number of successes must be an integer between 0 and number of trials")
		}
		@command <- paste("propinterval(",@succ,",",@trials,sep:"")
	} else {
		if(@out[2][13]=="") {
			alert("No variable selected")
			error("No variable selected")
		}
		@which <- vecread(string:@out[2][13])+1
		@command <- paste("propinterval(",@varxml$vars[@which],sep:"")
	}
	if(!isnumber(@out[2][4])) {
		alert("Coverage rate not numeric")
		error("Coverage rate not numeric")
	}
	@cover <- vecread(string:@out[2][4])
	if(@cover <= 0 || @cover >= 1) {
		alert("Coverage rate must be between 0 and 1")
		error("Coverage rate must be between 0 and 1")
	}
	@command <- paste(@command,",cover:",@cover,sep:"")
	if(@out[2][5] == "checked") {
		@command <- paste(@command,",plus4:T",sep:"")
	} 
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",lowerb:T)",sep:"")
	} else {
		@command <- paste(@command,",upperb:T)",sep:"")
	}
	if(@out[2][7] == "Selected") {
		@savevar <- @out[2][8]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
if(@what == "prop2int") {
	if(!ischar(g_prop2int)) {
		g_prop2int <- matread("Gui.dat.txt","g_prop2int",silent:T)
	}
	@varxml <- guilistctrl(reqbinary:T,req1d:T,attrns1d:T,\
		attrsystem:F,maxselect:2)
	@thisxml <- replacestr(g_prop2int,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"prop2int")
	if(isnull(@out)) {
		error("Test of proportions cancelled")
	}
	if(@out[2][8] == "Selected") {
		@succ1 <- @out[2][9]
		@trials1 <- @out[2][10]
		if(!isnumber(@succ1)) {
			alert("Number of successes must be numeric")
			error("Number of successes must be numeric")
		}
		if(!isnumber(@trials1)) {
			alert("Number of trials must be numeric")
			error("Number of trials must be numeric")
		}
		@trials1 <- vecread(string:@trials1)
		if(@trials1 <=0 || (round(@trials1) != @trials1)) {
			alert("Number of trials must be a positive integer")
			error("Number of trials must be a positive integer")
		}
		@succ1 <- vecread(string:@succ1)
		if(@succ1 < 0 || @succ1 > @trials1 || round(@succ1) != @succ1) {
			alert("Number of successes must be an integer between 0 and number of trials")
			error("Number of successes must be an integer between 0 and number of trials")
		}
		@succ2 <- @out[2][11]
		@trials2 <- @out[2][12]
		if(!isnumber(@succ2)) {
			alert("Number of successes must be numeric")
			error("Number of successes must be numeric")
		}
		if(!isnumber(@trials2)) {
			alert("Number of trials must be numeric")
			error("Number of trials must be numeric")
		}
		@trials2 <- vecread(string:@trials2)
		if(@trials2 <=0 || (round(@trials2) != @trials2)) {
			alert("Number of trials must be a positive integer")
			error("Number of trials must be a positive integer")
		}
		@succ2 <- vecread(string:@succ2)
		if(@succ2 < 0 || @succ2 > @trials2 || round(@succ2) != @succ2) {
			alert("Number of successes must be an integer between 0 and number of trials")
			error("Number of successes must be an integer between 0 and number of trials")
		}
		@command <- paste("propinterval(",@succ1,",",@trials1,",",@succ2,\
			",",@trials2,sep:"")
	} else {
		if(@out[2][14]=="") {
			alert("No variable selected")
			error("No variable selected")
		}
		@which <- vecread(string:@out[2][14])+1
		if(length(@which) != 2) {
			alert("You must select two variables")
			error("You must select two variables")
		}
		@command <- paste("propinterval(",@varxml$vars[@which[1]],","\
			,@varxml$vars[@which[2]],sep:"")
	}
	if(@out[2][4] == "checked") {
		@command <- paste(@command,",plus4:T",sep:"")
	} 
	if(@out[2][1]=="Selected") {
		@command <- paste(@command,",twotail:T)",sep:"")
	} elseif (@out[2][2]=="Selected") {
		@command <- paste(@command,",lowerb:T)",sep:"")
	} else {
		@command <- paste(@command,",upperb:T)",sep:"")
	}
	if(@out[2][6] == "Selected") {
		@savevar <- @out[2][7]
		if(!isname(@savevar)) {
			alert("Illegal variable name specified")
			error("Illegal variable name specified")
		}
		@command <- paste(@savevar, "<-", @command)
	}
	pushcommand(@command)
}
%guibasicstat%



guianova MACRO DOLLARS
# guianova takes no arguments; it does basic anova through dialogs 
if(!ischar(g_anova1)) {
	g_anova1 <- matread("Gui.dat.txt","g_anova1",silent:T)
}
@varxml <- guilistctrl(reqreal:T,req1d:T,attrnonsys:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(g_anova1,"LISTCONTROL",@varxml$xml)
if(isdefined(STRMODEL)) {
	@thisxml <- replacestr(@thisxml,"STRMODEL",STRMODEL)
} else {
	@thisxml <- replacestr(@thisxml,"STRMODEL","no current model")
}
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"anova1")
if(isnull(@out)) {
	error("Anova cancelled")
}
@thismodel <- NULL
@out <- @out[2]
if(@out[5]=="Selected") {
	if(!isdefined(STRMODEL)) {
		alert("No current model")
		error("No current model")
	}
	@thismodel <- STRMODEL
}
@marg <- ""
if(@out[1] == "checked") {
	@marg <- ",marg:T"
}
@pvals <- ",pvals:T"
if(@out[2] != "checked") {
	@pvals <- ",pvals:F"
}
@fstats <- ",fstats:T"
if(@out[3] != "checked") {
	@fstats <- ",fstats:F"
}
@silent <- ""
if(@out[4] == "checked") {
	@silent <- ",silent:T"
}
@varind <- @out[8]
if(isnull(@thismodel) && @varind == "") {
	alert("No response selected")
	error("No response selected")
}
if(@varind != "") {
	@varind <- vecread(string:@varind)+1
	@newy <- @varxml$vars[@varind]
}
@needwts <- F
if(@out[9] == "checked") {
	@needwts <- T
}
@nocoefs <- ""
if(@out[10] == "checked") {
	@nocoefs <- ",coefs:F"
}
@func <- "anova(\""
if(@out[11] == "checked") {
	@func <- "fastanova(\""
}
@unbal <- ""
if(@out[12] == "checked") {
	@unbal <- ",unbal:T"
}
if(isnull(@thismodel)) {
	@n <- length(<<@newy>>)
} else {
	@n <- length(modelinfo(y:T))
}
@wts <- ""
if(@needwts) {
	@wts <- guigetmdlwts(@n)
}
if(!isnull(@thismodel)) {
	@command <- paste(@func,@thismodel,"\"",@wts,@marg,@pvals,@fstats,\
		@silent,@nocoefs,@unbal,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
# here we need to build a new model
@thismodel <- guibldanvmdl(@newy)
@command <- paste(@func,@thismodel,"\"",@wts,@marg,@pvals,\
	@fstats,@silent,@nocoefs,@unbal,")",sep:"")
pushcommand(@command)
return(NULL)
%guianova%


guicoefs MACRO DOLLARS
if(!isdefined(TERMNAMES) || !ischar(TERMNAMES) || !isvector(TERMNAMES)) {
	alert("No active model")
	error("No active model")
}
@tplace <- "<item>All terms</item>"
@tlist <- @tplace
@nterms <- length(TERMNAMES)
for(@i,run(@nterms-1)) {
	@tlist <- paste(@tlist,"<item>",TERMNAMES[@i],"</item>\n",sep:"")
}
@eplace <- "<item>ERROR1</item>"
@elist <- paste("<item>",TERMNAMES[@nterms],"</item>\n",sep:"")
for(@i,run(@nterms-1)) {
	@elist <- paste(@elist,"<item>",TERMNAMES[@i],"</item>\n",sep:"")
}
if(!ischar(g_coefs)) {
	g_coefs <- matread("Gui.dat.txt","g_coefs",silent:T)
}
# do the last one in dialog first
@thisxml <- replacestr(g_coefs,@eplace,@elist)
@thisxml <- replacestr(@thisxml,@tplace,@tlist)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"coefs")
if(isnull(@out)) {
	error("Coefs cancelled")
}
if(@out[2][1] == "") {
	alert("No term chosen")
	error("No term chosen")
}
if(@out[2][1] == "All terms") {
	@command <- "coefs("
} else {
	@command <- paste("coefs(\"",@out[2][1],"\"",sep:"")
}
if(@out[2][2] == "checked") {
	@command <- paste(@command,",se:T",sep:"")
	if(@out[2][3] != "") {
		@command <- paste(@command,",error:\"",@out[2][3],"\"",sep:"")
	}
}
if(@out[2][4] != "checked") {
	@command <- paste(@command,",byterm:F",sep:"")
}
@command <- paste(@command,")",sep:"")
if(@out[2][6] == "Selected") {
	@savevar <- @out[2][7]
	if(!isname(@savevar)) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- paste(@savevar, "<-", @command)
}
pushcommand(@command)
%guicoefs%

guicontrast MACRO DOLLARS
if(!isdefined(TERMNAMES) || !ischar(TERMNAMES) || !isvector(TERMNAMES)) {
	alert("No active model")
	error("No active model")
}
@tplace <- "<item>All terms</item>"
@tlist <- ""
@nterms <- length(TERMNAMES)
for(@i,run(@nterms-1)) {
	@tlist <- paste(@tlist,"<item>",TERMNAMES[@i],"</item>\n",sep:"")
}
@eplace <- "<item>ERROR1</item>"
@elist <- paste("<item>",TERMNAMES[@nterms],"</item>\n",sep:"")
for(@i,run(@nterms-1)) {
	@elist <- paste(@elist,"<item>",TERMNAMES[@i],"</item>\n",sep:"")
}
@bplace <- "<item>No by variable</item>"
@blist <- @bplace
@varlist <- varnames()[-1]
@nvars <- length(@varlist)
for(@i,run(@nvars)) {
	@blist <- paste(@blist,"<item>",@varlist[@i],"</item>\n",sep:"")
}
if(!ischar(g_contrast)) {
	g_contrast <- matread("Gui.dat.txt","g_contrast",silent:T)
}
# do the last one in dialog first
@thisxml <- replacestr(g_contrast,@bplace,@blist)
@thisxml <- replacestr(@thisxml,@eplace,@elist)
@thisxml <- replacestr(@thisxml,@tplace,@tlist)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"contrast")
if(isnull(@out)) {
	error("Contrast cancelled")
}
if(@out[2][1] == "") {
	alert("No term chosen")
	error("No term chosen")
}
@command <- paste("docontrast(\"",@out[2][1],"\"",sep:"")
if(@out[2][14] == "Selected") {
	@command <- paste(@command,",",@out[2][15],sep:"")
} else {
	@command <- paste(@command,",vecread(string:\"",@out[2][17],\
		"\")",sep:"")
}
if(@out[2][3] != "" && @out[2][3] != "No by variable") {
	@command <- paste(@command,",by:\"",@out[2][3],"\"",sep:"")
}
if(@out[2][2] != "") {
	@command <- paste(@command,",error:\"",@out[2][2],"\"",sep:"")
}
if(@out[2][4] == "Selected" || @out[2][5] == "Selected" || \
	@out[2][6] == "Selected") {
	@cover <- @out[2][7]
	if(anytrue(!isnumber(@cover),(@cover <- vecread(string:@cover)) <= 0,\
		@cover >= 1)) {
		alert("Coverage must be between 0 and 1")
		error("Coverage must be between 0 and 1")
	}
	@command <- paste(@command,",coverage:",@cover,sep:"")
	if(@out[2][4] == "Selected") {
		@command <- paste(@command,",twosidedci:T",sep:"")
	} elseif(@out[2][5] == "Selected") {
		@command <- paste(@command,",lowerb:T",sep:"")
	} else {
		@command <- paste(@command,",upperb:T",sep:"")
	}
} else {
	if(@out[2][8] == "Selected") {
		@command <- paste(@command,",twotailedt:T",sep:"")
	} elseif(@out[2][9] == "Selected") {
		@command <- paste(@command,",uppertail:T",sep:"")
	} else {
		@command <- paste(@command,",lowertail:T",sep:"")
	}
}
@command <- paste(@command,")",sep:"")
if(@out[2][12] == "Selected") {
	@savevar <- @out[2][13]
	if(!isname(@savevar)) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- paste(@savevar, "<-", @command)
}
pushcommand(@command)
%guicontrast%


====>guiboxplot<====
guiboxplot MACRO DOLLARS
if(!ischar(g_plotbase)) {
	g_plotbase <- read("Gui.dat.txt","g_plotbase",silent:T)
}
if(!ischar(g_boxplot)) {
	g_boxplot <- read("Gui.dat.txt","g_boxplot",silent:T)
}
if(!ischar(g_helpctrlbs)) {
	g_helpctrlbs <- read("Gui.dat.txt","g_helpctrlbs",silent:T)
}
@thisxml <- replacestr(g_plotbase,"BASICPANEL",g_boxplot)
@varxml <- guilistctrl(usereal:T,usestruc:T,attrns1d:T,attrns2d:T,\
	attrnsstrc:T,attrsystem:F)
@thisxml <- replacestr(@thisxml,"LISTCONTROL",@varxml$xml)
@help <- findfile("docs/html/gui_guiboxplot.htm")
@help <- replacestr(g_helpctrlbs,"HELPFILE",@help)
@thisxml <- replacestr(@thisxml,"HELPCONTROL",@help)
@thisxml <- replacestr(@thisxml,"PLOTTITLE","Box and Whisker Plots")
@thisxml <- replacestr(@thisxml,"PLOTNAME","boxplot")
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"boxplot")[2]
if(@out[11] == "") {
	alert("No variables selected")
	error("No variables selected")
}
@varind <- vecread(string:@out[11]) + 1
@varlist <- @varxml$vars[@varind]
if(length(@varind) > 1) {
	for(@i,run(length(@varind))) {
		if(!isvector(<<@varlist[@i]>>)) {
			alert("You can only use real vectors when using more than one response")
			error("You can only use real vectors when using more than one response")
		}
	}
}
@dosplit <- F
if(@out[3] == "checked") {
	@dosplit <- T
	if(length(@varlist) > 1 || !isvector(<<@varlist[1]>>)) {
		alert("You may only use a split-by variable\n with a single response vector")
		error("You may only use a split-by variable\n with a single response vector")
	}
	if(!isname(@out[4])) {
		alert("Illegal name for by-variable")
		error("Illegal name for by-variable")
	}
}
@command <- "boxplot("
if(isstruc(<<@varlist[1]>>)) {
	@command <- paste(@command,@varlist[1],sep:"")
} elseif(!isvector(<<@varlist[1]>>)) {
	@command <- paste(@command,"split(",@varlist[1],")",sep:"")
} elseif (@dosplit) {
	@command <- paste(@command,"split(",@varlist[1],",",@out[4],")",sep:"")
} else {
	@command <- paste(@command,@varlist[1],sep:"")
	if(length(@varlist) > 1) {
		for(@i,run(2,length(@varlist))) {
			@command <- paste(@command,",",@varlist[@i],sep:"")
		}
	}
}
if(@out[1] == "checked") {
	@command <- paste(@command,",vert:T",sep:"")
}
if(@out[2] != "checked") {
	@command <- paste(@command,",boxtype:2",sep:"")
}
if(@out[5] == "checked") {
	@command <- paste(@command,",boxsize:",@out[6],sep:"")
}
if(@out[8] == "checked") {
	@command <- paste(@command,",vs:",@out[9],sep:"")
}
if(@out[7] == "") {
	@whichfar <- 1
} else {
	@whichfar <- match(@out[7],vector("Diamond","Plus","Square",\
		"Cross","Triangle","Star","Dot","Circle"))
}
if(@out[10] == "") {
	@whichmod <- 6
} else {
	@whichmod <- match(@out[7],vector("Diamond","Plus","Square",\
		"Cross","Triangle","Star","Dot","Circle"))
}
@octal <- vector("\"\\1\"","\"\\2\"","\"\\3\"","\"\\4\"","\"\\5\"","\"\\6\"","\"\\7\"","\"\\10\"")
if(@whichfar != 1 || @whichmod != 6) {
	@command <- paste(@command,",symbols:vector(",@octal[@whichmod],",",\
		@octal[@whichfar],")",sep:"")
}
@command <- paste(@command,@out[44],sep:"")

@appropt <- guiappropt(@out,11)
@axisopt <- guiaxisopt(@out,11+18)
@command <- paste(@command,@appropt,@axisopt,sep:"")
@command <- paste(@command,")",sep:"")
pushcommand(@command)
%guiboxplot%

====>guiaxisopt<====
guiappropt MACRO DOLLARS
@dout <- $1
@offset <- $2
@dout <- @dout[run(18)+@offset]
@out <- ""
if(@dout[2] == "Selected") {
	@wind <- vecread(string:@dout[3])[1]
	@out <- paste(@out,",wind:",@wind,sep:"")
}
@width <- vecread(string:@dout[4])[1]
@height <- vecread(string:@dout[5])[1]
if(@width != 550) {
	@out <- paste(@out,",width:",@width,sep:"")
}
if(@height != 400) {
	@out <- paste(@out,",height:",@height,sep:"")
}
if(@dout[6] != "") {
	@out <- paste(@out,",title:\"",@dout[6],"\"",sep:"")
}
if(@dout[7] != "") {
	@out <- paste(@out,",xlab:\"",@dout[7],"\"",sep:"")
}
if(@dout[8] != "") {
	@out <- paste(@out,",ylab:\"",@dout[8],"\"",sep:"")
}
if(@dout[9] != "checked") {
	@bord <- ""
	if(@dout[11] == "checked") {
		@bord <- paste(@bord,"T")
	}
	if(@dout[13] == "checked") {
		@bord <- paste(@bord,"B")
	}
	if(@dout[15] == "checked") {
		@bord <- paste(@bord,"L")
	}
	if(@dout[17] == "checked") {
		@bord <- paste(@bord,"R")
	}
	if(@bord == "") {
		@bord <- "none"
	}
	@out <- paste(",borders:\"",@bord,"\"",sep:"")
}
if(@dout[10] != "checked") {
	@ticks <- ""
	if(@dout[12] == "checked") {
		@ticks <- paste(@ticks,"T")
	}
	if(@dout[14] == "checked") {
		@ticks <- paste(@ticks,"B")
	}
	if(@dout[16] == "checked") {
		@ticks <- paste(@ticks,"L")
	}
	if(@dout[18] == "checked") {
		@ticks <- paste(@ticks,"R")
	}
	if(@ticks == "") {
		@ticks <- "none"
	}
	@out <- paste(",ticks:\"",@ticks,"\"",sep:"")
}
@out
%guiappropt%

====>guiaxisopt<====
guiaxisopt MACRO DOLLARS
@dout <- $1
@offset <- $2
@dout <- @dout[run(14)+@offset]
@out <- ""
if(@dout[1] == "checked") {
	@out <- paste(@out,",logx:T",sep:"")
}
if(@dout[2] != "") {
	@out <- paste(@out,",xmin:",@dout[2],sep:"")
}
if(@dout[3] != "") {
	@out <- paste(@out,",xmax:",@dout[3],sep:"")
}
if(@dout[4] != "checked") {
	@out <- paste(@out,",xaxis:F",sep:"")
} 
if(@dout[5] != "") {
	@out <- paste(@out,",xticks:",@dout[5],sep:"")
}
if(@dout[6] != "") {
	@out <- paste(@out,",xticklabs:",@dout[6],sep:"")
}
if(@dout[7] != "") {
	@out <- paste(@out,",xticklen:",@dout[7],sep:"")
}
if(@dout[8] == "checked") {
	@out <- paste(@out,",logy:T",sep:"")
}
if(@dout[9] != "") {
	@out <- paste(@out,",ymin:",@dout[9],sep:"")
}
if(@dout[10] != "") {
	@out <- paste(@out,",ymax:",@dout[10],sep:"")
}
if(@dout[11] != "checked") {
	@out <- paste(@out,",yaxis:F",sep:"")
} 
if(@dout[12] != "") {
	@out <- paste(@out,",yticks:",@dout[12],sep:"")
}
if(@dout[13] != "") {
	@out <- paste(@out,",yticklabs:",@dout[13],sep:"")
}
if(@dout[14] != "") {
	@out <- paste(@out,",yticklen:",@dout[14],sep:"")
}
@out
%guiaxisopt%


guirandtest MACRO DOLLARS
if(!ischar(g_randtest)) {
	g_randtest <- matread("Gui.dat.txt","g_randtest",silent:T)
}
@type <- keyvalue($K,"type","char scalar")
@ms <- 1
if(@type == "twosample") {
	@ms <- 2
}
@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,\
attrsystem:F,maxselect:@ms)
@thisxml <- replacestr(g_randtest,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"randtest")[2]
if(isnull(@out)) {
	error("Randomization test cancelled")
}
if(@out[11]=="") {
	alert("No variable selected")
	error("No variable selected")
}
@which <- vecread(string:@out[11])+1
if(length(@which) != @ms) {
	if(@ms == 1) {
		@msg <- "You must select one variable"
	} else {
		@msg <- "You must select two variables"
	}
	alert(@msg)
	error(@msg)
}
@command <- paste("dorandtest(",@varxml$vars[@which[1]],sep:"")
if(@ms == 2) {
	@command <- paste(@command,",",@varxml$vars[@which[2]],sep:"")
}
@command <- paste(@command,",type:\"",@type,"\"",sep:"")
if(@out[5] == "Selected") {
	@nt <- vecread(string:@out[6])[1]
	@command <- paste(@command,",trials:",@nt,sep:"")
}
if(@out[1] == "Selected") {
	@command <- paste(@command,",twotail:T",sep:"")
} elseif(@out[2] == "Selected") {
	@command <- paste(@command,",uppert:T",sep:"")
} else {
	@command <- paste(@command,",lowert:T",sep:"")
}
if(@out[7] == "checked") {
	@command <- paste(@command,",hist:T",sep:"")
}
@command <- paste(@command,")",sep:"")
if(@out[9] == "Selected") {
	@varname <- @out[10]
	if(!isname(@varname)) {
		alert("Illegal variable name chosen")
		error("Illegal variable name chosen")
	}
	@command <- paste(@varname,"<-",@command)
}
pushcommand(@command)
%guirandtest%



guihist MACRO DOLLARS
if(!ischar(g_plotbase)) {
	g_plotbase <- read("Gui.dat.txt","g_plotbase",silent:T)
}
if(!ischar(g_hist)) {
	g_hist <- read("Gui.dat.txt","g_hist",silent:T)
}
if(!ischar(g_helpctrlbs)) {
	g_helpctrlbs <- read("Gui.dat.txt","g_helpctrlbs",silent:T)
}
@thisxml <- replacestr(g_plotbase,"BASICPANEL",g_hist)
@varxml <- guilistctrl(reqreal:T,req1d:T,attrns1d:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(@thisxml,"LISTCONTROL",@varxml$xml)
@help <- findfile("docs/html/gui_guihist.htm")
@help <- replacestr(g_helpctrlbs,"HELPFILE",@help)
@thisxml <- replacestr(@thisxml,"HELPCONTROL",@help)
@thisxml <- replacestr(@thisxml,"PLOTTITLE","Histogram")
@thisxml <- replacestr(@thisxml,"PLOTNAME","hist")
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"hist")[2]
if(@out[15] == "") {
	alert("No variable selected")
	error("No variable selected")
}
@varind <- vecread(string:@out[15]) + 1
@varlist <- @varxml$vars[@varind]
@command <- paste("hist(",@varlist,sep:"")
@dosplit <- F
if(@out[5] == "Selected") {
	@nbin <- vecread(string:@out[6])[1]
	@command <- paste(@command,",",@nbin,sep:"")
}
if(@out[7] == "Selected") {
	@anc <- @out[8]
	if(!isnumber(@anc)) {
		alert("Bin anchor must be a number")
		error("Bin anchor must be a number")
	}
	@wid <- @out[9]
	if(!isnumber(@wid)) {
		alert("Bin width must be a number")
		error("Bin width must be a number")
	}
	@command <- paste(@command,",vector(",@anc,",",@wid,")",sep:"")
}
if(@out[10] == "Selected") {
	@command <- paste(@command,",",@out[11],sep:"")
}
if(@out[2] == "Selected") {
	@command <- paste(@command,",relfreq:T",sep:"")
}
if(@out[3] == "Selected") {
	@command <- paste(@command,",freq:T",sep:"")
}
if(@out[14] == "Selected") {
	@command <- paste(@command,",leftendin:T",sep:"")
}
if(@out[12] == "checked") {
	@command <- paste(@command,",outsideok:T",sep:"")
}
@command <- paste(@command,@out[48],sep:"")
@appropt <- guiappropt(@out,15)
@axisopt <- guiaxisopt(@out,15+18)
@command <- paste(@command,@appropt,@axisopt,sep:"")

@command <- paste(@command,")",sep:"")
pushcommand(@command)
%guihist%

guiplotresid MACRO DOLLARS
if(!ischar(g_plotbase)) {
        g_plotbase <- matread("Gui.dat.txt","g_plotbase",silent:T)
}
if(!ischar(g_plotres)) {
        g_plotres <- matread("Gui.dat.txt","g_plotres",silent:T)
}
if(!ischar(g_helpctrlbs)) {
        g_helpctrlbs <- read("Gui.dat.txt","g_helpctrlbs",silent:T)
}
@thisxml <- replacestr(g_plotbase,"BASICPANEL",g_plotres)
@help <- findfile("docs/html/gui_guiplotresid.htm")
@help <- replacestr(g_helpctrlbs,"HELPFILE",@help)
@thisxml <- replacestr(@thisxml,"HELPCONTROL",@help)
@thisxml <- replacestr(@thisxml,"PLOTTITLE","Residual Plots")
@thisxml <- replacestr(@thisxml,"PLOTNAME","plotres")
thisxml <- @thisxml
write(thisxml,file:"tmpjunk",new:T)
@out <- setmdialog(@thisxml,"plotres")
if(isnull(@out)) {
        error("Residual plot cancelled")
}
@out <- @out[2]
@doyhat <- @dorankits <- @doindex <- F
if(@out[1] == "checked") {
	@doyhat <- T
}
if(@out[2] == "checked") {
	@dorankits <- T
}
if(@out[3] == "checked") {
	@doindex <- T
}
if((@doyhat + @dorankits + @doindex) == 0) {
	alert("You must select at least one kind of plot")
	error("You must select at least one kind of plot")
}
@types <- vector("\"yhat\"","\"rankits\"","\"index\"")[vector(@doyhat,@dorankits,@doindex)]
if(length(@types) > 1) {
	@types <- paste("vector(",paste(@types,sep:","),")",sep:"")
}
@symb <- match(@out[4],vector("Diamond","Plus","Square",\
                "Cross","Triangle","Star","Dot","Circle","Case number"),8)
if(@symb == 9) {
	@symb <- "\"###\""
} else {
	@size <- (match(@out[5],vector("Large","Medium","Small"),3)-1)*8
	@symb <- @symb+@size
	@symb <- paste("\"\\",floor(@symb/8),@symb %% 8,"\"",sep:"")
}
@whatres <- "\"raw\""
if(@out[7] == "Selected") {
	@whatres <- "\"scaled\""
} elseif(@out[8] == "Selected") {
	@whatres <- "\"standardized\""
} elseif(@out[9] == "Selected") {
	@whatres <- "\"studentized\""
}
@command <- paste("plotresids(",@whatres,",",@types,",symbol:",@symb,sep:"")
@command <- paste(@command,@out[42],sep:"")
@appropt <- guiappropt(@out,9)
@axisopt <- guiaxisopt(@out,9+18)
@command <- paste(@command,@appropt,@axisopt,sep:"")

@command <- paste(@command,")")
pushcommand(@command)
%guiplotresid%


guiglmtable MACRO DOLLARS
if(!isdefined(TERMNAMES)) {
	alert("No active model")
	error("No active model")
}
if(!ischar(g_glmtable)) {
	g_glmtable <- read("Gui.dat.txt","g_glmtable",silent:T)
}
@vars <- varnames()[-1]
@factors <- NULL
for(@i,run(length(@vars))) {
	if(isfactor(<<@vars[@i]>>)) {
		@factors <- vector(@factors,@i)
	}
}
@nvarts <- length(@vars)-length(@factors)
@varts <- @vars[-@factors]
@nfactors <- length(@factors)
@factors <- @vars[@factors]
if(@nvarts == 0) {
	@thisxml <- replacestr(g_glmtable,"VARIATEVALUES","No Variates in Model")
} else {
	@tmp <- paste(@nvarts,"Variate(s) in Model")
	@thisxml <- replacestr(g_glmtable,"VARIATEVALUES",@tmp)
}
@varxml <- guilistctrl(useonly:@factors)
@thisxml <- replacestr(@thisxml,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"glmtable")[2]
@command <- "glmtable("
if(@out[12] == "Selected") {
	if(@out[13] == "") {
		alert("No factors selected")
		error("No factors selected")
	}
	@varind <- vecread(string:@out[13])+1
	@term <- paste(@varxml$vars[@varind],sep:"")
	@command <- paste(@command,"\"",@term,"\"",sep:"")
}
if(@out[2] == "Selected") {
	@command <- paste(@command,",wtdmeans:T",sep:"")
}
if(@out[3] == "Selected") {
	@command <- paste(@command,",x:",@out[4],sep:"")
}
if(@out[5] != "checked") {
	@command <- paste(@command,",estimate:F",sep:"")
}
if(@out[6] != "checked") {
	@command <- paste(@command,",seest:F",sep:"")
}
if(@out[7] == "checked") {
	@command <- paste(@command,",sepred:T",sep:"")
}
@command <- paste(@command,")",sep:"")
if(@out[9] == "Selected") {
	if(!isname(@out[10])) {
		alert("Illegal save variable name")
		error("Illegal save variable name")
	}
	@command <- paste(@out[10],"<-",@command)
}
pushcommand(@command)
%guiglmtable%



guitabs MACRO DOLLARS
if(!ischar(g_tabs)) {
		g_tabs <- matread("Gui.dat.txt","g_tabs",silent:T)
}
@varxml <- guilistctrl(usereal:T,uselogic:T,matchrows:T,\
	attrns1d:T,attrns2d:T,attrsystem:F)
@thisxml <- replacestr(g_tabs,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"tabs")
if(isnull(@out)) {
	error("Tabular summaries cancelled")
}
@out <- @out[2]
if(@out[16]=="") {
	alert("No variables selected")
	error("No variables selected")
}
@varind <- vecread(string:@out[16])+1
@varlist <- paste(@varxml$vars[@varind],sep:",")
if(sum((@out[run(4,15)])=="checked") == 0) {
	alert("No statistics selected")
	error("No statistics selected")
}
@whichstat <- @out[run(7,15)] == "checked"
if(@out[5] == "checked") {
	@whichstat[run(3)] <- T
}
if(@out[6] == "checked") {
	@whichstat <- rep(T,9)
}
@nonly <- F
if(@out[4] == "checked") {
	@nonly <- T
}
@statind <- run(9)[@whichstat]
@stats <- vector(",n:T",",mean:T",",var:T",",stddev:T",\
	",min:T",",max:T",",sum:T",",prod:T",",covar:T")
@usedstats <- paste(@stats[@statind],sep:"")
if(@nonly || sum(@whichstat == rep(vector(T,F),vector(3,6))) == 9) {
	# no statistics or usual statistics
	@usedstats <- ""
}
@command <- "tabs("
if(@nonly) {
	@command <- paste(@command,",",sep:"")
}
@command <- paste(@command,@varlist,@usedstats,")",sep:"")
if(@out[2] == "Selected") {
	@outvar <- @out[3]
	if(!isname(@outvar)) {
		alert("Illegal variable name specified")
		error("Illegal variable name specified")
	}
	@command <- paste(@outvar,@command,sep:" <- ")
}
pushcommand(@command)
%guitabs%



guipairwise MACRO DOLLARS
if(!isdefined(TERMNAMES) || !ischar(TERMNAMES) || !isvector(TERMNAMES)) {
	alert("No active model")
	error("No active model")
}
@fplace <- "<item>FACTORS</item>"
@vnames <- varnames()[-1]
@nnames <- length(@vnames)
for(@i,run(@nnames,1)) {
	if(anytrue(!isname(@vnames[@i]),!isdefined(@vnames[@i]),\
	  !isfactor(<<@vnames[@i]>>))) {
		@vnames <- @vnames[-@i]
	}
}
if(isnull(@vnames)) {
	alert("No factors in model")
	error("No factors in model")
}
@flist <- ""
for(@i,run(length(@vnames))) {
	@flist <- paste(@flist,"<item>",@vnames[@i],"</item>\n",sep:"")
}
@eplace <- "<item>ERROR1</item>"
@nterms <- length(TERMNAMES)
@elist <- paste("<item>",TERMNAMES[@nterms],"</item>\n",sep:"")
for(@i,run(@nterms-1)) {
	@elist <- paste(@elist,"<item>",TERMNAMES[@i],"</item>\n",sep:"")
}
if(!ischar(g_pairwise)) {
	g_pairwise <- matread("Gui.dat.txt","g_pairwise",silent:T)
}
# do the last one in dialog first
@thisxml <- replacestr(g_pairwise,@eplace,@elist)
@thisxml <- replacestr(@thisxml,@fplace,@flist)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"pairwise")
if(isnull(@out)) {
	error("Contrast cancelled")
}
@out <- @out[2]
if(@out[1] == "") {
	alert("No factor chosen")
	error("No factor chosen")
}
@command <- paste("pairwise(\"",@out[1],"\"",sep:"")
if(!isnumber(@out[2])) {
	alert("Error rate must be numeric")
	error("Error rate must be numeric")
}
@command <- paste(@command,",",@out[2],sep:"")
if    (@out[3] == "Selected") {
	@command <- paste(@command,",hsd:T",sep:"")
} elseif(@out[4] == "Selected") {
	@command <- paste(@command,",bsd:T",sep:"")
} elseif(@out[5] == "Selected") {
	@command <- paste(@command,",regwr:T",sep:"")
} elseif(@out[6] == "Selected") {
	@command <- paste(@command,",regwb:T",sep:"")
} elseif(@out[7] == "Selected") {
	@command <- paste(@command,",snk:T",sep:"")
} else  {
	@command <- paste(@command,",lsd:T",sep:"")
}
if(@out[9] != "") {
	@command <- paste(@command,",error:\"",@out[9],"\"",sep:"")
}
@command <- paste(@command,")")
pushcommand(@command)
%guipairwise%


guisampsize MACRO DOLLARS
if(!ischar(g_sampsize)) {
	g_sampsize <- matread("Gui.dat.txt","g_sampsize",silent:T)
}
@out <- setmdialog(g_sampsize,"sampsize")
if(isnull(@out)) {
	error("Sample size cancelled")
}
@out <- @out[2]
@pwr <- @out[1]
@alpha <- @out[2]
if(@out[3] == "Selected") {
	@command <- paste("@means <- vecread(string:\"",\
		@out[4],"\");\\\nfindsampsize(@means,",\
		@out[5],sep:"")
} else {
	@command <- paste("findsampsize(",@out[7],",",\
		@out[8],sep:"")
}
@command <- paste(@command,",",@alpha,",",@pwr,sep:"")
if(@out[6] == "Selected" && @out[10] == "checked") {
	alert("Cannot use proportional sample sizes with n=1 noncentrality")
	error("Cannot use proportional sample sizes with n=1 noncentrality")
}
if(@out[9] == "checked" && @out[10] == "checked") {
	alert("Cannot use proportional sample sizes with RCB")
	error("Cannot use proportional sample sizes with RCB")
}
if(@out[9] == "checked") {
	@command <- paste(@command,",rcb:T",sep:"")
}
if(@out[10] == "checked") {
	@command <- paste("@propvec <- vecread(string:\"",\
		@out[11],"\");\\\n",@command,",prop:@propvec",sep:"")
}
@command <- paste(@command,")",sep:"")
pushcommand(@command)
%guisampsize%



guipower MACRO DOLLARS
if(!ischar(g_power)) {
	g_power <- matread("Gui.dat.txt","g_power",silent:T)
}
@out <- setmdialog(g_power,"power")
if(isnull(@out)) {
	error("Power calculation cancelled")
}
@out <- @out[2]
@alpha <- @out[1]
if(@out[3] == "Selected") {
	@command <- paste("@means <- vecread(string:\"",\
		@out[4],"\");\\\n@ns <- vecread(string:\"",\
		@out[5],"\");\\\nfindpower(@means,@ns,",\
		@out[6],sep:"")
} else {
	@command <- paste("findpower(",@out[8],",",\
		@out[9],",",@out[10],sep:"")
}
@command <- paste(@command,",",@alpha,sep:"")
if(@out[7] == "Selected" && @out[2] == "checked") {
	alert("Cannot use rcb with general noncentrality")
	error("Cannot use rcb with general noncentrality")
}
if(@out[2] == "checked") {
	@command <- paste(@command,",rcb:T",sep:"")
}
@command <- paste(@command,")",sep:"")
pushcommand(@command)
%guipower%

===>guintrctplt<===
guintrctplt MACRO DOLLARS
if(!ischar(g_plotbase)) {
	g_plotbase <- read("Gui.dat.txt","g_plotbase",silent:T)
}
if(!ischar(g_ntrctplt)) {
	g_ntrctplt <- read("Gui.dat.txt","g_ntrctplt",silent:T)
}
if(!ischar(g_helpctrlbs)) {
	g_helpctrlbs <- read("Gui.dat.txt","g_helpctrlbs",silent:T)
}
@thisxml <- replacestr(g_plotbase,"BASICPANEL",g_ntrctplt)
@varxml <- guilistctrl(usereal:T,attrnonsys:T,attrsystem:F,matchrows:T)
@thisxml <- replacestr(@thisxml,"LISTCONTROL",@varxml$xml)
@help <- findfile("docs/html/gui_guintrctplt.htm")
@help <- replacestr(g_helpctrlbs,"HELPFILE",@help)
@thisxml <- replacestr(@thisxml,"HELPCONTROL",@help)
@thisxml <- replacestr(@thisxml,"PLOTTITLE","Interaction Plot")
@thisxml <- replacestr(@thisxml,"PLOTNAME","ntrctplt")
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"ntrctplt")
if(isnull(@out)) {
	error("interaction plot cancelled")
}
@out <- @out[2]
if(@out[8] == "") {
	alert("No variables selected")
	error("No variables selected")
}
@varind <- vecread(string:@out[8]) + 1
@varlist <- @varxml$vars[@varind]
@doerrors <- ""
if(@out[2] == "Selected") {
	@doerrors <- paste(",errors:",@out[3],sep:"")
}
@frommodel <- ""
if(@out[4] == "checked") {
	@frommodel <- ",frommodel:T"
}
@command <- "interactplot("
@command <- paste(@command,paste(@varlist,sep:","),sep:"")
@command <- paste(@command,@frommodel,@doerrors,sep:"")

if(@doerrors != "") {
	if(length(dim(<<@varlist[1]>>)) > 1) {
		if(@out[7] != "") {
			@command <- paste(@command,",errormat:",@out[7],sep:"")
		}
	} elseif(@out[6] != "") {
		@command <- paste(@command,",errorvar:",@out[6],sep:"")
	} elseif(@out[5] == "checked") {
		@command <- paste(@command,",pool:T",sep:"")
	}
}
		
@command <- paste(@command,@out[41],sep:"")
@appropt <- guiappropt(@out,8)
@axisopt <- guiaxisopt(@out,8+18)
@command <- paste(@command,@appropt,@axisopt,")",sep:"")
pushcommand(@command)
%guintrctplt%






guimakecols MACRO DOLLARS
if(!ischar(g_mkclsbase)) {
	g_mkclsbase <- read("Gui.dat.txt","g_mkclsbase",silent:T)
}
if(!ischar(g_mkclsitem)) {
	g_mkclsitem <- read("Gui.dat.txt","g_mkclsitem",silent:T)
}
@mat <- guilistdlg(req2d:T,reqreal:T,attrsystem:F,attrnonsys:T,maxselect:1)
if(isnull(@mat)) {
	error("makecols cancelled or no variable selected")
}
@nc <- ncols(<<@mat>>)
@items <- ""
for(@i,run(@nc)) {
	@this <- g_mkclsitem
	@this <- replacestr(@this,"COLUMN",paste(@i))
	@this <- replacestr(@this,"COLUMN",paste(@i))
	@this <- replacestr(@this,"COLUMN",paste(@i))
	@this <- replacestr(@this,"COLUMN",paste(@i))
	@items <- paste(@items,@this,sep:"\n")
}
@thisxml <- replacestr(g_mkclsbase,"COLUMNITEMS",@items)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"makecols")
if(isnull(@out)) {
	error("make columns cancelled")
}
@out <- @out[2]
@varlist <- NULL
@factlist <- NULL
for(@i,run(@nc)) {
	@varlist <- vector(@varlist,@out[2*@i-1])
	if(@out[2*@i] == "checked") {
		@factlist <- vector(@factlist,@varlist[@i])
	}
	if(!isname(@varlist[@i])) {
		@msg <- paste("Illegal variable name for column",@i)
		alert(@msg)
		error(@msg)
	}
}
@command <- paste(@mat,@varlist,sep:",")
@command <- paste("makecols(",@command,")",sep:"")
if(length(@factlist) > 0) {
	for(@i,run(length(@factlist))) {
		@c2 <- paste(";\\\n",@factlist[@i]," <- makefactor(",@factlist[@i],")",sep:"")
		@command <- paste(@command,@c2,sep:"")
	}
}
pushcommand(@command)
%guimakecols%



guimakefact MACRO DOLLARS
if(!ischar(g_makefact)) {
	g_makefact <- read("Gui.dat.txt","g_makefact",silent:T)
}
@varxml <- guilistctrl(req1d:T,usechar:T,uselogic:T,usereal:T,\
	attrnonsys:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(g_makefact,"LISTCONTROL",@varxml$xml)
@out <- setmdialog(@thisxml,"makefact")
if(isnull(@out)) {
	error("make factor cancelled")
}
@out <- @out[2]
if(@out[7] == "") {
	alert("No variable selected")
	error("No variable selected")
}
@varind <- vecread(string:@out[7]) + 1
@var <- @varxml$vars[@varind]
@command <- paste("makefactor(",@var,sep:"")
if(@out[5] != "checked") {
	@command <- paste(@command,",sort:F",sep:"")
}
if(@out[6] == "checked") {
	@command <- paste(@command,",labels:F",sep:"")
} else {
	@command <- paste(@command,",labels:T",sep:"")
}
@command <- paste(@command,")",sep:"")
if(@out[3] == "Selected") {
	if(!isname(@out[4])) {
		alert("Illegal variable name")
		error("Illegal variable name")
	}
	@command <- paste(@out[4],"<-",@command)
} elseif (@out[2] == "Selected") {
	@command <- paste(@var,"<-",@command)
}
pushcommand(@command)
%guimakefact%

guigetmdlwts  MACRO DOLLARS
@n <- $1
@wts <- ""
if(!ischar(g_anovawts)) {
	g_anovawts <- matread("Gui.dat.txt","g_anovawts",silent:T)
}
@varxml <- guilistctrl(reqreal:T,req1d:T,reqnrows:@n,\
	attrnonsys:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(g_anovawts,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"anovawts")
if(isnull(@out)) {
	error("Anova cancelled")
}
if(@out[2][1] == "") {
	alert("No weight vector selected")
	error("No weight vector selected")
}
@varind <- vecread(string:@out[2][1])+1
@wts <- paste(",wts:",@varxml$vars[@varind],sep:"")
return(@wts)
%guigetmdlwts%


guibldanvmdl MACRO DOLLARS
@newy <- $1
@n <- length(<<@newy>>)
@thismodel <- paste(@newy,"=",sep:"")
@firstterm <- T
if(!ischar(g_anovamodel)) {
	g_anovamodel <- matread("Gui.dat.txt","g_anovamodel",silent:T)
}
@varxml <- guilistctrl(reqreal:T,req1d:T,reqnrows:@n,attrnsvart:T,\
	attrnsfact:T,attrsystem:F,omit:@newy)
while(T) {
	@thisxml <- replacestr(g_anovamodel,"LISTCONTROL",@varxml$xml)
	@thisxml <- replacestr(@thisxml,"CURRENTMODEL",@thismodel)
	thisxml <- @thisxml
	@out <- setmdialog(@thisxml,"anovamodel")
	if(isnull(@out)) {
		error("Anova cancelled")
	}
	@out <- @out[2]
	@thismodel <- @out[1]
	if(@out[21] == "6002") { # done
		break
	}
	if(@out[9] != "Selected" && @out[12] != "Selected" && \
			@out[15] != "Selected") {
		if(@out[20] == "") {
			alert("No variables selected for term")
			next
		}
		@varind <- vecread(string:@out[20])+1
		@termvars <- @varxml$vars[@varind]
	}
	if(@out[2] == "Selected") {
		@term <- paste(@termvars,sep:"+")
	} elseif(@out[3] == "Selected") {
		@term <- paste(@termvars,sep:".")
	} elseif(@out[4] == "Selected") {
		@term <- paste(@termvars,sep:"*")
	} elseif(@out[5] == "Selected") {
		@term <- paste(@termvars,sep:"/")
	} elseif(@out[6] == "Selected") {
		@term <- paste(@termvars,sep:"+")
		@pow <- vecread(string:@out[7])[1]
		@term <- paste("(",@term,")^",@pow,sep:"")
	} elseif(@out[9] == "Selected") {
		@pow <- vecread(string:@out[11])[1]
		@term <- paste("P",@pow,"(",@out[10],")",sep:"")
	} elseif(@out[12] == "Selected") {
		@pow <- vecread(string:@out[14])[1]
		@term <- paste("C",@pow,"(",@out[13],")",sep:"")
	} else {
		@term <- @out[16]
	}
	if(@out[8] == "checked") {
		@term <- paste("E(",@term,")",sep:"")
	}
	@op <- "+"
	if(@firstterm) {
		@op <- ""
	}
	if(@out[17] == "checked") {
		@op <- "-"
	} elseif(@out[18] == "checked") {
		@op <- "-*"
	}
	@const <- ""
	if(@out[19] == "checked") {
		@const <- "-1"
	}
	@thismodel <- paste(@thismodel,@op,@term,@const,sep:"")
	@firstterm <- F
}
return(@thismodel)
%guibldanvmdl%



guiems MACRO DOLLARS
if(!ischar(g_ems)) {
	g_ems <- matread("Gui.dat.txt","g_ems",silent:T)
}
@varxml <- guilistctrl(reqreal:T,req1d:T,attrnonsys:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(g_ems,"LISTCONTROL",@varxml$xml)
if(isdefined(STRMODEL)) {
	@thisxml <- replacestr(@thisxml,"STRMODEL",STRMODEL)
} else {
	@thisxml <- replacestr(@thisxml,"STRMODEL","no current model")
}
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"ems")
if(isnull(@out)) {
	error("Expected mean squares cancelled")
}
@thismodel <- NULL
@out <- @out[2]
if(@out[7]=="Selected") {
	if(!isdefined(STRMODEL)) {
		alert("No current model")
		error("No current model")
	}
	@thismodel <- STRMODEL
}
@marg <- ""
if(@out[1] == "checked") {
	@marg <- ",marg:T"
}
@restrict <- ""
if(@out[2] != "checked") {
	@restrict <- ",restrict:F"
}
@nonhier <- ""
if(@out[3] != "checked") {
	@nonhier <- ",nonhier:T"
}
@pre <- ""
@keep <- ""
if(@out[5] == "Selected") {
	if(!isname(@out[6])) {
		alert("Illegal variable name")
		error("Illegal variable name")
	}
	@pre <- paste(@out[6]," <- ",sep:"")
	@keep <- ",keep:T,print:T"
}
@varind <- @out[10]
if(isnull(@thismodel) && @varind == "") {
	alert("No response selected")
	error("No response selected")
}
if(@varind != "") {
	@varind <- vecread(string:@varind)+1
	@newy <- @varxml$vars[@varind]
}
if(isnull(@thismodel)) {
	@thismodel <- guibldanvmdl(@newy)
}
@vars <- varnames(@thismodel)[-1]
@random <- guilistdlg(useonly:@vars,title:"Random factors",prompt:"Select random factors")
if(isnull(@random)) {
	@random <- ",random:NULL"
} else {
	if(length(@random) > 1) {
		@random <- paste(@random,sep:"\",\"")
		@random <- paste("vector(\"",@random,"\")",sep:"")
	} else {
		@random <- paste("\"",@random,"\"",sep:"")
	}
	@random <- paste(",random:",@random,sep:"")
}
@command <- paste(@pre,"ems(\"",@thismodel,"\"",@random,@marg,\
	@restrict,@nonhier,@keep,")",sep:"")
pushcommand(@command)
return(NULL)
%guiems%



guivarcomp MACRO DOLLARS
if(!ischar(g_varcomp)) {
	g_varcomp <- matread("Gui.dat.txt","g_varcomp",silent:T)
}
@varxml <- guilistctrl(reqreal:T,req1d:T,attrnonsys:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(g_varcomp,"LISTCONTROL",@varxml$xml)
if(isdefined(STRMODEL)) {
	@thisxml <- replacestr(@thisxml,"STRMODEL",STRMODEL)
} else {
	@thisxml <- replacestr(@thisxml,"STRMODEL","no current model")
}
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"varcomp")
if(isnull(@out)) {
	error("Variance components cancelled")
}
@thismodel <- NULL
@out <- @out[2]
if(@out[8] == "Selected") {
	@var <- guilistdlg(reqstruc:T,attrsystem:F,attrnonsys:T,maxselect:1)
	if(isnull(@var)) {
		error("Variance components cancelled")
	}
	@command <- paste("varcomp(",@var,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@out[4]=="Selected") {
	if(!isdefined(STRMODEL)) {
		alert("No current model")
		error("No current model")
	}
	@thismodel <- STRMODEL
}
@marg <- ""
if(@out[1] == "checked") {
	@marg <- ",marg:T"
}
@restrict <- ""
if(@out[2] != "checked") {
	@restrict <- ",restrict:F"
}
@nonhier <- ""
if(@out[3] != "checked") {
	@nonhier <- ",nonhier:T"
}
@varind <- @out[7]
if(isnull(@thismodel) && @varind == "") {
	alert("No response selected")
	error("No response selected")
}
if(@varind != "") {
	@varind <- vecread(string:@varind)+1
	@newy <- @varxml$vars[@varind]
}
if(isnull(@thismodel)) {
	@thismodel <- guibldanvmdl(@newy)
}
@vars <- varnames(@thismodel)[-1]
@random <- guilistdlg(useonly:@vars,title:"Random factors",prompt:"Select random factors")
if(isnull(@random)) {
	@random <- ",random:NULL"
} else {
	if(length(@random) > 1) {
		@random <- paste(@random,sep:"\",\"")
		@random <- paste("vector(\"",@random,"\")",sep:"")
	} else {
		@random <- paste("\"",@random,"\"",sep:"")
	}
	@random <- paste(",random:",@random,sep:"")
}
@command <- paste("varcomp(\"",@thismodel,"\"",@random,@marg,\
	@restrict,@nonhier,")",sep:"")
pushcommand(@command)
return(NULL)
%guivarcomp%


guimixed MACRO DOLLARS
if(!ischar(g_mixed)) {
	g_mixed <- matread("Gui.dat.txt","g_mixed",silent:T)
}
@varxml <- guilistctrl(reqreal:T,req1d:T,attrnonsys:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(g_mixed,"LISTCONTROL",@varxml$xml)
if(isdefined(STRMODEL)) {
	@thisxml <- replacestr(@thisxml,"STRMODEL",STRMODEL)
} else {
	@thisxml <- replacestr(@thisxml,"STRMODEL","no current model")
}
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"mixed")
if(isnull(@out)) {
	error("Mixed effects analysis cancelled")
}
@thismodel <- NULL
@out <- @out[2]
@useneg <- ""
if(@out[4] == "checked") {
	@useneg <- ",useneg:T"
}
if(@out[9] == "Selected") {
	@var <- guilistdlg(reqstruc:T,attrsystem:F,attrnonsys:T,maxselect:1)
	if(isnull(@var)) {
		error("Variance components cancelled")
	}
	@command <- paste("mixed(",@var,@useneg,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@out[5]=="Selected") {
	if(!isdefined(STRMODEL)) {
		alert("No current model")
		error("No current model")
	}
	@thismodel <- STRMODEL
}
@marg <- ""
if(@out[1] == "checked") {
	@marg <- ",marg:T"
}
@restrict <- ""
if(@out[2] != "checked") {
	@restrict <- ",restrict:F"
}
@nonhier <- ""
if(@out[3] != "checked") {
	@nonhier <- ",nonhier:T"
}
@varind <- @out[8]
if(isnull(@thismodel) && @varind == "") {
	alert("No response selected")
	error("No response selected")
}
if(@varind != "") {
	@varind <- vecread(string:@varind)+1
	@newy <- @varxml$vars[@varind]
}
if(isnull(@thismodel)) {
	@thismodel <- guibldanvmdl(@newy)
}
@vars <- varnames(@thismodel)[-1]
@random <- guilistdlg(useonly:@vars,title:"Random factors",prompt:"Select random factors")
if(isnull(@random)) {
	@random <- ",random:NULL"
} else {
	if(length(@random) > 1) {
		@random <- paste(@random,sep:"\",\"")
		@random <- paste("vector(\"",@random,"\")",sep:"")
	} else {
		@random <- paste("\"",@random,"\"",sep:"")
	}
	@random <- paste(",random:",@random,sep:"")
}
@command <- paste("mixed(\"",@thismodel,"\"",@random,@marg,\
	@restrict,@nonhier,@useneg,")",sep:"")
pushcommand(@command)
return(NULL)
%guimixed%




guicumprob MACRO DOLLARS
@which <- argvalue($1,"distribution type","char scalar")
if(@which == "uniform") {
	if(!ischar(g_cumuni)) {
		g_cumuni <- matread("Gui.dat.txt","g_cumuni",silent:T)
	}
	@out <- setmdialog(g_cumuni,"cumuni")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@low <- @out[5]
	@high <- @out[6]
	@upper <- @out[7] == "checked"
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Lower endpoints empty")
		error("Lower endpoints empty")
	}
	if(@out[6] == "") {
		alert("Upper endpoints empty")
		error("Upper endpoints empty")
	}
	if(@upper) {
		@command <- paste(@pre,"{@prob <- (",@high,"-",@y,")/(",@high,"-",@low,")",sep:"")
	} else {
		@command <- paste(@pre,"{@prob <- (",@y,"-",@low,")/(",@high,"-",@low,")",sep:"")
	}
	@command <- paste(@command,";\\\n@prob[@prob > 1] <- 1;@prob[@prob<0] <- 0;@prob}",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "F") {
	if(!ischar(g_cumF)) {
		g_cumF <- matread("Gui.dat.txt","g_cumF",silent:T)
	}
	@out <- setmdialog(g_cumF,"cumF")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@ndf <- @out[5]
	@ddf <- @out[6]
	@noncen <- @out[7]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Numerator df empty")
		error("Numerator df empty")
	}
	if(@out[6] == "") {
		alert("Denominator df empty")
		error("Denominator df empty")
	}
	@doncp <- ""
	if(@noncen != "" && @noncen != "0") {
		@doncp <- paste(",",@noncen,sep:"")
	}
	@upper <- ""
	if(@out[8] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumF(",@y,",",@ndf,",",@ddf,@doncp,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "beta") {
	if(!ischar(g_cumbeta)) {
		g_cumbeta <- matread("Gui.dat.txt","g_cumbeta",silent:T)
	}
	@out <- setmdialog(g_cumbeta,"cumbeta")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@alpha <- @out[5]
	@beta <- @out[6]
	@noncen <- @out[7]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Alpha empty")
		error("Alpha empty")
	}
	if(@out[6] == "") {
		alert("Beta empty")
		error("Beta empty")
	}
	@doncp <- ""
	if(@noncen != "" && @noncen != "0") {
		@doncp <- paste(",",@noncen,sep:"")
	}
	@upper <- ""
	if(@out[8] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumbeta(",@y,",",@alpha,",",@beta,@doncp,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "binomial") {
	if(!ischar(g_cumbin)) {
		g_cumbin <- matread("Gui.dat.txt","g_cumbin",silent:T)
	}
	@out <- setmdialog(g_cumbin,"cumbin")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@N <- @out[5]
	@p <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("N empty")
		error("N empty")
	}
	if(@out[6] == "") {
		alert("P empty")
		error("P empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumbin(",@y,",",@N,",",@p,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "chisquare") {
	if(!ischar(g_cumchi)) {
		g_cumchi <- matread("Gui.dat.txt","g_cumchi",silent:T)
	}
	@out <- setmdialog(g_cumchi,"cumchi")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@df <- @out[5]
	@noncen <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@doncp <- ""
	if(@noncen != "" && @noncen != "0") {
		@doncp <- paste(",",@noncen,sep:"")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumchi(",@y,",",@df,@doncp,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "dunnett") {
	if(!ischar(g_cumdunn)) {
		g_cumdunn <- matread("Gui.dat.txt","g_cumdunn",silent:T)
	}
	@out <- setmdialog(g_cumdunn,"cumdunn")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@K <- @out[5]
	@df <- @out[6]
	@ns <- @out[7]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Number of groups empty")
		error("Number of groups empty")
	}
	if(@out[6] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@dons <- ""
	if(@ns != "" && @ns != "default is equal") {
		@dons <- paste(",",@ns,sep:"")
	}
	@oneside <- ""
	if(@out[8] == "checked") {
		@oneside <- ",onesided:T"
	}
	@upper <- ""
	if(@out[9] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumdunnett(",@y,",",@K,",",@df,@dons,@oneside,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "gamma") {
	if(!ischar(g_cumgamma)) {
		g_cumgamma <- matread("Gui.dat.txt","g_cumgamma",silent:T)
	}
	@out <- setmdialog(g_cumgamma,"cumgamma")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@shape <- @out[5]
	@scale <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Shape empty")
		error("Shape empty")
	}
	if(@out[6] == "") {
		alert("Scale empty")
		error("Scale empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumgamma(",@y,"/",@scale,",",@shape,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "normal") {
	if(!ischar(g_cumnor)) {
		g_cumnor <- matread("Gui.dat.txt","g_cumnor",silent:T)
	}
	@out <- setmdialog(g_cumnor,"cumnor")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@mean <- @out[5]
	@sd <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Mean empty")
		error("Mean empty")
	}
	if(@out[6] == "") {
		alert("SD empty")
		error("SD empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumnor((",@y,"-",@mean,")/",@sd,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "poisson") {
	if(!ischar(g_cumpoi)) {
		g_cumpoi <- matread("Gui.dat.txt","g_cumpoi",silent:T)
	}
	@out <- setmdialog(g_cumpoi,"cumpoi")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@mean <- @out[5]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Mean empty")
		error("Mean empty")
	}
	@upper <- ""
	if(@out[6] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumpoi(",@y,",",@mean,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "studrange") {
	if(!ischar(g_cumstdrng)) {
		g_cumstdrng <- matread("Gui.dat.txt","g_cumstdrng",silent:T)
	}
	@out <- setmdialog(g_cumstdrng,"cumstdrng")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@K <- @out[5]
	@df <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Number of groups empty")
		error("Number of groups empty")
	}
	if(@out[6] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumstudrng(",@y,",",@K,",",@df,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "student") {
	if(!ischar(g_cumstu)) {
		g_cumstu <- matread("Gui.dat.txt","g_cumstu",silent:T)
	}
	@out <- setmdialog(g_cumstu,"cumstu")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@df <- @out[5]
	@noncen <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@doncp <- ""
	if(@noncen != "" && @noncen != "0") {
		@doncp <- paste(",",@noncen,sep:"")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"cumstu(",@y,",",@df,@doncp,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
%guicumprob%




guiinvprob MACRO DOLLARS
@which <- argvalue($1,"distribution type","char scalar")
if(@which == "uniform") {
	if(!ischar(g_cumuni)) {
		g_cumuni <- matread("Gui.dat.txt","g_cumuni",silent:T)
	}
	@out <- setmdialog(g_cumuni,"cumuni")
	if(isnull(@out)) {
		error("cumulative probability cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@low <- @out[5]
	@high <- @out[6]
	@upper <- @out[7] == "checked"
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Lower endpoints empty")
		error("Lower endpoints empty")
	}
	if(@out[6] == "") {
		alert("Upper endpoints empty")
		error("Upper endpoints empty")
	}
	@command <- paste(@pre,"{@prob <- ",@y,";@prob[@prob > 1] <- 1;@prob[@prob<0] <- 0;\\\n",sep:"")
	if(@upper) {
		@command <- paste(@command,@high,"-@prob*(",@high,"-",@low,")}",sep:"")
	} else {
		@command <- paste(@command,@low,"+@prob*(",@high,"-",@low,")}",sep:"")
	}
	pushcommand(@command)
	return(NULL)
}
if(@which == "F") {
	if(!ischar(g_invF)) {
		g_invF <- matread("Gui.dat.txt","g_invF",silent:T)
	}
	@out <- setmdialog(g_invF,"invF")
	if(isnull(@out)) {
		error("percent points cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@ndf <- @out[5]
	@ddf <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Numerator df empty")
		error("Numerator df empty")
	}
	if(@out[6] == "") {
		alert("Denominator df empty")
		error("Denominator df empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"invF(",@y,",",@ndf,",",@ddf,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "beta") {
	if(!ischar(g_invbeta)) {
		g_invbeta <- matread("Gui.dat.txt","g_invbeta",silent:T)
	}
	@out <- setmdialog(g_invbeta,"invbeta")
	if(isnull(@out)) {
		error("percent point cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@alpha <- @out[5]
	@beta <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Alpha empty")
		error("Alpha empty")
	}
	if(@out[6] == "") {
		alert("Beta empty")
		error("Beta empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"invbeta(",@y,",",@alpha,",",@beta,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "chisquare") {
	if(!ischar(g_cumchi)) {
		g_cumchi <- matread("Gui.dat.txt","g_cumchi",silent:T)
	}
	@out <- setmdialog(g_cumchi,"cumchi")
	if(isnull(@out)) {
		error("percent point cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@df <- @out[5]
	@noncen <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@doncp <- ""
	if(@noncen != "" && @noncen != "0") {
		@doncp <- paste(",",@noncen,sep:"")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"invchi(",@y,",",@df,@doncp,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "dunnett") {
	if(!ischar(g_cumdunn)) {
		g_cumdunn <- matread("Gui.dat.txt","g_cumdunn",silent:T)
	}
	@out <- setmdialog(g_cumdunn,"cumdunn")
	if(isnull(@out)) {
		error("percent point cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@K <- @out[5]
	@df <- @out[6]
	@ns <- @out[7]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Number of groups empty")
		error("Number of groups empty")
	}
	if(@out[6] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@dons <- ""
	if(@ns != "" && @ns != "default is equal") {
		@dons <- paste(",",@ns,sep:"")
	}
	@oneside <- ""
	if(@out[8] == "checked") {
		@oneside <- ",onesided:T"
	}
	@upper <- ""
	if(@out[9] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"invdunnett(",@y,",",@K,",",@df,@dons,@oneside,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "gamma") {
	if(!ischar(g_cumgamma)) {
		g_cumgamma <- matread("Gui.dat.txt","g_cumgamma",silent:T)
	}
	@out <- setmdialog(g_cumgamma,"cumgamma")
	if(isnull(@out)) {
		error("percent point cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@shape <- @out[5]
	@scale <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Shape empty")
		error("Shape empty")
	}
	if(@out[6] == "") {
		alert("Scale empty")
		error("Scale empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,@scale,"*invgamma(",@y,",",@shape,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "normal") {
	if(!ischar(g_cumnor)) {
		g_cumnor <- matread("Gui.dat.txt","g_cumnor",silent:T)
	}
	@out <- setmdialog(g_cumnor,"cumnor")
	if(isnull(@out)) {
		error("percent point cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@mean <- @out[5]
	@sd <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Mean empty")
		error("Mean empty")
	}
	if(@out[6] == "") {
		alert("SD empty")
		error("SD empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,@mean,"+",@sd,"*invnor(",@y,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "studrange") {
	if(!ischar(g_cumstdrng)) {
		g_cumstdrng <- matread("Gui.dat.txt","g_cumstdrng",silent:T)
	}
	@out <- setmdialog(g_cumstdrng,"cumstdrng")
	if(isnull(@out)) {
		error("percent point cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@K <- @out[5]
	@df <- @out[6]
	if(@out[4] == "") {
		alert("Values empty")
		error("Values empty")
	}
	if(@out[5] == "") {
		alert("Number of groups empty")
		error("Number of groups empty")
	}
	if(@out[6] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@upper <- ""
	if(@out[7] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"invstudrng(",@y,",",@K,",",@df,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
if(@which == "student") {
	if(!ischar(g_invstu)) {
		g_invstu <- matread("Gui.dat.txt","g_invstu",silent:T)
	}
	@out <- setmdialog(g_invstu,"invstu")
	if(isnull(@out)) {
		error("percent point cancelled")
	}
	@out <- @out[2]
	@pre <- ""
	if(@out[2] == "Selected") {
		@pre <- @out[3]
		if(!isname(@pre)) {
			alert("Illegal variable name")
			error("Illegal variable name")
		}
		@pre <- paste(@pre," <- ",sep:"")
	}
	@y <- @out[4]
	@df <- @out[5]
	if(@out[5] == "") {
		alert("DF empty")
		error("DF empty")
	}
	@upper <- ""
	if(@out[6] == "checked") {
		@upper <- ",upper:T"
	}
	@command <- paste(@pre,"invstu(",@y,",",@df,@upper,")",sep:"")
	pushcommand(@command)
	return(NULL)
}
%guiinvprob%



guiallK MACRO DOLLARS
@k <- $1
if(!ischar(g_all3)) {
        g_allK <- read("Gui.dat.txt","g_allK",silent:T)
}
if(@k == 3) {
	@thisxml <- replacestr(g_allK,"NUMBER","Three")
	@thisxml <- replacestr(@thisxml,"NUMBER","Three")
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrnonsys:T,attrsystem:F,maxselect:4)
} else {
	@thisxml <- replacestr(g_allK,"NUMBER","Four")
	@thisxml <- replacestr(@thisxml,"NUMBER","Four")
	@varxml <- guilistctrl(reqreal:T,req1d:T,attrnonsys:T,attrsystem:F,maxselect:5)
}
@thisxml <- replacestr(@thisxml,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"allK")
if(isnull(@out)) {
	error("All 3 cancelled")
}
@out <- @out[2]

if(@out[6] == "") {
        alert("No variables selected")
        error("No variables selected")
}
@varind <- vecread(string:@out[6]) + 1
@varlist <- @varxml$vars[@varind]
if(length(@varlist) != (@k+1)) {
	@msg <- paste("You must choose a response and",@k,"factors")
	alert(@msg)
	error(@msg)
}
@varlist <- paste(@varlist,sep:",")
@pre <- ""
@keep <- ""
if(@out[2] == "Selected") {
	if(!isname(@out[3])) {
		alert("Illegal variable name")
		error("Illegal variable name")
	}
	@pre <- paste(@out[2]," <- ",sep:"")
	@keep <- ",keep:T,print:T"
}
@var <- ""
if(@out[4] == "checked") {
	if(@out[5] == "") {
		alert("Error variance is empty")
		error("Error variance is empty")
	}
	@var <- paste(",mse:",@out[5],sep:"")
}
if(@k == 3) {
	@command <- paste(@pre,"all3anova(",@varlist,@var,@keep,")",sep:"")
}else{
	@command <- paste(@pre,"all4anova(",@varlist,@var,@keep,")",sep:"")
}
pushcommand(@command)
%guiallK%



guisidebside MACRO DOLLARS
if(!ischar(g_sidebside)) {
        g_sidebside <- read("Gui.dat.txt","g_sidebside",silent:T)
}
@out <- setmdialog(g_sidebside,"sidebside")
if(isnull(@out)) {
	error("Side-by-side plot cancelled")
}
@out <- @out[2]

@command <- "sidebyside("
@first <- ""
if(@out[1] == "checked") {
	@command <- paste(@command,@first,"rescale:T",sep:"")
	@first <- ","
}
if(@out[2] == "checked") {
	@command <- paste(@command,@first,"showconst:T",sep:"")
	@first <- ","
}
@boxcut <- vecread(string:@out[3])[1]
if(@boxcut != 20) {
	@command <- paste(@command,@first,"boxcut:",@boxcut,sep:"")
	@first <- ","
}
	
if(@out[4] == "checked") {
	if(@out[5] == "") {
		alert("Label heights empty")
		error("Label heights empty")
	}
	@command <- paste(@command,@first,"termlaby:",@out[5],sep:"")
	@first <- ","
}
if(@out[6] == "checked") {
	if(@out[7] == "") {
		alert("Label heights empty")
		error("Label heights empty")
	}
	@command <- paste(@command,@first,"labels:",@out[7],sep:"")
	@first <- ","
}
@command <- paste(@command,")",sep:"")
pushcommand(@command)
%guisidebside%



guireml MACRO DOLLARS
if(!ischar(g_reml)) {
	g_reml <- matread("Gui.dat.txt","g_reml",silent:T)
}
@varxml <- guilistctrl(reqreal:T,req1d:T,attrnonsys:T,attrsystem:F,maxselect:1)
@thisxml <- replacestr(g_reml,"LISTCONTROL",@varxml$xml)
thisxml <- @thisxml
@out <- setmdialog(@thisxml,"reml")
if(isnull(@out)) {
	error("Reml analysis cancelled")
}
@thismodel <- NULL
@out <- @out[2]
@marg <- ""
if(@out[1] == "checked") {
	@marg <- ",marg:T"
}
@restrict <- ""
if(@out[2] != "checked") {
	@restrict <- ",restrict:F"
}
@nonhier <- ""
if(@out[3] != "checked") {
	@nonhier <- ",nonhier:T"
}
@V <- ""
if(@out[4] == "checked") {
	@V <- ",retV:T"
}
@mle <- ""
if(@out[5] == "checked") {
	@mle <- ",usemle:T"
}
@pre <- ""
if(@out[7] == "Selected") {
	if(!isname(@out[8])) {
		alert("Illegal variable name")
		error("Illegal variable name")
	}
	@pre <- paste(@out[8]," <- ",sep:"")
}
@varind <- @out[9]
if(@varind == "") {
	alert("No response selected")
	error("No response selected")
}
if(@varind != "") {
	@varind <- vecread(string:@varind)+1
	@newy <- @varxml$vars[@varind]
}
@thismodel <- guibldanvmdl(@newy)
@vars <- varnames(@thismodel)[-1]
@random <- guilistdlg(useonly:@vars,title:"Random factors",prompt:"Select random factors")
@n <- nrows(<<@newy>>)
@Z <- guilistdlg(req2d:T,reqreal:T,title:"Z-matrices",reqnrows:@n,\
	prompt:"Select Z-matrices for random effects")
if(!isnull(@random)) {
	if(length(@random) > 1) {
		@random <- paste(@random,sep:"\",\"")
		@random <- paste("vector(\"",@random,"\")",sep:"")
	} else {
		@random <- paste("\"",@random,"\"",sep:"")
	}
	@random <- paste(",random:",@random,sep:"")
}
if(!isnull(@Z)) {
	if(length(@Z) > 1) {
		@Z <- paste(@Z,sep:"\",\"")
		@Z <- paste("vector(\"",@Z,"\")",sep:"")
	} else {
		@Z <- paste("\"",@Z,"\"",sep:"")
	}
	@Z <- paste(",Z:",@Z,sep:"")
}
if(isnull(@Z) && isnull(@random)) {
	alert("You must specify either random factors or Z-matrices")
	error("You must specify either random factors or Z-matrices")
} elseif(isnull(@random)) {
	@random <- ""
} elseif(isnull(@Z)) {
	@Z <- ""
}
@command <- paste(@pre,"reml(\"",@thismodel,"\"",@random,@Z,@marg,\
	@restrict,@nonhier,@mle,@V,")",sep:"")
pushcommand(@command)
return(NULL)
%guireml%

