1

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

Community
  • 1
  • 1

1 Answers1

1

I have found an answer (courtesy of Greg Snow enter link description here

sorry for answering my own Q, but editing was impossible through misplaced error calls "you're text appears to contain code blablabla" whilst I correctly designated it (cntrl K).

here's the code

    define.test<-function(){                
# create a function to call upon
require(tcltk)                    
# make sure tcltk package is active
#  define attributes of widget components   
t3<- tktoplevel()                 
# create main (toplevel) widget
tktitle(t3)<-"Statistical power"      
# widget looks better with title
fontHead    <-tkfont.create(family="times",size=16,weight="bold") 
# define font for heading, etc
fontSub     <-tkfont.create(family="times",size=14,weight="bold")
fontQ       <-tkfont.create(family="times",size=14)
fontQ.s     <-tkfont.create(family="times",size=12)
filename    <-tclVar("Your test")                  
# Default testname, to change in widget
groups      <-tclVar("")                          
# empty variable for number of groups, to fill in in widget
test        <-""                                        
# empty var for test, to be found by <<- in button function
submit.prop <- function(){                 
# function for proportional button
            test<<-"prop"                            
# reassign test in higer level
            tkdestroy(t3)}                            
# destroy widget, or nothing happens
submit.scal <- function(){                       
# function voor scalar button (same as above)
            test<<-"scale"
            tkdestroy(t3)}
###   build widget         
tkgrid(tklabel(t3, text="This module will give you insight in the statistical power requirements of your test", font=fontHead), columnspan=6)     
# header
tkgrid(tklabel(t3, text="     "))                # empty row
tkgrid(tklabel(t3, text="Please answer the following questions:", font=fontSub),  columnspan=6, sticky="w")           # sub header
tkgrid(tklabel(t3,text="     "))
tkgrid(tklabel(t3,text="What is the name of your test?", font=fontQ), row=5, column=0, rowspan=1, columnspan=2,sticky="w")          #Q1
tkgrid(tkentry(t3, textvariable=filename), row=5, column=2, rowspan=1, columnspan=3, sticky="ew") 
# entry for test name(= filename)

tkgrid(tklabel(t3,text="     "))
tkgrid(tklabel(t3,text="How many test-groups do you have?", font=fontQ), row=7, column=0, rowspan=1, columnspan=4, sticky="w")                      
#Q2
tkgrid(tkentry(t3,textvariable=groups),row=7,column=4,rowspan=1,columnspan=1,sticky="ew")                                                      # entry for number of groups to test

tkgrid(tklabel(t3,text="     "))
tkgrid(tklabel(t3,text="What type of differences do you want to test for?",font=fontQ), sticky="w")                                             #Q3
tkgrid(tklabel(t3,text="Proportional differences (e.g. click through rate, bounce rate, gender rate, etc)",  font=fontQ.s),row=10,column=0,rowspan=1,columnspan=4, sticky="w" )
tkgrid(tkbutton(t3,text="Proportional",command=submit.prop),row=10,column=4,rowspan=1,columnspan=2, sticky="ew")            # define test as proportional
tkgrid(tklabel(t3,text="Scaled differences (e.g. converted value, age, numer of sessions before conversion, etc)",  font=fontQ.s),row=11,column=0,rowspan=1,columnspan=4, sticky="w" )
tkgrid(tkbutton(t3,text="Scale",command=submit.scal),row=11,column=4,rowspan=1,columnspan=2, sticky="ew")        # define test as scalar

tkfocus(t3)            # focus on widget
tkwait.window(t3)         # wait for user to give input
return(c(tclvalue(filename),tclvalue(groups),test))        # create character string with user input
}
input       <-define.test()
filename    <-input[1]
groups      <-as.numeric(input[2])
test        <-input[3]