TABLE OF CONTENTS
S3Methods/splinesurvtkplot [ Functions ]
NAME
splinesurvtkplot --- plot the curve using tcltk
FUNCTION
Uses tcltk and the tkrplot package to plot the curve, with a slider to select the iteration.
SYNOPSIS
3941 splinesurvtkplot <- function(x, ...)
INPUTS
x a splinesurv object ... plotting parameters
SOURCE
3944 { 3945 library(tkrplot) 3946 which <- "h" 3947 # tk canvas 3948 tt <- tktoplevel() 3949 tktitle(tt) <- "SplineSurv" 3950 iter <- 0 3951 # tcl variables, to hold the selected iteration and plot type 3952 tcliter <- tclVar(iter) 3953 tclwhich <- tclVar(which) 3954 maxiter = x$control$maxiter 3955 res <- max(1, round(maxiter / 100)) 3956 # plotting canvas 3957 img <- tkrplot(tt, function() plot(x = x, which = which, iter = iter, ...)) 3958 3959 # an inner function to set the iteration 3960 setiter <- function(...){ 3961 # get the iteration from the tcliter variable 3962 thisiter <- round(as.numeric(tclvalue(tcliter))) 3963 if(iter != thisiter){ 3964 assign("iter", thisiter, inherits = TRUE) 3965 #replot if the iteration has changed 3966 tkrreplot(img) 3967 } 3968 } 3969 3970 # an inner function to set the type of plot to "hazard" 3971 setwhich_h <- function(...) { 3972 assign("which", "h", inherits = TRUE) 3973 tkrreplot(img) 3974 } 3975 # an inner function to set the type of plot to "survival" 3976 setwhich_s <- function(...) { 3977 assign("which", "s", inherits = TRUE) 3978 tkrreplot(img) 3979 } 3980 # an inner function to set the type of plot to "frailty" 3981 setwhich_f <- function(...){ 3982 assign("which", "f", inherits = TRUE) 3983 tkrreplot(img) 3984 } 3985 # an inner function to set the current iteration to 0, corresponding to 3986 # plotting the posterior mean. 3987 setpost <- function(...){ 3988 assign("iter", 0, inherits = TRUE) 3989 tclvalue(tcliter) <- 0 3990 tkrreplot(img) 3991 } 3992 3993 # a TK scale control, used to select the iteration to plot 3994 iter_scale <- tkscale(tt, command = setiter, from = 0, to = maxiter, resolution = res, 3995 showvalue = T, orient = "horiz", variable = tcliter, length = 400) 3996 # a frame containing the plot type buttons 3997 ff <- tkframe(tt, relief = "ridge", borderwidth = 2, width = 150, height = 100) 3998 # buttons to select the type of plot desired 3999 which_b_h <- tkradiobutton(ff, command = setwhich_h, text = "hazard", 4000 variable = tclwhich, value = "h" ) 4001 which_b_s <- tkradiobutton(ff, command = setwhich_s, text = "survival", 4002 variable = tclwhich, value = "s" ) 4003 which_b_f <- tkradiobutton(ff, command = setwhich_f, text = "frailty", 4004 variable = tclwhich, value = "f" ) 4005 # button to plot the posterior mean of the curve 4006 post_b <- tkbutton(tt, command = setpost, text = "Posterior" ) 4007 # layout on the grid 4008 tkgrid(img, columnspan = 2) 4009 tkgrid(which_b_h, which_b_s, which_b_f) 4010 tkgrid(ff, columnspan = 2) 4011 tkgrid(post_b, iter_scale) 4012 tkgrid.configure(iter_scale, sticky = "e") 4013 tkgrid.configure(post_b, sticky = "sw") 4014 4015 }