I'm trying to create a small interactive window in which user (for now me) can enter specific information regarding power calculations (test name, number of groups, type of data) in order to perform the correct kind of power calculation. I know how to do this directly in R, but I want to create a module for others to use who are generally less interested or competent with code and stats, so they can do some simple pre-test power calculations for a better test design.
I'm stuck, I keep getting similar error messages that I don't really understand. here's my code:
>require(tcltk)
>t3<- tktoplevel()
>tktitle(t3)<-"Statistical power"
##create buildingblocks
#define appearance of heading, sub, questions
>fontHead<-tkfont.create(family="times",size=16,weight="bold")
>fontSub<-tkfont.create(family="times",size=14,weight="bold")
>fontQ<-tkfont.create(family="times",size=14)
>fontQ.s<-tkfont.create(family="times",size=12)
>heading.m <-tklabel(t3,text="This module will give you insight in the statistical power requirements of your test",font=fontHead)
>heading.s <-tklabel(t3,text="Please answer the following questions:",font=fontSub)
>Q1 <-tklabel(t3,text="What is the name of your test?",font=fontQ)
>filename <-tclVar("Your test") # this I have seen at**
>e.Q1 <-tkentry(t3,width=30,textvariable=filename)
>submit.name <-function(){ # this I have seen at**
> filename<<- as.character(tclvalue(e.Q1)) # this I have seen at**
> e <- parent.env(environment()) # this I have seen at**
> e$filename <- filename } # this I have seen at**
>b.Q1.sub <-tkbutton(t3,text="Submit",command=submit.name) # this I have seen at**
# creating the widget
>tkgrid(heading.m,columnspan=6)
>tkgrid(tklabel(t3,text=" "))
>tkgrid(heading.s, columnspan=6, sticky="w")
>tkgrid(Q1,row=4,column=0,rowspan=1,columnspan=2,sticky="w")
<tkgrid(e.Q1,row=4,column=2,rowspan=1,columnspan=3,sticky="ew")
<tkgrid(b.Q1.sub,row=4,column=5,rowspan=1,columnspan=1,sticky="ew")
** I copied this solution from Greg Snow's answer to the following question (Get data out of a tcltk function) it doesn't work for me unfortunately. Running my code I get this error message: "Error in structure(.External(.C_dotTclObjv, objv), class = "tclObj") : [tcl] can't read ".32.4 ": no such variable."
above is an example, what I also want to achieve is for the user to enter the amount of groups and whether the data is proportional or scale. here's the code:
>Q2 <-tklabel(t3,text="How many test-groups do you have?",font=fontQ)
>groups <-tclVar("")
>e.Q2 <-tkentry(t3,textvariable=groups) # I want to link this answer to buttonclick at Q3 for determining type of test
> #groups <-as.numeric(tclvalue(e.Q2)) # running this produced this message ***
>#groups <-function(){
as.integer(tclvalue(e.Q2))
} ## running this produced this message****
> Q3 <-tklabel(t3,text="What type of differences do you want to test for?",font=fontQ)
l.Q3.prop <-tklabel(t3,text="Proportional differences (e.g. click through rate, bounce rate, gender rate, etc)",font=fontQ.s)
l.Q3.scal <-tklabel(t3,text="Scaled differences (e.g. converted value, age, numer of sessions before conversion, etc)",font=fontQ.s)
onok.prop <-function() {
groups<-as.numeric(tclvalue(e.Q2))
test<-ifelse(unlist(groups)>2,"Chisq","prop")
return(test)
tkdestroy(t3) }
onok.scal <-function(){
groups<-as.numeric(tclvalue(e.Q2))
test<-ifelse(unlist(groups)>2,"Anova","t-test") return(test)
tkdestroy(t3) }
b.Q3.prop <-tkbutton(t3,text="Proportional",command=onok.prop)
b.Q3.scal <-tkbutton(t3,text="Scale",command=onok.scal)
tkgrid(tklabel(t3,text=" "))
tkgrid(Q2,row=6,column=0,rowspan=1,columnspan=4, sticky="w")
tkgrid(e.Q2,row=6,column=4,rowspan=1,columnspan=2,sticky="ew")
tkgrid(tklabel(t3,text=" "))
tkgrid(Q3,sticky="w")
tkgrid(l.Q3.prop,row=9,column=0,rowspan=1,columnspan=4, sticky="w" )
tkgrid(b.Q3.prop,row=9,column=4,rowspan=1,columnspan=2, sticky="ew")
tkgrid(l.Q3.scal,row=10,column=0,rowspan=1,columnspan=4, sticky="w" )
tkgrid(b.Q3.scal,row=10,column=4,rowspan=1,columnspan=2, sticky="ew")
*** Error in structure(.External(.C_dotTclObjv, objv), class = "tclObj") : [tcl] can't read ".19.6 ": no such variable. (or variations on this with different numbers)
**** Error in as.integer(substitute(groups)) : cannot coerce type 'symbol' to vector of type 'integer' (or variations such as " ... type 'closure' to vector of type 'integer' )
I would really appreciate some practical help here, as Googling the error messages produced either solutions which got me to new erro messages (at least that felt like progress) but also sometimes no results (which surprised me). Calling the help files related to things like environment, get, mget, deparse, function etc from R actually leaves me even more puzzled than before I read them.
thanks in advance, yours