cro: Cross tabulation with support of labels, weights and multiple...

Description Usage Arguments Value See Also Examples

Description

You can combine tables with add_rows and merge.etable. For sorting table see tab_sort_asc. To provide multiple-response variables as arguments use mrset for multiples with category encoding and mdset for multiples with dichotomy (dummy) encoding. To compute statistics with nested variables/banners use nest. For more sophisticated interface with modern piping via magrittr see tables.

Usage

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
cro(cell_vars, col_vars = total(), row_vars = NULL, weight = NULL,
  subgroup = NULL, total_label = NULL, total_statistic = "u_cases",
  total_row_position = c("below", "above", "none"))

cro_cases(cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

cro_cpct(cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

cro_rpct(cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

cro_tpct(cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

cro_cpct_responses(cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_responses", total_row_position = c("below",
  "above", "none"))

calc_cro(data, cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

calc_cro_cases(data, cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

calc_cro_cpct(data, cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

calc_cro_rpct(data, cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

calc_cro_tpct(data, cell_vars, col_vars = total(), row_vars = NULL,
  weight = NULL, subgroup = NULL, total_label = NULL,
  total_statistic = "u_cases", total_row_position = c("below", "above",
  "none"))

calc_cro_cpct_responses(data, cell_vars, col_vars = total(),
  row_vars = NULL, weight = NULL, subgroup = NULL,
  total_label = NULL, total_statistic = "u_responses",
  total_row_position = c("below", "above", "none"))

total(x = 1, label = "#Total")

Arguments

cell_vars

vector/data.frame/list. Variables on which percentage/cases will be computed. Use mrset/mdset for multiple-response variables.

col_vars

vector/data.frame/list. Variables which breaks table by columns. Use mrset/mdset for multiple-response variables.

row_vars

vector/data.frame/list. Variables which breaks table by rows. Use mrset/mdset for multiple-response variables.

weight

numeric vector. Optional cases weights. Cases with NA's, negative and zero weights are removed before calculations.

subgroup

logical vector. You can specify subgroup on which table will be computed.

total_label

By default "#Total". You can provide several names - each name for each total statistics.

total_statistic

By default it is "u_cases" (unweighted cases). Possible values are "u_cases", "u_responses", "u_cpct", "u_rpct", "u_tpct", "w_cases", "w_responses", "w_cpct", "w_rpct", "w_tpct". "u_" means unweighted statistics and "w_" means weighted statistics.

total_row_position

Position of total row in the resulting table. Can be one of "below", "above", "none".

data

data.frame in which context all other arguments will be evaluated (for calc_cro_*).

x

vector/data.frame of class 'category'/'dichotomy'.

label

character. Label for total variable.

Value

object of class 'etable'. Basically it's a data.frame but class is needed for custom methods.

See Also

tables, fre, cro_fun.

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
data(mtcars)
mtcars = apply_labels(mtcars,
                      mpg = "Miles/(US) gallon",
                      cyl = "Number of cylinders",
                      disp = "Displacement (cu.in.)",
                      hp = "Gross horsepower",
                      drat = "Rear axle ratio",
                      wt = "Weight (1000 lbs)",
                      qsec = "1/4 mile time",
                      vs = "Engine",
                      vs = c("V-engine" = 0,
                             "Straight engine" = 1),
                      am = "Transmission",
                      am = c("Automatic" = 0,
                             "Manual"=1),
                      gear = "Number of forward gears",
                      carb = "Number of carburetors"
)

calculate(mtcars, cro(am, vs))
calc_cro(mtcars, am, vs) # the same result

# column percent with multiple banners
calculate(mtcars, cro_cpct(cyl, list(total(), vs, am)))
calc_cro_cpct(mtcars, cyl, list(total(), vs, am)) # the same result

# nested banner
calculate(mtcars, cro_cpct(cyl, list(total(), vs %nest% am)))

# stacked variables
calculate(mtcars, cro(list(cyl, carb), list(total(), vs %nest% am)))

# nested variables
calculate(mtcars, cro_cpct(am %nest% cyl, list(total(), vs)))

# row variables
calculate(mtcars, cro_cpct(cyl, list(total(), vs), row_vars = am))

# several totals above table
calculate(mtcars, cro_cpct(cyl, 
              list(total(), vs), 
              row_vars = am,
              total_row_position = "above",
              total_label = c("number of cases", "row %"),
              total_statistic = c("u_cases", "u_rpct")
              ))

# multiple-choice variable
# brands - multiple response question
# Which brands do you use during last three months? 
set.seed(123)
brands = data.frame(t(replicate(20,sample(c(1:5,NA),4,replace = FALSE))))
# score - evaluation of tested product
score = sample(-1:1,20,replace = TRUE)
var_lab(brands) = "Used brands"
val_lab(brands) = make_labels("
                              1 Brand A
                              2 Brand B
                              3 Brand C
                              4 Brand D
                              5 Brand E
                              ")

var_lab(score) = "Evaluation of tested brand"
val_lab(score) = num_lab("
                             -1 Dislike it
                             0 So-so
                             1 Like it    
                             ")

cro_cpct(mrset(brands), list(total(), score))
# responses
cro_cpct_responses(mrset(brands), list(total(), score))

gdemin/expss documentation built on May 16, 2019, 11:14 p.m.