cross_table: cross_table

Description Usage Arguments Value Examples

Description

cross_table is for cross table analysis.

Usage

1
2
3
4
5
6
7
8
cross_table(
  dat,
  cross_x,
  cross_y = NULL,
  target = NULL,
  value = NULL,
  cross_type = "total_sum"
)

Arguments

dat

A data.frame with independent variables.

cross_x

Names of variables to cross.

cross_y

Names of variables to cross.

target

The name of target variable.

value

The name of the variable to sum. When this parameter is NULL, the default statistics is to sum frequency.

cross_type

Output form of the result of crosstable. Provide these forms: "total_sum","total_pct","total_mean","total_median","total_max","total_min","bad_sum","bad_pct".

Value

A cross table.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cross_table(dat = UCICreditCard, cross_x = "SEX",cross_y = "AGE",
 target = "default.payment.next.month", cross_type = "bad_pct",value = "LIMIT_BAL")
cross_table(dat = UCICreditCard, cross_x = "SEX",cross_y = "AGE",
 target = "default.payment.next.month", cross_type = "total_pct",value = "LIMIT_BAL")
cross_table(dat = UCICreditCard, cross_x = "SEX",cross_y = "AGE",
 target = "default.payment.next.month", cross_type = "total_mean",value = "LIMIT_BAL")
cross_table(dat = UCICreditCard, cross_x = "SEX",cross_y = "AGE",
 target = "default.payment.next.month", cross_type = "total_median",value = "LIMIT_BAL")
cross_table(dat = UCICreditCard, cross_x = c("SEX", "MARRIAGE"), cross_y = "AGE",
target = "default.payment.next.month", cross_type = "bad_pct",value = "LIMIT_BAL")

Example output

Package 'creditmodel' version 1.2.7
     SEX 01.(-Inf,27] 02.(27,31] 03.(31,37] 04.(37,43] 05.(43, Inf]  sum_x
1 female          19%     15.63%     17.42%     20.29%       20.65% 18.61%
2   male       18.29%     14.77%     15.46%     15.71%       18.15% 16.29%
3  sum_y       18.48%     15.08%     16.22%     17.61%       19.31% 17.18%
     SEX 01.(-Inf,27] 02.(27,31] 03.(31,37] 04.(37,43] 05.(43, Inf]  sum_x
1 female        3.56%      7.42%     10.25%      7.99%        9.48% 38.69%
2   male        9.69%     13.07%     16.32%      11.3%       10.93% 61.31%
3  sum_y       13.25%     20.48%     26.57%     19.29%       20.41%   100%
     SEX 01.(-Inf,27] 02.(27,31] 03.(31,37] 04.(37,43] 05.(43, Inf]   mean_x
1 female     82849.86   171933.5   191042.3   187614.6     174558.7 161599.8
2   male    109547.91   189794.7   203382.9   194679.5     168550.0 173191.0
3 mean_y     96198.88   180864.1   197212.6   191147.0     171554.3 167395.4
       SEX 01.(-Inf,27] 02.(27,31] 03.(31,37] 04.(37,43] 05.(43, Inf] median_x
1   female        50000     150000     170000     160000       130000   150000
2     male        80000     180000     190000     180000       140000   180000
3 median_y        65000     165000     180000     170000       135000   165000
     SEX MARRIAGE/AGE 01.(-Inf,27] 02.(27,31] 03.(31,37] 04.(37,43]
1 female            D       26.25%      1.41%     10.29%        32%
2 female            M       18.33%     14.84%     16.43%     18.76%
3 female            N       25.75%     19.39%     18.77%     20.77%
4 female      missing       67.57%         0%         0%         0%
5   male            D       21.05%     26.83%      7.67%     10.78%
6   male            M       17.51%     14.27%     14.55%     15.39%
7   male            N       22.81%     16.15%     16.35%     15.86%
8   male      missing           0%         0%         0%     47.17%
9  sum_y        sum_y       18.48%     15.08%     16.22%     17.61%
  05.(43, Inf]  sum_x
1       38.05%  28.1%
2       17.22% 16.58%
3       21.12% 20.42%
4           0% 13.74%
5       14.94% 13.99%
6       16.91% 15.52%
7       18.64% 17.14%
8         5.7%  6.72%
9       19.31% 17.18%

creditmodel documentation built on Jan. 25, 2021, 5:08 p.m.