Comparing the biggest units with respect to two numerical variables
Rank2NumVar.Rd
Calculating rank and share for two numerical variables, and the ratio between the variables Listing big units, either the k biggest units or units with value greater than a threshold
Usage
Rank2NumVar(
data,
idVar,
xVar,
yVar,
strataVar = NULL,
antall = 5,
grense = NULL,
identiske = FALSE
)
Arguments
- data
Input data set of class data.frame.
- idVar
Name of an identification variable.
- xVar
Name of the x variable to be compared.
- yVar
Name of the y variable to be compared.
- strataVar
Name of stratification variable. Optional. If strataVar is given, the calculation and listing is performed within each stratum.
- antall
Parameter specifying how many of the biggest units to be listed. Default 5.
- grense
Parameter specifying a threshold for the units to be listed. This parameter overrules antall. Optional.
- identiske
When TRUE, only units with value on both x and y are used in the calculations. Default FALSE.
Value
Output of Rank2NumVar is a data set of class data.frame. The variables in the data frame are:
- id
The input identification variable
- x
The input x variable
- y
The input y variable
- strata
The input strata variable if strataVar is given, "1" otherwise
- forh
The ratio between x and y: y/x
- xRank
The rank of x
- yRank
The rank of y
- xProsAvSumx
x in percent of the total/stratum total for x
- yProsAvSumy
y in percent of the total/stratum total for y
Examples
testdata <- KostraData("testdata")
# lager en grupperingsvariabel
testdata$gr <- as.character(c(rep(3, 30), rep(5, 40), rep(1, 61), rep(2, 91), rep(3, 68),
rep(4, 61), rep(5, 45), rep(4, 20)))
# uten strata
Rank2NumVar(data = testdata, idVar = "Region", xVar = "areal_130_eier_2014", yVar = "areal_130_eier_2015",
strataVar = NULL, antall = 10, grense = NULL, identiske = FALSE)
#> id x y strata forh xRank yRank xProsAvSumx yProsAvSumy
#> 1 120100 50336 50336 1 1.0000000 1 1 2.9724902 2.9868052
#> 2 110200 24000 33029 1 1.3762083 4 2 1.4172712 1.9598535
#> 3 21900 28000 28015 1 1.0005357 2 3 1.6534831 1.6623360
#> 4 10600 25306 25306 1 1.0000000 3 4 1.4943944 1.5015911
#> 5 112000 12141 22815 1 1.8791698 22 5 0.7169621 1.3537818
#> 6 100100 21802 21802 1 1.0000000 5 6 1.2874728 1.2936730
#> 7 23100 21518 21518 1 1.0000000 6 7 1.2707018 1.2768212
#> 8 62400 19400 19400 1 1.0000000 7 8 1.1456276 1.1511447
#> 9 190200 10765 19292 1 1.7921040 30 9 0.6357052 1.1447363
#> 10 110300 19132 18953 1 0.9906439 8 10 1.1298014 1.1246209
#> 11 80500 17376 16941 1 0.9749655 9 11 1.0261044 1.0052341
#> 12 22000 16708 16708 1 1.0000000 10 13 0.9866570 0.9914085
# med strata
Rank2NumVar(data = testdata, idVar = "Region", xVar = "areal_130_eier_2014", yVar = "areal_130_eier_2015",
strataVar = "gr", antall = 10, grense = NULL, identiske = FALSE)
#> id x y strata forh xRank yRank xProsAvSumx yProsAvSumy
#> 1 62400 19400 19400 1 1.0000000 1 1 7.317634 6.992679
#> 2 80500 17376 16941 1 0.9749655 2 2 6.554186 6.106339
#> 3 60400 0 14677 1 Inf 59 3 0.000000 5.290286
#> 4 70100 6969 13646 1 1.9581002 10 4 2.628690 4.918665
#> 5 70600 9946 10255 1 1.0310678 3 5 3.751608 3.696388
#> 6 60500 9306 9126 1 0.9806576 4 6 3.510201 3.289443
#> 7 80600 8977 8977 1 1.0000000 5 7 3.386103 3.235736
#> 8 81400 8126 8126 1 1.0000000 6 8 3.065108 2.928995
#> 9 52800 7626 7626 1 1.0000000 7 9 2.876509 2.748772
#> 10 61700 6936 6936 1 1.0000000 11 10 2.616243 2.500063
#> 11 80700 7500 6030 1 0.8040000 8 14 2.828982 2.173498
#> 12 62500 7128 5066 1 0.7107183 9 20 2.688665 1.826026
#> 13 120100 50336 50336 2 1.0000000 1 1 12.303661 12.417788
#> 14 110200 24000 33029 2 1.3762083 2 2 5.866336 8.148187
#> 15 112000 12141 22815 2 1.8791698 6 3 2.967632 5.628414
#> 16 100100 21802 21802 2 1.0000000 3 4 5.329077 5.378509
#> 17 110300 19132 18953 2 0.9906439 4 5 4.676447 4.675666
#> 18 112400 14371 12100 2 0.8419734 5 6 3.512713 2.985045
#> 19 111900 5727 9645 2 1.6841278 17 7 1.399854 2.379402
#> 20 124700 11732 9399 2 0.8011422 7 8 2.867660 2.318714
#> 21 110600 8499 8499 2 1.0000000 9 9 2.077416 2.096686
#> 22 123500 7161 7161 2 1.0000000 12 10 1.750368 1.766604
#> 23 112100 11195 5510 2 0.4921840 8 18 2.736401 1.359306
#> 24 124600 8456 NA 2 NA 10 NA 2.066906 NA
#> 25 21900 28000 28015 3 1.0005357 1 1 7.371505 7.784345
#> 26 10600 25306 25306 3 1.0000000 2 2 6.662261 7.031613
#> 27 22000 16708 16708 3 1.0000000 3 3 4.398683 4.642543
#> 28 10500 16299 16287 3 0.9992638 4 4 4.291006 4.525562
#> 29 21700 14450 14450 3 1.0000000 5 5 3.804223 4.015127
#> 30 160100 14026 14022 3 0.9997148 6 6 3.692598 3.896201
#> 31 22100 7950 7950 3 1.0000000 9 7 2.092981 2.209014
#> 32 143200 8630 7685 3 0.8904983 8 8 2.272003 2.135381
#> 33 140100 7279 7279 3 1.0000000 12 9 1.916328 2.022568
#> 34 21300 7626 7226 3 0.9475479 11 10 2.007682 2.007841
#> 35 13600 10562 5648 3 0.5347472 7 13 2.780637 1.569373
#> 36 150500 7660 5040 3 0.6579634 10 17 2.016633 1.400432
#> 37 180400 15406 15448 4 1.0027262 1 1 5.468395 5.438383
#> 38 180500 15208 15208 4 1.0000000 2 2 5.398114 5.353893
#> 39 200400 10568 13690 4 1.2954201 7 3 3.751136 4.819489
#> 40 172100 12600 12600 4 1.0000000 3 4 4.472399 4.435761
#> 41 170200 12200 12209 4 1.0007377 4 5 4.330418 4.298111
#> 42 201200 10860 10860 4 1.0000000 5 6 3.854782 3.823203
#> 43 171900 10730 10726 4 0.9996272 6 7 3.808638 3.776029
#> 44 182400 8200 8200 4 1.0000000 8 8 2.910609 2.886765
#> 45 175100 NA 8000 4 NA NA 9 NA 2.816356
#> 46 171400 7495 7495 4 1.0000000 9 10 2.660367 2.638574
#> 47 165300 7100 7100 4 1.0000000 10 11 2.520161 2.499516
#> 48 23100 21518 21518 5 1.0000000 1 1 6.017355 6.001428
#> 49 190200 10765 19292 5 1.7921040 9 2 3.010355 5.380591
#> 50 23500 11878 16748 5 1.4100017 5 3 3.321598 4.671062
#> 51 42700 16127 15973 5 0.9904508 2 4 4.509800 4.454913
#> 52 23000 15531 13287 5 0.8555148 3 5 4.343133 3.705780
#> 53 190300 12229 12229 5 1.0000000 4 6 3.419752 3.410701
#> 54 50200 11379 11379 5 1.0000000 6 7 3.182056 3.173634
#> 55 41200 11316 11316 5 1.0000000 7 8 3.164438 3.156063
#> 56 30100 9861 9881 5 1.0020282 10 9 2.757558 2.755837
#> 57 50100 8724 8724 5 1.0000000 12 10 2.439604 2.433147
#> 58 40300 11234 3739 5 0.3328289 8 32 3.141508 1.042817
# med identiske = TRUE
Rank2NumVar(data = testdata, idVar = "Region", xVar = "areal_130_eier_2014", yVar = "areal_130_eier_2015",
strataVar = "gr", antall = 10, grense = NULL, identiske = TRUE)
#> id x y strata forh xRank yRank xProsAvSumx yProsAvSumy
#> 1 62400 19400 19400 1 1.0000000 1 1 7.398509 6.992679
#> 2 80500 17376 16941 1 0.9749655 2 2 6.626623 6.106339
#> 3 60400 0 14677 1 Inf 58 3 0.000000 5.290286
#> 4 70100 6969 13646 1 1.9581002 10 4 2.657743 4.918665
#> 5 70600 9946 10255 1 1.0310678 3 5 3.793071 3.696388
#> 6 60500 9306 9126 1 0.9806576 4 6 3.548996 3.289443
#> 7 80600 8977 8977 1 1.0000000 5 7 3.423526 3.235736
#> 8 81400 8126 8126 1 1.0000000 6 8 3.098984 2.928995
#> 9 52800 7626 7626 1 1.0000000 7 9 2.908300 2.748772
#> 10 61700 6936 6936 1 1.0000000 11 10 2.645158 2.500063
#> 11 80700 7500 6030 1 0.8040000 8 14 2.860248 2.173498
#> 12 62500 7128 5066 1 0.7107183 9 20 2.718380 1.826026
#> 13 120100 50336 50336 2 1.0000000 1 1 12.771194 12.417788
#> 14 110200 24000 33029 2 1.3762083 2 2 6.089253 8.148187
#> 15 112000 12141 22815 2 1.8791698 6 3 3.080401 5.628414
#> 16 100100 21802 21802 2 1.0000000 3 4 5.531579 5.378509
#> 17 110300 19132 18953 2 0.9906439 4 5 4.854150 4.675666
#> 18 112400 14371 12100 2 0.8419734 5 6 3.646194 2.985045
#> 19 111900 5727 9645 2 1.6841278 16 7 1.453048 2.379402
#> 20 124700 11732 9399 2 0.8011422 7 8 2.976630 2.318714
#> 21 110600 8499 8499 2 1.0000000 9 9 2.156357 2.096686
#> 22 123500 7161 7161 2 1.0000000 11 10 1.816881 1.766604
#> 23 101700 7682 5926 2 0.7714137 10 16 1.949068 1.461932
#> 24 112100 11195 5510 2 0.4921840 8 18 2.840383 1.359306
#> 25 21900 28000 28015 3 1.0005357 1 1 7.501775 7.784345
#> 26 10600 25306 25306 3 1.0000000 2 2 6.779997 7.031613
#> 27 22000 16708 16708 3 1.0000000 3 3 4.476416 4.642543
#> 28 10500 16299 16287 3 0.9992638 4 4 4.366837 4.525562
#> 29 21700 14450 14450 3 1.0000000 5 5 3.871452 4.015127
#> 30 160100 14026 14022 3 0.9997148 6 6 3.757853 3.896201
#> 31 22100 7950 7950 3 1.0000000 9 7 2.129968 2.209014
#> 32 143200 8630 7685 3 0.8904983 8 8 2.312154 2.135381
#> 33 140100 7279 7279 3 1.0000000 12 9 1.950194 2.022568
#> 34 21300 7626 7226 3 0.9475479 11 10 2.043162 2.007841
#> 35 13600 10562 5648 3 0.5347472 7 13 2.829777 1.569373
#> 36 150500 7660 5040 3 0.6579634 10 17 2.052271 1.400432
#> 37 180400 15406 15448 4 1.0027262 1 1 5.638865 5.595986
#> 38 180500 15208 15208 4 1.0000000 2 2 5.566394 5.509047
#> 39 200400 10568 13690 4 1.2954201 7 3 3.868073 4.959157
#> 40 172100 12600 12600 4 1.0000000 3 4 4.611820 4.564308
#> 41 170200 12200 12209 4 1.0007377 4 5 4.465413 4.422669
#> 42 201200 10860 10860 4 1.0000000 5 6 3.974950 3.933999
#> 43 171900 10730 10726 4 0.9996272 6 7 3.927367 3.885458
#> 44 182400 8200 8200 4 1.0000000 8 8 3.001343 2.970423
#> 45 171400 7495 7495 4 1.0000000 9 9 2.743301 2.715039
#> 46 165300 7100 7100 4 1.0000000 10 10 2.598724 2.571951
#> 47 23100 21518 21518 5 1.0000000 1 1 6.227967 6.111992
#> 48 190200 10765 19292 5 1.7921040 9 2 3.115720 5.479717
#> 49 23500 11878 16748 5 1.4100017 5 3 3.437856 4.757117
#> 50 42700 16127 15973 5 0.9904508 2 4 4.667647 4.536985
#> 51 23000 15531 13287 5 0.8555148 3 5 4.495146 3.774051
#> 52 190300 12229 12229 5 1.0000000 4 6 3.539446 3.473536
#> 53 50200 11379 11379 5 1.0000000 6 7 3.293431 3.232101
#> 54 41200 11316 11316 5 1.0000000 7 8 3.275196 3.214207
#> 55 30100 9861 9881 5 1.0020282 10 9 2.854075 2.806608
#> 56 50100 8724 8724 5 1.0000000 12 10 2.524992 2.477973
#> 57 40300 11234 3739 5 0.3328289 8 32 3.251463 1.062029
# med grense (overstyrer antall)
Rank2NumVar(data = testdata, idVar = "Region", xVar = "areal_130_eier_2014", yVar = "areal_130_eier_2015",
strataVar = "gr", antall = 10, grense = 10000, identiske = FALSE)
#> id x y strata forh xRank yRank xProsAvSumx yProsAvSumy
#> 1 62400 19400 19400 1 1.0000000 1 1 7.317634 6.992679
#> 2 80500 17376 16941 1 0.9749655 2 2 6.554186 6.106339
#> 3 60400 0 14677 1 Inf 59 3 0.000000 5.290286
#> 4 70100 6969 13646 1 1.9581002 10 4 2.628690 4.918665
#> 5 70600 9946 10255 1 1.0310678 3 5 3.751608 3.696388
#> 6 120100 50336 50336 2 1.0000000 1 1 12.303661 12.417788
#> 7 110200 24000 33029 2 1.3762083 2 2 5.866336 8.148187
#> 8 112000 12141 22815 2 1.8791698 6 3 2.967632 5.628414
#> 9 100100 21802 21802 2 1.0000000 3 4 5.329077 5.378509
#> 10 110300 19132 18953 2 0.9906439 4 5 4.676447 4.675666
#> 11 112400 14371 12100 2 0.8419734 5 6 3.512713 2.985045
#> 12 124700 11732 9399 2 0.8011422 7 8 2.867660 2.318714
#> 13 112100 11195 5510 2 0.4921840 8 18 2.736401 1.359306
#> 14 21900 28000 28015 3 1.0005357 1 1 7.371505 7.784345
#> 15 10600 25306 25306 3 1.0000000 2 2 6.662261 7.031613
#> 16 22000 16708 16708 3 1.0000000 3 3 4.398683 4.642543
#> 17 10500 16299 16287 3 0.9992638 4 4 4.291006 4.525562
#> 18 21700 14450 14450 3 1.0000000 5 5 3.804223 4.015127
#> 19 160100 14026 14022 3 0.9997148 6 6 3.692598 3.896201
#> 20 13600 10562 5648 3 0.5347472 7 13 2.780637 1.569373
#> 21 180400 15406 15448 4 1.0027262 1 1 5.468395 5.438383
#> 22 180500 15208 15208 4 1.0000000 2 2 5.398114 5.353893
#> 23 200400 10568 13690 4 1.2954201 7 3 3.751136 4.819489
#> 24 172100 12600 12600 4 1.0000000 3 4 4.472399 4.435761
#> 25 170200 12200 12209 4 1.0007377 4 5 4.330418 4.298111
#> 26 201200 10860 10860 4 1.0000000 5 6 3.854782 3.823203
#> 27 171900 10730 10726 4 0.9996272 6 7 3.808638 3.776029
#> 28 23100 21518 21518 5 1.0000000 1 1 6.017355 6.001428
#> 29 190200 10765 19292 5 1.7921040 9 2 3.010355 5.380591
#> 30 23500 11878 16748 5 1.4100017 5 3 3.321598 4.671062
#> 31 42700 16127 15973 5 0.9904508 2 4 4.509800 4.454913
#> 32 23000 15531 13287 5 0.8555148 3 5 4.343133 3.705780
#> 33 190300 12229 12229 5 1.0000000 4 6 3.419752 3.410701
#> 34 50200 11379 11379 5 1.0000000 6 7 3.182056 3.173634
#> 35 41200 11316 11316 5 1.0000000 7 8 3.164438 3.156063
#> 36 40300 11234 3739 5 0.3328289 8 32 3.141508 1.042817