tab1: One-way tabulation

Description Usage Arguments Details Value Author(s) See Also Examples

Description

One-way tabulation with automatic bar chart and optional indicator variables generation

Usage

1
2
3
4
5
6
7
8
tab1(x0, decimal = 1, sort.group = FALSE, 
    cum.percent = !any(is.na(x0)), graph = TRUE, 
    missing = TRUE, bar.values = "frequency", 
    horiz = FALSE, cex = 1, cex.names = 1, main = "auto", xlab = "auto", 
    ylab = "auto", col = "auto", gen.ind.vars = FALSE, ...) 

## S3 method for class 'tab1'
print(x, ...)

Arguments

x0

a variable

decimal

number of decimals for the percentages in the table

sort.group

pattern for sorting categories in the table and in the chart. Default is no sorting. I can also be "decreasing" or "increasing".

cum.percent

presence of cumulative percentage in the output table. Default is TRUE for a variable without any missing values.

graph

whether a graph should be shown

missing

include the missing values category or <NA> in the graphic display

bar.values

include the value of frequency. This can also be "percent" or "none" at the end of each bar

horiz

set the bar chart to horizontal orientation

cex

parameter for extension of characters or relative size of the bar.values

cex.names

character extension or relative scale of the name labels for the bars

main

main title of the graph

xlab

label of X axis

ylab

label of Y axis

col

colours of the bar

gen.ind.vars

whether the indicator variables will be generated

x

object of class 'tab1' obtained from saving 'tab1' results

...

further arguments passed to or used by other methods

Details

'tab1' is an advanced one-way tabulation providing a nice frequency table as well as a bar chart. The description of the variable is also used in the main title of the graph.

The bar chart is vertical unless the number of categories is more than six and any of the labels of the levels consists of more than 8 characters or 'horiz' is set to TRUE.

For table has less than categories, the automatic colour is "grey". Otherwise, the graph will be colourful. The argument, 'col' can be overwritten by the user.

The argument 'gen.ind.vars' is effective only if x0 is factor.

Value

Output table

Author(s)

Virasakdi Chongsuvivatwong <[email protected]>

See Also

'tabpct', 'label.var', 'table', 'barplot', 'model.matrix'

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
tab1(state.division)
tab1(state.division, bar.values ="percent")
tab1(state.division, sort.group ="decreasing")
tab1(state.division, sort.group ="increasing")
tab1(state.division, col=c("chocolate","brown1","brown4"),
  main="Number of states in each zone")
# For presentation, several 'cex' parameters should increase
tab1(state.division, col=c("chocolate","brown1","brown4"),
  main="Number of states in each zone",
  cex.main=1.7, cex.name=1.2, cex.axis=1.3, cex.lab=1.3)


data(Oswego)
.data <- Oswego
attach(.data)
tab1(ill) # Note the column of cumulative percentages in the table.
tab1(ill, cum.percent=FALSE)
tab1(chocolate) 
# Due to missing values, cumulative percentages are now automatically turned off.
tab1(chocolate, cum.percent=TRUE)
# Slightly too many columns in text!
tab1(chocolate, missing=FALSE, bar.values="percent")
agegr <- cut(age, breaks=c(0,10,20,30,40,50,60,70,80))
tab1(agegr) # No need to start with 'calc' as it is outside .data
tab1(agegr, col="grey") # graphic output from older versions of 'tab1'
tab1(agegr, col=c("red","yellow","blue")) # Colours recycled
tab1(agegr, horiz=TRUE)

# Keeping output table
dev.off()
tab1(agegr, graph = FALSE) -> a
print(a)
a # same results
attributes(a)
a$output.table
class(a$output.table) # "matrix" 
# 'a$output.table' is ready for exporting to a .csv file by 
# write.csv(a$output.table, file="table1.csv") 
# "table1.csv" is now readable by a spreadsheet program
detach(.data)
rm(list=ls())

Example output

Loading required package: foreign
Loading required package: survival
Loading required package: MASS
Loading required package: nnet
state.division : 
                   Frequency Percent Cum. percent
New England                6      12           12
Middle Atlantic            3       6           18
South Atlantic             8      16           34
East South Central         4       8           42
West South Central         4       8           50
East North Central         5      10           60
West North Central         7      14           74
Mountain                   8      16           90
Pacific                    5      10          100
  Total                   50     100          100
state.division : 
                   Frequency Percent Cum. percent
New England                6      12           12
Middle Atlantic            3       6           18
South Atlantic             8      16           34
East South Central         4       8           42
West South Central         4       8           50
East North Central         5      10           60
West North Central         7      14           74
Mountain                   8      16           90
Pacific                    5      10          100
  Total                   50     100          100
state.division : 
                   Frequency Percent Cum. percent
South Atlantic             8      16           16
Mountain                   8      16           32
West North Central         7      14           46
New England                6      12           58
Pacific                    5      10           68
East North Central         5      10           78
West South Central         4       8           86
East South Central         4       8           94
Middle Atlantic            3       6          100
  Total                   50     100          100
state.division : 
                   Frequency Percent Cum. percent
Middle Atlantic            3       6            6
East South Central         4       8           14
West South Central         4       8           22
East North Central         5      10           32
Pacific                    5      10           42
New England                6      12           54
West North Central         7      14           68
Mountain                   8      16           84
South Atlantic             8      16          100
  Total                   50     100          100
state.division : 
                   Frequency Percent Cum. percent
New England                6      12           12
Middle Atlantic            3       6           18
South Atlantic             8      16           34
East South Central         4       8           42
West South Central         4       8           50
East North Central         5      10           60
West North Central         7      14           74
Mountain                   8      16           90
Pacific                    5      10          100
  Total                   50     100          100
state.division : 
                   Frequency Percent Cum. percent
New England                6      12           12
Middle Atlantic            3       6           18
South Atlantic             8      16           34
East South Central         4       8           42
West South Central         4       8           50
East North Central         5      10           60
West North Central         7      14           74
Mountain                   8      16           90
Pacific                    5      10          100
  Total                   50     100          100
ill : 
        Frequency Percent Cum. percent
FALSE          29    38.7         38.7
TRUE           46    61.3        100.0
  Total        75   100.0        100.0
ill : 
        Frequency Percent
FALSE          29    38.7
TRUE           46    61.3
  Total        75   100.0
chocolate : 
        Frequency   %(NA+)   %(NA-)
FALSE          27     36.0     36.5
TRUE           47     62.7     63.5
<NA>            1      1.3      0.0
  Total        75    100.0    100.0
chocolate : 
        Frequency   %(NA+) cum.%(NA+)   %(NA-) cum.%(NA-)
FALSE          27     36.0       36.0     36.5       36.5
TRUE           47     62.7       98.7     63.5      100.0
<NA>            1      1.3      100.0      0.0      100.0
  Total        75    100.0      100.0    100.0      100.0
chocolate : 
        Frequency   %(NA+)   %(NA-)
FALSE          27     36.0     36.5
TRUE           47     62.7     63.5
<NA>            1      1.3      0.0
  Total        75    100.0    100.0
agegr : 
        Frequency Percent Cum. percent
(0,10]          7     9.3          9.3
(10,20]        19    25.3         34.7
(20,30]         4     5.3         40.0
(30,40]        15    20.0         60.0
(40,50]         5     6.7         66.7
(50,60]        10    13.3         80.0
(60,70]        12    16.0         96.0
(70,80]         3     4.0        100.0
  Total        75   100.0        100.0
agegr : 
        Frequency Percent Cum. percent
(0,10]          7     9.3          9.3
(10,20]        19    25.3         34.7
(20,30]         4     5.3         40.0
(30,40]        15    20.0         60.0
(40,50]         5     6.7         66.7
(50,60]        10    13.3         80.0
(60,70]        12    16.0         96.0
(70,80]         3     4.0        100.0
  Total        75   100.0        100.0
agegr : 
        Frequency Percent Cum. percent
(0,10]          7     9.3          9.3
(10,20]        19    25.3         34.7
(20,30]         4     5.3         40.0
(30,40]        15    20.0         60.0
(40,50]         5     6.7         66.7
(50,60]        10    13.3         80.0
(60,70]        12    16.0         96.0
(70,80]         3     4.0        100.0
  Total        75   100.0        100.0
agegr : 
        Frequency Percent Cum. percent
(0,10]          7     9.3          9.3
(10,20]        19    25.3         34.7
(20,30]         4     5.3         40.0
(30,40]        15    20.0         60.0
(40,50]         5     6.7         66.7
(50,60]        10    13.3         80.0
(60,70]        12    16.0         96.0
(70,80]         3     4.0        100.0
  Total        75   100.0        100.0
null device 
          1 
agegr : 
        Frequency Percent Cum. percent
(0,10]          7     9.3          9.3
(10,20]        19    25.3         34.7
(20,30]         4     5.3         40.0
(30,40]        15    20.0         60.0
(40,50]         5     6.7         66.7
(50,60]        10    13.3         80.0
(60,70]        12    16.0         96.0
(70,80]         3     4.0        100.0
  Total        75   100.0        100.0
agegr : 
        Frequency Percent Cum. percent
(0,10]          7     9.3          9.3
(10,20]        19    25.3         34.7
(20,30]         4     5.3         40.0
(30,40]        15    20.0         60.0
(40,50]         5     6.7         66.7
(50,60]        10    13.3         80.0
(60,70]        12    16.0         96.0
(70,80]         3     4.0        100.0
  Total        75   100.0        100.0
$names
[1] "first.line"   "output.table"

$class
[1] "tab1" "list"

        Frequency Percent Cum. percent
(0,10]          7     9.3          9.3
(10,20]        19    25.3         34.7
(20,30]         4     5.3         40.0
(30,40]        15    20.0         60.0
(40,50]         5     6.7         66.7
(50,60]        10    13.3         80.0
(60,70]        12    16.0         96.0
(70,80]         3     4.0        100.0
  Total        75   100.0        100.0
[1] "matrix"

epiDisplay documentation built on May 2, 2019, 5:16 a.m.