box5num MACRO DOLLARS ) Macro to make simplified box plot as done in Moore's "The Basic ) Practice of Statistics", reflecting only the 5 number summary ) with no information on outliers ) Usage: ) box5num(x [,fivenum:T], [,graphics keyword phrases]) ) x REAL vector or a structure of REAL vectors ) ) where x is a REAL vector or a structure of REAL vectors )) Version of 000125 by C. Bingham, kb@stat.umn.edu # $S(x [,fivenum:T][,graphics keyword phrases]), x a structure or REAL vector @x <- argvalue($1,"$1") if (isstruc(@x)){ @nboxes <- ncomps(@x) # Check that all components are REAL vectors for(@i,1,@nboxes){ argvalue(@x[@i],paste("component",@i,"of $1"),"real vector") } @xticklabs <- compnames(@x) if (@xticklabs[1] == "col1" || @xticklabs[1] == "comp1") { @xticklabs <- getlabels(vector(run(@nboxes),labels:"Group ")) } }else{ @x <- structure(argvalue(@x,"$1","real vector")) @nboxes <- 1 @xticklabs <- "$1" } @fivenum <- keyvalue($K,"fivenum*","TF",default:F) @d <- .25 # half width of boxes if (@fivenum){ @names <- vector("Min","Q1","M","Q3","Max") @result <- if(@nboxes > 1){ @labs <- keyvalue($K,"xticklab*","character vector") if (anytrue(isnull(@labs), length(@labs) != @nboxes)) { @labs <- @xticklabs } matrix(rep(0,5*@nboxes),5,\ labels:structure(@names,delete(@labs,return:T))) }else{ vector(0,0,0,0,0,labels:@names) } delete(@names) } for (@i,1,@nboxes){ @y <- @x[@i] @y <- sort(@y[!ismissing(@y)]) @n <- length(@y) @J <- run(floor(@n/2)) @fn <- vector(min(@y),describe(@y[@J],median:T), describe(@y,median:T),\ describe(@y[@n+1 - @J],median:T), max(@y)) # 5 number summary if (@fivenum){ @result[,@i] <- @fn } lineplot(vector(@i-@d,@i+@d,?,\ @i,@i,?,\ @i-@d,@i+@d,@i+@d,@i-@d,@i-@d,?,\ @i-@d,@i+@d,?,\ @i,@i,?,\ @i-@d,@i+@d),\ vector(@fn[1],@fn[1],?,\ @fn[1],@fn[2],?,\ @fn[2],@fn[2],@fn[4],@fn[4],@fn[2],?,\ @fn[3], @fn[3],?,\ @fn[4], @fn[5],?,\ @fn[5],@fn[5]), add:@i>1,xticks:NULL,yticks:NULL,show:F) } @x <- vector(@x) @x <- @x[!ismissing(@x)] @ymin <- min(@x) @ymax <- max(@x) @r <- @ymax - @ymin # range @ymin <-- .05*@r # adjust y extremes @ymax <-+ .05*@r @pad <- if (@nboxes > 5){ 1 }else{ (6 - @nboxes)/2 } showplot(notakey:NULL,$K,xmin:1-@pad,xmax:@nboxes+@pad,ymin:@ymin,ymax:@ymax,\ yaxis:F,xticks:run(@nboxes),xticklen:0,xticklabs:@xticklabs,yticks:?) delete(@x,@y,@i,@d,@J,@fn,@ymin,@ymax,@r,@pad,@nboxes) if (delete(@fivenum,return:T)){ delete(@result,return:T) }else{NULL} %box5num%