
Fast (Grouped, Weighted) Summary Statistics for Cross-Sectional and Panel Data
qsu.Rdqsu, shorthand for quick-summary, is an extremely fast summary command inspired by the (xt)summarize command in the STATA statistical software.
It computes a set of 7 statistics (nobs, mean, sd, min, max, skewness and kurtosis) using a numerically stable one-pass method generalized from Welford's Algorithm. Statistics can be computed weighted, by groups, and also within-and between entities (for panel data, see Details).
Usage
qsu(x, ...)
# Default S3 method
qsu(x, g = NULL, pid = NULL, w = NULL, higher = FALSE,
array = TRUE, stable.algo = .op[["stable.algo"]], ...)
# S3 method for class 'matrix'
qsu(x, g = NULL, pid = NULL, w = NULL, higher = FALSE,
array = TRUE, stable.algo = .op[["stable.algo"]], ...)
# S3 method for class 'data.frame'
qsu(x, by = NULL, pid = NULL, w = NULL, cols = NULL, higher = FALSE,
array = TRUE, labels = FALSE, stable.algo = .op[["stable.algo"]], ...)
# S3 method for class 'grouped_df'
qsu(x, pid = NULL, w = NULL, higher = FALSE,
array = TRUE, labels = FALSE, stable.algo = .op[["stable.algo"]], ...)
# Methods for indexed data / compatibility with plm:
# S3 method for class 'pseries'
qsu(x, g = NULL, w = NULL, effect = 1L, higher = FALSE,
array = TRUE, stable.algo = .op[["stable.algo"]], ...)
# S3 method for class 'pdata.frame'
qsu(x, by = NULL, w = NULL, cols = NULL, effect = 1L, higher = FALSE,
array = TRUE, labels = FALSE, stable.algo = .op[["stable.algo"]], ...)
# Methods for compatibility with sf:
# S3 method for class 'sf'
qsu(x, by = NULL, pid = NULL, w = NULL, cols = NULL, higher = FALSE,
array = TRUE, labels = FALSE, stable.algo = .op[["stable.algo"]], ...)
# S3 method for class 'qsu'
as.data.frame(x, ..., gid = "Group", stringsAsFactors = TRUE)
# S3 method for class 'qsu'
print(x, digits = .op[["digits"]] + 2L, nonsci.digits = 9, na.print = "-",
return = FALSE, print.gap = 2, ...)Arguments
- x
a vector, matrix, data frame, 'indexed_series' ('pseries') or 'indexed_frame' ('pdata.frame').
- g
a factor,
GRPobject, atomic vector (internally converted to factor) or a list of vectors / factors (internally converted to aGRPobject) used to groupx.- by
(p)data.frame method: Same as
g, but also allows one- or two-sided formulas i.e.~ group1 + group2orvar1 + var2 ~ group1 + group2. See Examples.- pid
same input as
g/by: Specify a panel-identifier to also compute statistics on between- and within- transformed data. Data frame method also supports one- or two-sided formulas, grouped_df method supports expressions evaluated in the data environment. Transformations are taken independently from grouping withg/by(grouped statistics are computed on the transformed data ifg/byis also used). However, passing any LHS variables topidwill overwrite anyLHSvariables passed toby.- w
a vector of (non-negative) weights. Adding weights will compute the weighted mean, sd, skewness and kurtosis, and transform the data using weighted individual means if
pidis used. A"WeightSum"column will be added giving the sum of weights, see also Details. Data frame method supports formula, grouped_df method supports expression.- cols
select columns to summarize using column names, indices, a logical vector or a function (e.g.
is.numeric). Two-sided formulas passed tobyorpidoverwritecols.- higher
logical. Add higher moments (skewness and kurtosis).
- array
logical. If computations have more than 2 dimensions (up to a maximum of 4D: variables, statistics, groups and panel-decomposition)
TRUEreturns an array, whileFALSEreturns a (nested) list of matrices.- stable.algo
logical.
FALSEuses a faster but less stable method to calculate the standard deviation (see Details offsd). Only available ifw = NULLandhigher = FALSE.- labels
logical
TRUEor a function: to display variable labels in the summary. See Details.- effect
plm methods: Select which panel identifier should be used for between and within transformations of the data. 1L takes the first variable in the index, 2L the second etc.. Index variables can also be called by name using a character string. More than one variable can be supplied.
- ...
arguments to be passed to or from other methods.
- gid
character. Name assigned to the group-id column, when summarising variables by groups.
- stringsAsFactors
logical. Make factors from dimension names of 'qsu' array. Same as option to
as.data.frame.table.- digits
the number of digits to print after the comma/dot.
- nonsci.digits
the number of digits to print before resorting to scientific notation (default is to print out numbers with up to 9 digits and print larger numbers scientifically).
- na.print
character string to substitute for missing values.
- return
logical. Don't print but instead return the formatted object.
- print.gap
integer. Spacing between printed columns. Passed to
print.default.
Details
The algorithm used to compute statistics is well described here [see sections Welford's online algorithm, Weighted incremental algorithm and Higher-order statistics. Skewness and kurtosis are calculated as described in Higher-order statistics and are mathematically identical to those implemented in the moments package. Just note that qsu computes the kurtosis (like momens::kurtosis), not the excess-kurtosis (= kurtosis - 3) defined in Higher-order statistics. The Weighted incremental algorithm described can easily be generalized to higher-order statistics].
Grouped computations specified with g/by are carried out extremely efficiently as in fsum (in a single pass, without splitting the data).
If pid is used, qsu performs a panel-decomposition of each variable and computes 3 sets of statistics: Statistics computed on the 'Overall' (raw) data, statistics computed on the 'Between' - transformed (pid - averaged) data, and statistics computed on the 'Within' - transformed (pid - demeaned) data.
More formally, let x (bold) be a panel vector of data for N individuals indexed by i, recorded for T periods, indexed by t. xit then denotes a single data-point belonging to individual i in time-period t (t/T must not represent time). Then xi. denotes the average of all values for individual i (averaged over t), and by extension xN. is the vector (length N) of such averages for all individuals. If no groups are supplied to g/by, the 'Between' statistics are computed on xN., the vector of individual averages. (This means that for a non-balanced panel or in the presence of missing values, the 'Overall' mean computed on x can be slightly different than the 'Between' mean computed on xN., and the variance decomposition is not exact). If groups are supplied to g/by, xN. is expanded to the vector xi. (length N x T) by replacing each value xit in x with xi., while preserving missing values in x. Grouped Between-statistics are then computed on xi., with the only difference that the number of observations ('Between-N') reported for each group is the number of distinct non-missing values of xi. in each group (not the total number of non-missing values of xi. in each group, which is already reported in 'Overall-N'). See Examples.
'Within' statistics are always computed on the vector x - xi. + x.., where x.. is simply the 'Overall' mean computed from x, which is added back to preserve the level of the data. The 'Within' mean computed on this data will always be identical to the 'Overall' mean. In the summary output, qsu reports not 'N', which would be identical to the 'Overall-N', but 'T', the average number of time-periods of data available for each individual obtained as 'T' = 'Overall-N / 'Between-N'. When using weights (w) with panel data (pid), the 'Between' sum of weights is also simply the number of groups, and the 'Within' sum of weights is the 'Overall' sum of weights divided by the number of groups. See Examples.
Apart from 'N/T' and the extrema, the standard-deviations ('SD') computed on between- and within- transformed data are extremely valuable because they indicate how much of the variation in a panel-variable is between-individuals and how much of the variation is within-individuals (over time). At the extremes, variables that have common values across individuals (such as the time-variable(s) 't' in a balanced panel), can readily be identified as individual-invariant because the 'Between-SD' on this variable is 0 and the 'Within-SD' is equal to the 'Overall-SD'. Analogous, time-invariant individual characteristics (such as the individual-id 'i') have a 0 'Within-SD' and a 'Between-SD' equal to the 'Overall-SD'. See Examples.
For data frame methods, if labels = TRUE, qsu uses function(x) paste(names(x), setv(vlabels(x), NA, ""), sep = ": ") to combine variable names and labels for display. Alternatively, the user can pass a custom function which will be applied to the data frame, e.g. using labels = vlabels just displays the labels. See also vlabels.
qsu comes with its own print method which by default writes out up to 9 digits at 4 decimal places. Larger numbers are printed in scientific format. for numbers between 7 and 9 digits, an apostrophe (') is placed after the 6th digit to designate the millions. Missing values are printed using '-'.
The sf method simply ignores the geometry column.
Value
A vector, matrix, array or list of matrices of summary statistics. All matrices and arrays have a class 'qsu' and a class 'table' attached.
Note
In weighted summaries, observations with missing or zero weights are skipped, and thus do not affect any of the calculated statistics, including the observation count. This also implies that a logical vector passed to w can be used to efficiently summarize a subset of the data.
If weights w are used together with pid, transformed data is computed using weighted individual means i.e. weighted xi. and weighted x... Weighted statistics are subsequently computed on this weighted-transformed data.
References
Welford, B. P. (1962). Note on a method for calculating corrected sums of squares and products. Technometrics. 4 (3): 419-420. doi:10.2307/1266577.
Examples
## World Development Panel Data
# Simple Summaries -------------------------
qsu(wlddev) # Simple summary
#> N Mean SD Min Max
#> country 13176 - - - -
#> iso3c 13176 - - - -
#> date 13176 - - - -
#> year 13176 1990 17.6075 1960 2020
#> decade 13176 1985.5738 17.5117 1960 2020
#> region 13176 - - - -
#> income 13176 - - - -
#> OECD 13176 - - - -
#> PCGDP 9470 12048.778 19077.6416 132.0776 196061.417
#> LIFEEX 11670 64.2963 11.4764 18.907 85.4171
#> GINI 1744 38.5341 9.2006 20.7 65.8
#> ODA 8608 454'720131 868'712654 -997'679993 2.56715605e+10
#> POP 12919 24'245971.6 102'120674 2833 1.39771500e+09
qsu(wlddev, labels = TRUE) # Display variable labels
#> N
#> country: Country Name 13176
#> iso3c: Country Code 13176
#> date: Date Recorded (Fictitious) 13176
#> year: Year 13176
#> decade: Decade 13176
#> region: Region 13176
#> income: Income Level 13176
#> OECD: Is OECD Member Country? 13176
#> PCGDP: GDP per capita (constant 2010 US$) 9470
#> LIFEEX: Life expectancy at birth, total (years) 11670
#> GINI: Gini index (World Bank estimate) 1744
#> ODA: Net official development assistance and official aid received (constant 2018 US$) 8608
#> POP: Population, total 12919
#> Mean
#> country: Country Name -
#> iso3c: Country Code -
#> date: Date Recorded (Fictitious) -
#> year: Year 1990
#> decade: Decade 1985.5738
#> region: Region -
#> income: Income Level -
#> OECD: Is OECD Member Country? -
#> PCGDP: GDP per capita (constant 2010 US$) 12048.778
#> LIFEEX: Life expectancy at birth, total (years) 64.2963
#> GINI: Gini index (World Bank estimate) 38.5341
#> ODA: Net official development assistance and official aid received (constant 2018 US$) 454'720131
#> POP: Population, total 24'245971.6
#> SD
#> country: Country Name -
#> iso3c: Country Code -
#> date: Date Recorded (Fictitious) -
#> year: Year 17.6075
#> decade: Decade 17.5117
#> region: Region -
#> income: Income Level -
#> OECD: Is OECD Member Country? -
#> PCGDP: GDP per capita (constant 2010 US$) 19077.6416
#> LIFEEX: Life expectancy at birth, total (years) 11.4764
#> GINI: Gini index (World Bank estimate) 9.2006
#> ODA: Net official development assistance and official aid received (constant 2018 US$) 868'712654
#> POP: Population, total 102'120674
#> Min
#> country: Country Name -
#> iso3c: Country Code -
#> date: Date Recorded (Fictitious) -
#> year: Year 1960
#> decade: Decade 1960
#> region: Region -
#> income: Income Level -
#> OECD: Is OECD Member Country? -
#> PCGDP: GDP per capita (constant 2010 US$) 132.0776
#> LIFEEX: Life expectancy at birth, total (years) 18.907
#> GINI: Gini index (World Bank estimate) 20.7
#> ODA: Net official development assistance and official aid received (constant 2018 US$) -997'679993
#> POP: Population, total 2833
#> Max
#> country: Country Name -
#> iso3c: Country Code -
#> date: Date Recorded (Fictitious) -
#> year: Year 2020
#> decade: Decade 2020
#> region: Region -
#> income: Income Level -
#> OECD: Is OECD Member Country? -
#> PCGDP: GDP per capita (constant 2010 US$) 196061.417
#> LIFEEX: Life expectancy at birth, total (years) 85.4171
#> GINI: Gini index (World Bank estimate) 65.8
#> ODA: Net official development assistance and official aid received (constant 2018 US$) 2.56715605e+10
#> POP: Population, total 1.39771500e+09
qsu(wlddev, higher = TRUE) # Add skewness and kurtosis
#> N Mean SD Min Max Skew
#> country 13176 - - - - -
#> iso3c 13176 - - - - -
#> date 13176 - - - - -
#> year 13176 1990 17.6075 1960 2020 -0
#> decade 13176 1985.5738 17.5117 1960 2020 0.0326
#> region 13176 - - - - -
#> income 13176 - - - - -
#> OECD 13176 - - - - -
#> PCGDP 9470 12048.778 19077.6416 132.0776 196061.417 3.1276
#> LIFEEX 11670 64.2963 11.4764 18.907 85.4171 -0.6748
#> GINI 1744 38.5341 9.2006 20.7 65.8 0.596
#> ODA 8608 454'720131 868'712654 -997'679993 2.56715605e+10 6.9832
#> POP 12919 24'245971.6 102'120674 2833 1.39771500e+09 9.7494
#> Kurt
#> country -
#> iso3c -
#> date -
#> year 1.7994
#> decade 1.7917
#> region -
#> income -
#> OECD -
#> PCGDP 17.1154
#> LIFEEX 2.6718
#> GINI 2.5329
#> ODA 114.889
#> POP 108.9066
# Grouped Summaries ------------------------
qsu(wlddev, ~ region, labels = TRUE) # Statistics by World Bank Region
#> , , country: Country Name
#>
#> N Mean SD Min Max
#> East Asia & Pacific 2196 - - - -
#> Europe & Central Asia 3538 - - - -
#> Latin America & Caribbean 2562 - - - -
#> Middle East & North Africa 1281 - - - -
#> North America 183 - - - -
#> South Asia 488 - - - -
#> Sub-Saharan Africa 2928 - - - -
#>
#> , , iso3c: Country Code
#>
#> N Mean SD Min Max
#> East Asia & Pacific 2196 - - - -
#> Europe & Central Asia 3538 - - - -
#> Latin America & Caribbean 2562 - - - -
#> Middle East & North Africa 1281 - - - -
#> North America 183 - - - -
#> South Asia 488 - - - -
#> Sub-Saharan Africa 2928 - - - -
#>
#> , , date: Date Recorded (Fictitious)
#>
#> N Mean SD Min Max
#> East Asia & Pacific 2196 - - - -
#> Europe & Central Asia 3538 - - - -
#> Latin America & Caribbean 2562 - - - -
#> Middle East & North Africa 1281 - - - -
#> North America 183 - - - -
#> South Asia 488 - - - -
#> Sub-Saharan Africa 2928 - - - -
#>
#> , , year: Year
#>
#> N Mean SD Min Max
#> East Asia & Pacific 2196 1990 17.6108 1960 2020
#> Europe & Central Asia 3538 1990 17.6093 1960 2020
#> Latin America & Caribbean 2562 1990 17.6103 1960 2020
#> Middle East & North Africa 1281 1990 17.6137 1960 2020
#> North America 183 1990 17.6551 1960 2020
#> South Asia 488 1990 17.6249 1960 2020
#> Sub-Saharan Africa 2928 1990 17.6098 1960 2020
#>
#> , , decade: Decade
#>
#> N Mean SD Min Max
#> East Asia & Pacific 2196 1985.5738 17.5151 1960 2020
#> Europe & Central Asia 3538 1985.5738 17.5136 1960 2020
#> Latin America & Caribbean 2562 1985.5738 17.5145 1960 2020
#> Middle East & North Africa 1281 1985.5738 17.5179 1960 2020
#> North America 183 1985.5738 17.5591 1960 2020
#> South Asia 488 1985.5738 17.5291 1960 2020
#> Sub-Saharan Africa 2928 1985.5738 17.5141 1960 2020
#>
#> , , income: Income Level
#>
#> N Mean SD Min Max
#> East Asia & Pacific 2196 - - - -
#> Europe & Central Asia 3538 - - - -
#> Latin America & Caribbean 2562 - - - -
#> Middle East & North Africa 1281 - - - -
#> North America 183 - - - -
#> South Asia 488 - - - -
#> Sub-Saharan Africa 2928 - - - -
#>
#> , , OECD: Is OECD Member Country?
#>
#> N Mean SD Min Max
#> East Asia & Pacific 2196 - - - -
#> Europe & Central Asia 3538 - - - -
#> Latin America & Caribbean 2562 - - - -
#> Middle East & North Africa 1281 - - - -
#> North America 183 - - - -
#> South Asia 488 - - - -
#> Sub-Saharan Africa 2928 - - - -
#>
#> , , PCGDP: GDP per capita (constant 2010 US$)
#>
#> N Mean SD Min
#> East Asia & Pacific 1467 10513.2441 14383.5507 132.0776
#> Europe & Central Asia 2243 25992.9618 26435.1316 366.9354
#> Latin America & Caribbean 1976 7628.4477 8818.5055 1005.4085
#> Middle East & North Africa 842 13878.4213 18419.7912 578.5996
#> North America 180 48699.76 24196.2855 16405.9053
#> South Asia 382 1235.9256 1611.2232 265.9625
#> Sub-Saharan Africa 2380 1840.0259 2596.0104 164.3366
#> Max
#> East Asia & Pacific 71992.1517
#> Europe & Central Asia 196061.417
#> Latin America & Caribbean 88391.3331
#> Middle East & North Africa 116232.753
#> North America 113236.091
#> South Asia 8476.564
#> Sub-Saharan Africa 20532.9523
#>
#> , , LIFEEX: Life expectancy at birth, total (years)
#>
#> N Mean SD Min Max
#> East Asia & Pacific 1807 65.9445 10.1633 18.907 85.078
#> Europe & Central Asia 3046 72.1625 5.7602 45.369 85.4171
#> Latin America & Caribbean 2107 68.3486 7.3768 41.762 82.1902
#> Middle East & North Africa 1226 66.2508 9.8306 29.919 82.8049
#> North America 144 76.2867 3.5734 68.8978 82.0488
#> South Asia 480 57.5585 11.3004 32.446 78.921
#> Sub-Saharan Africa 2860 51.581 8.6876 26.172 74.5146
#>
#> , , GINI: Gini index (World Bank estimate)
#>
#> N Mean SD Min Max
#> East Asia & Pacific 154 37.7571 5.0318 27.8 49.1
#> Europe & Central Asia 798 31.9114 4.5809 20.7 48.4
#> Latin America & Caribbean 413 49.9557 5.4821 34.4 63.3
#> Middle East & North Africa 91 36.0143 5.2073 26 47.4
#> North America 49 37.4816 3.6972 31 41.5
#> South Asia 46 33.8804 3.9898 25.9 43.8
#> Sub-Saharan Africa 193 44.6606 8.2003 29.8 65.8
#>
#> , , ODA: Net official development assistance and official aid received (constant 2018 US$)
#>
#> N Mean SD Min
#> East Asia & Pacific 1537 352'017964 622'847624 -997'679993
#> Europe & Central Asia 787 402'455286 568'237036 -322'070007
#> Latin America & Caribbean 1972 172'880081 260'781049 -444'040009
#> Middle East & North Africa 1105 732'380009 1.52108993e+09 -141'789993
#> North America 39 468717.916 10'653560.8 -15'869999.9
#> South Asia 466 1.27049955e+09 1.61492889e+09 -247'369995
#> Sub-Saharan Africa 2702 486'371750 656'336230 -18'409999.8
#> Max
#> East Asia & Pacific 4.04487988e+09
#> Europe & Central Asia 4.34612988e+09
#> Latin America & Caribbean 2.99568994e+09
#> Middle East & North Africa 2.56715605e+10
#> North America 61'509998.3
#> South Asia 8.75425977e+09
#> Sub-Saharan Africa 1.18790801e+10
#>
#> , , POP: Population, total
#>
#> N Mean SD Min
#> East Asia & Pacific 2160 47'788194.6 184'121276 4375
#> Europe & Central Asia 3480 14'103754.9 24'686065.8 13411
#> Latin America & Caribbean 2520 10'371370.7 26'728206 2833
#> Middle East & North Africa 1227 12'549479.2 17'750818.2 47384
#> North America 180 93'783656.8 116'925373 44400
#> South Asia 480 144'180423 300'282162 89863
#> Sub-Saharan Africa 2872 11'597636.9 19'916800.8 41700
#> Max
#> East Asia & Pacific 1.39771500e+09
#> Europe & Central Asia 148'538197
#> Latin America & Caribbean 211'049527
#> Middle East & North Africa 100'388073
#> North America 328'239523
#> South Asia 1.36641775e+09
#> Sub-Saharan Africa 200'963599
#>
qsu(wlddev, PCGDP + LIFEEX ~ income) # Summarize GDP per Capita and Life Expectancy by
#> , , PCGDP
#>
#> N Mean SD Min Max
#> High income 3179 30280.7283 23847.0483 932.0417 196061.417
#> Low income 1311 597.4053 288.4392 164.3366 1864.7925
#> Lower middle income 2246 1574.2535 858.7183 144.9863 4818.1922
#> Upper middle income 2734 4945.3258 2979.5609 132.0776 20532.9523
#>
#> , , LIFEEX
#>
#> N Mean SD Min Max
#> High income 3831 73.6246 5.6693 42.672 85.4171
#> Low income 1800 49.7301 9.0944 26.172 74.43
#> Lower middle income 2790 58.1481 9.3115 18.907 76.699
#> Upper middle income 3249 66.6466 7.537 36.535 80.279
#>
stats <- qsu(wlddev, ~ region + income, # World Bank Income Level
cols = 9:10, higher = TRUE) # Same variables, by both region and income
aperm(stats) # A different perspective on the same stats
#> , , East Asia & Pacific.High income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 487 26766.9163 14823.5175 932.0417 71992.1517 0.2811 2.5566
#> LIFEEX 664 73.3724 6.659 54.81 85.078 -0.4945 2.6876
#>
#> , , East Asia & Pacific.Lower middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 562 1599.4748 895.5278 144.9863 4503.1454 0.4987 3.0945
#> LIFEEX 780 59.1597 9.6542 18.907 75.4 -1.0076 4.1679
#>
#> , , East Asia & Pacific.Upper middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 418 3561.0911 2468.1843 132.0776 12486.6788 1.4194 4.89
#> LIFEEX 363 66.9366 5.6713 43.725 77.15 -0.9194 4.8567
#>
#> , , Europe & Central Asia.High income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 1551 35718.5696 26466.4643 4500.7362 196061.417 2.2834 10.2728
#> LIFEEX 1845 74.8234 4.3845 63.0749 85.4171 0.042 2.1824
#>
#> , , Europe & Central Asia.Low income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 35 809.4753 336.5425 366.9354 1458.9932 0.426 1.9987
#> LIFEEX 60 60.1129 6.147 50.613 71.097 0.3991 1.9875
#>
#> , , Europe & Central Asia.Lower middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 125 1804.0338 964.3793 534.9587 4243.7743 0.6386 2.2984
#> LIFEEX 240 66.7943 3.4816 56.1281 71.901 -0.8383 3.22
#>
#> , , Europe & Central Asia.Upper middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 532 4979.0901 2720.4775 700.7008 15190.0995 1.0955 4.1706
#> LIFEEX 901 68.946 4.9936 45.369 78.573 -1.1687 5.5764
#>
#> , , Latin America & Caribbean.High income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 554 15523.2862 12970.8584 2139.4078 88391.3331 2.7213 13.3985
#> LIFEEX 662 72.2297 4.701 57.219 82.1902 -0.475 2.6697
#>
#> , , Latin America & Caribbean.Low income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 60 1357.3326 197.5647 1029.2088 1864.7925 0.5339 2.5057
#> LIFEEX 60 53.4918 6.3638 41.762 64.001 -0.2004 1.9654
#>
#> , , Latin America & Caribbean.Lower middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 235 1866.2055 584.342 1005.4085 3572.3576 0.8155 2.9192
#> LIFEEX 240 61.4557 9.1704 41.82 75.27 -0.278 1.8612
#>
#> , , Latin America & Caribbean.Upper middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 1127 5282.9759 2916.0793 1079.3833 15739.3804 1.1654 4.1689
#> LIFEEX 1145 68.3281 6.123 46.702 80.279 -0.7517 3.3845
#>
#> , , Middle East & North Africa.High income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 347 28850.0007 20875.87 2314.5202 116232.753 1.7178 6.0067
#> LIFEEX 476 70.6365 8.2407 42.672 82.8049 -1.2731 4.2978
#>
#> , , Middle East & North Africa.Low income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 30 1069.6596 198.1582 631.4879 1334.7848 -1.1705 3.3573
#> LIFEEX 120 59.741 12.2042 29.919 74.43 -0.9727 3.0557
#>
#> , , Middle East & North Africa.Lower middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 196 2076.3417 920.3099 578.5996 4408.366 0.5759 2.8787
#> LIFEEX 270 62.4798 9.3779 42.021 76.699 -0.2512 1.8235
#>
#> , , Middle East & North Africa.Upper middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 269 4593.4118 2111.7582 1431.6015 12064.7807 1.2241 4.5445
#> LIFEEX 360 65.4501 8.5814 42.609 78.93 -0.6974 2.5476
#>
#> , , North America.High income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 180 48699.76 24196.2855 16405.9053 113236.091 0.938 2.9688
#> LIFEEX 144 76.2867 3.5734 68.8978 82.0488 -0.1963 1.976
#>
#> , , South Asia.Low income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 78 429.8696 152.4194 265.9625 859.0237 0.8628 2.9011
#> LIFEEX 120 51.5601 11.0428 32.446 70.778 0.0156 1.767
#>
#> , , South Asia.Lower middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 220 810.8415 578.5148 302.0926 3262.199 2.1093 7.6591
#> LIFEEX 240 56.9501 9.4251 34.526 72.591 -0.34 2.2159
#>
#> , , South Asia.Upper middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 84 3097.7215 2532.6969 585.9084 8476.564 0.736 2.042
#> LIFEEX 120 64.774 11.1413 37.343 78.921 -0.944 2.9181
#>
#> , , Sub-Saharan Africa.High income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 60 7510.635 3462.9403 2616.8743 15048.7469 0.3697 2.1189
#> LIFEEX 40 71.5749 1.9009 67.9707 74.3098 -0.3487 1.9765
#>
#> , , Sub-Saharan Africa.Low income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 1108 548.5624 217.068 164.3366 1535.7082 0.7121 3.7279
#> LIFEEX 1440 48.154 7.8474 26.172 69.024 0.1456 2.6414
#>
#> , , Sub-Saharan Africa.Lower middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 908 1528.0373 789.4848 261.7993 4818.1922 1.5382 5.4549
#> LIFEEX 1020 53.697 7.3026 36.095 72.981 0.0644 2.621
#>
#> , , Sub-Saharan Africa.Upper middle income
#>
#> N Mean SD Min Max Skew Kurt
#> PCGDP 304 6359.7324 3909.8516 407.7823 20532.9523 0.9609 4.3485
#> LIFEEX 360 57.0724 8.2369 36.535 74.5146 -0.1454 2.9076
#>
# Grouped summary
wlddev |> fgroup_by(region) |> fselect(PCGDP, LIFEEX) |> qsu()
#> , , PCGDP
#>
#> N Mean SD Min
#> East Asia & Pacific 1467 10513.2441 14383.5507 132.0776
#> Europe & Central Asia 2243 25992.9618 26435.1316 366.9354
#> Latin America & Caribbean 1976 7628.4477 8818.5055 1005.4085
#> Middle East & North Africa 842 13878.4213 18419.7912 578.5996
#> North America 180 48699.76 24196.2855 16405.9053
#> South Asia 382 1235.9256 1611.2232 265.9625
#> Sub-Saharan Africa 2380 1840.0259 2596.0104 164.3366
#> Max
#> East Asia & Pacific 71992.1517
#> Europe & Central Asia 196061.417
#> Latin America & Caribbean 88391.3331
#> Middle East & North Africa 116232.753
#> North America 113236.091
#> South Asia 8476.564
#> Sub-Saharan Africa 20532.9523
#>
#> , , LIFEEX
#>
#> N Mean SD Min Max
#> East Asia & Pacific 1807 65.9445 10.1633 18.907 85.078
#> Europe & Central Asia 3046 72.1625 5.7602 45.369 85.4171
#> Latin America & Caribbean 2107 68.3486 7.3768 41.762 82.1902
#> Middle East & North Africa 1226 66.2508 9.8306 29.919 82.8049
#> North America 144 76.2867 3.5734 68.8978 82.0488
#> South Asia 480 57.5585 11.3004 32.446 78.921
#> Sub-Saharan Africa 2860 51.581 8.6876 26.172 74.5146
#>
# Panel Data Summaries ---------------------
qsu(wlddev, pid = ~ iso3c, labels = TRUE) # Adding between and within countries statistics
#> , , country: Country Name
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , date: Date Recorded (Fictitious)
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , year: Year
#>
#> N/T Mean SD Min Max
#> Overall 13176 1990 17.6075 1960 2020
#> Between 216 1990 0 1990 1990
#> Within 61 1990 17.6075 1960 2020
#>
#> , , decade: Decade
#>
#> N/T Mean SD Min Max
#> Overall 13176 1985.5738 17.5117 1960 2020
#> Between 216 1985.5738 0 1985.5738 1985.5738
#> Within 61 1985.5738 17.5117 1960 2020
#>
#> , , region: Region
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , income: Income Level
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , OECD: Is OECD Member Country?
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , PCGDP: GDP per capita (constant 2010 US$)
#>
#> N/T Mean SD Min Max
#> Overall 9470 12048.778 19077.6416 132.0776 196061.417
#> Between 206 12962.6054 20189.9007 253.1886 141200.38
#> Within 45.9709 12048.778 6723.6808 -33504.8721 76767.5254
#>
#> , , LIFEEX: Life expectancy at birth, total (years)
#>
#> N/T Mean SD Min Max
#> Overall 11670 64.2963 11.4764 18.907 85.4171
#> Between 207 64.9537 9.8936 40.9663 85.4171
#> Within 56.3768 64.2963 6.0842 32.9068 84.4198
#>
#> , , GINI: Gini index (World Bank estimate)
#>
#> N/T Mean SD Min Max
#> Overall 1744 38.5341 9.2006 20.7 65.8
#> Between 167 39.4233 8.1356 24.8667 61.7143
#> Within 10.4431 38.5341 2.9277 25.3917 55.3591
#>
#> , , ODA: Net official development assistance and official aid received (constant 2018 US$)
#>
#> N/T Mean SD Min Max
#> Overall 8608 454'720131 868'712654 -997'679993 2.56715605e+10
#> Between 178 439'168412 569'049959 468717.916 3.62337432e+09
#> Within 48.3596 454'720131 650'709624 -2.44379420e+09 2.45610972e+10
#>
#> , , POP: Population, total
#>
#> N/T Mean SD Min Max
#> Overall 12919 24'245971.6 102'120674 2833 1.39771500e+09
#> Between 216 24'178573 98'616506.7 8343.3333 1.08786967e+09
#> Within 59.8102 24'245971.6 26'803077.4 -405'793067 510'077008
#>
# -> They show amongst other things that year and decade are individual-invariant,
# that we have GINI-data on only 161 countries, with only 8.42 observations per country on average,
# and that GDP, LIFEEX and GINI vary more between-countries, but ODA received varies more within
# countries over time.
# Let's do this manually for PCGDP:
x <- wlddev$PCGDP
g <- wlddev$iso3c
# This is the exact variance decomposion
all.equal(fvar(x), fvar(B(x, g)) + fvar(W(x, g)))
#> [1] TRUE
# What qsu does is calculate
r <- rbind(Overall = qsu(x),
Between = qsu(fmean(x, g)), # Aggregation instead of between-transform
Within = qsu(fwithin(x, g, mean = "overall.mean"))) # Same as qsu(W(x, g) + fmean(x))
r[3, 1] <- r[1, 1] / r[2, 1]
print.qsu(r)
#> N Mean SD Min Max
#> Overall 9470 12048.778 19077.6416 132.0776 196061.417
#> Between 206 12962.6054 20189.9007 253.1886 141200.38
#> Within 45.9709 12048.778 6723.6808 -33504.8721 76767.5254
# Proof:
qsu(x, pid = g)
#> N/T Mean SD Min Max
#> Overall 9470 12048.778 19077.6416 132.0776 196061.417
#> Between 206 12962.6054 20189.9007 253.1886 141200.38
#> Within 45.9709 12048.778 6723.6808 -33504.8721 76767.5254
# Using indexed data:
wldi <- findex_by(wlddev, iso3c, year) # Creating a Indexed Data Frame frame from this data
qsu(wldi) # Summary for pdata.frame -> qsu(wlddev, pid = ~ iso3c)
#> , , country
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , iso3c
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , date
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , year
#>
#> N/T Mean SD Min Max
#> Overall 13176 1990 17.6075 1960 2020
#> Between 216 1990 0 1990 1990
#> Within 61 1990 17.6075 1960 2020
#>
#> , , decade
#>
#> N/T Mean SD Min Max
#> Overall 13176 1985.5738 17.5117 1960 2020
#> Between 216 1985.5738 0 1985.5738 1985.5738
#> Within 61 1985.5738 17.5117 1960 2020
#>
#> , , region
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , income
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , OECD
#>
#> N/T Mean SD Min Max
#> Overall 13176 - - - -
#> Between 216 - - - -
#> Within 61 - - - -
#>
#> , , PCGDP
#>
#> N/T Mean SD Min Max
#> Overall 9470 12048.778 19077.6416 132.0776 196061.417
#> Between 206 12962.6054 20189.9007 253.1886 141200.38
#> Within 45.9709 12048.778 6723.6808 -33504.8721 76767.5254
#>
#> , , LIFEEX
#>
#> N/T Mean SD Min Max
#> Overall 11670 64.2963 11.4764 18.907 85.4171
#> Between 207 64.9537 9.8936 40.9663 85.4171
#> Within 56.3768 64.2963 6.0842 32.9068 84.4198
#>
#> , , GINI
#>
#> N/T Mean SD Min Max
#> Overall 1744 38.5341 9.2006 20.7 65.8
#> Between 167 39.4233 8.1356 24.8667 61.7143
#> Within 10.4431 38.5341 2.9277 25.3917 55.3591
#>
#> , , ODA
#>
#> N/T Mean SD Min Max
#> Overall 8608 454'720131 868'712654 -997'679993 2.56715605e+10
#> Between 178 439'168412 569'049959 468717.916 3.62337432e+09
#> Within 48.3596 454'720131 650'709624 -2.44379420e+09 2.45610972e+10
#>
#> , , POP
#>
#> N/T Mean SD Min Max
#> Overall 12919 24'245971.6 102'120674 2833 1.39771500e+09
#> Between 216 24'178573 98'616506.7 8343.3333 1.08786967e+09
#> Within 59.8102 24'245971.6 26'803077.4 -405'793067 510'077008
#>
qsu(wldi$PCGDP) # Default summary for Panel Series
#> N/T Mean SD Min Max
#> Overall 9470 12048.778 19077.6416 132.0776 196061.417
#> Between 206 12962.6054 20189.9007 253.1886 141200.38
#> Within 45.9709 12048.778 6723.6808 -33504.8721 76767.5254
qsu(G(wldi$PCGDP)) # Summarizing GDP growth, see also ?G
#> N/T Mean SD Min Max
#> Overall 9264 2.0762 6.0081 -64.9924 140.3708
#> Between 202 2.0752 1.8684 -7.6806 10.3106
#> Within 45.8614 2.0762 5.785 -67.359 133.0971
# Grouped Panel Data Summaries -------------
qsu(wlddev, ~ region, ~ iso3c, cols = 9:12) # Panel-Statistics by region
#> , , Overall, PCGDP
#>
#> N/T Mean SD Min
#> East Asia & Pacific 1467 10513.2441 14383.5507 132.0776
#> Europe & Central Asia 2243 25992.9618 26435.1316 366.9354
#> Latin America & Caribbean 1976 7628.4477 8818.5055 1005.4085
#> Middle East & North Africa 842 13878.4213 18419.7912 578.5996
#> North America 180 48699.76 24196.2855 16405.9053
#> South Asia 382 1235.9256 1611.2232 265.9625
#> Sub-Saharan Africa 2380 1840.0259 2596.0104 164.3366
#> Max
#> East Asia & Pacific 71992.1517
#> Europe & Central Asia 196061.417
#> Latin America & Caribbean 88391.3331
#> Middle East & North Africa 116232.753
#> North America 113236.091
#> South Asia 8476.564
#> Sub-Saharan Africa 20532.9523
#>
#> , , Between, PCGDP
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 34 10513.2441 12771.742 444.2899 39722.0077
#> Europe & Central Asia 56 25992.9618 24051.035 809.4753 141200.38
#> Latin America & Caribbean 38 7628.4477 8470.9708 1357.3326 77403.7443
#> Middle East & North Africa 20 13878.4213 17251.6962 1069.6596 64878.4021
#> North America 3 48699.76 18604.4369 35260.4708 74934.5874
#> South Asia 8 1235.9256 1488.3669 413.68 6621.5002
#> Sub-Saharan Africa 47 1840.0259 2234.3254 253.1886 9922.0052
#>
#> , , Within, PCGDP
#>
#> N/T Mean SD Min
#> East Asia & Pacific 43.1471 12048.778 6615.8248 -11964.6472
#> Europe & Central Asia 40.0536 12048.778 10971.0483 -33504.8721
#> Latin America & Caribbean 52 12048.778 2451.2636 -354.1639
#> Middle East & North Africa 42.1 12048.778 6455.0512 -18674.4049
#> North America 60 12048.778 15470.4609 -29523.1017
#> South Asia 47.75 12048.778 617.0934 10026.9155
#> Sub-Saharan Africa 50.6383 12048.778 1321.764 4846.3834
#> Max
#> East Asia & Pacific 49541.463
#> Europe & Central Asia 76767.5254
#> Latin America & Caribbean 23036.3668
#> Middle East & North Africa 63665.0446
#> North America 50350.2816
#> South Asia 14455.865
#> Sub-Saharan Africa 24883.1246
#>
#> , , Overall, LIFEEX
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 1807 65.9445 10.1633 18.907 85.078
#> Europe & Central Asia 3046 72.1625 5.7602 45.369 85.4171
#> Latin America & Caribbean 2107 68.3486 7.3768 41.762 82.1902
#> Middle East & North Africa 1226 66.2508 9.8306 29.919 82.8049
#> North America 144 76.2867 3.5734 68.8978 82.0488
#> South Asia 480 57.5585 11.3004 32.446 78.921
#> Sub-Saharan Africa 2860 51.581 8.6876 26.172 74.5146
#>
#> , , Between, LIFEEX
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 32 65.9445 7.6833 49.7995 77.9008
#> Europe & Central Asia 55 72.1625 4.4378 60.1129 85.4171
#> Latin America & Caribbean 40 68.3486 4.9199 53.4918 82.1902
#> Middle East & North Africa 21 66.2508 5.922 52.5371 76.7395
#> North America 3 76.2867 1.3589 74.8065 78.4175
#> South Asia 8 57.5585 5.6158 49.1972 69.3429
#> Sub-Saharan Africa 48 51.581 5.657 40.9663 71.5749
#>
#> , , Within, LIFEEX
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 56.4688 64.2963 6.6528 32.9068 83.9918
#> Europe & Central Asia 55.3818 64.2963 3.6723 46.3045 78.6265
#> Latin America & Caribbean 52.675 64.2963 5.4965 46.7831 79.5026
#> Middle East & North Africa 58.381 64.2963 7.8467 41.6187 78.8872
#> North America 48 64.2963 3.3049 54.7766 69.4306
#> South Asia 60 64.2963 9.8062 41.4342 83.0122
#> Sub-Saharan Africa 59.5833 64.2963 6.5933 41.5678 84.4198
#>
#> , , Overall, GINI
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 154 37.7571 5.0318 27.8 49.1
#> Europe & Central Asia 798 31.9114 4.5809 20.7 48.4
#> Latin America & Caribbean 413 49.9557 5.4821 34.4 63.3
#> Middle East & North Africa 91 36.0143 5.2073 26 47.4
#> North America 49 37.4816 3.6972 31 41.5
#> South Asia 46 33.8804 3.9898 25.9 43.8
#> Sub-Saharan Africa 193 44.6606 8.2003 29.8 65.8
#>
#> , , Between, GINI
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 23 37.7571 4.3005 30.8 45.8857
#> Europe & Central Asia 49 31.9114 4.0611 24.8667 40.935
#> Latin America & Caribbean 25 49.9557 4.0492 41.1 57.9
#> Middle East & North Africa 15 36.0143 4.7002 29.05 42.7
#> North America 2 37.4816 3.3563 33.1222 40.0129
#> South Asia 7 33.8804 3.0052 30.3556 38.8
#> Sub-Saharan Africa 46 44.6606 6.8844 34.52 61.7143
#>
#> , , Within, GINI
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 6.6957 38.5341 2.6125 31.0187 45.8901
#> Europe & Central Asia 16.2857 38.5341 2.1195 31.2841 50.1387
#> Latin America & Caribbean 16.52 38.5341 3.6955 25.3917 48.8341
#> Middle East & North Africa 6.0667 38.5341 2.2415 31.7675 45.777
#> North America 24.5 38.5341 1.5507 33.0212 42.7119
#> South Asia 6.5714 38.5341 2.6244 32.8341 45.0675
#> Sub-Saharan Africa 4.1957 38.5341 4.4553 27.9452 55.3591
#>
#> , , Overall, ODA
#>
#> N/T Mean SD Min
#> East Asia & Pacific 1537 352'017964 622'847624 -997'679993
#> Europe & Central Asia 787 402'455286 568'237036 -322'070007
#> Latin America & Caribbean 1972 172'880081 260'781049 -444'040009
#> Middle East & North Africa 1105 732'380009 1.52108993e+09 -141'789993
#> North America 39 468717.916 10'653560.8 -15'869999.9
#> South Asia 466 1.27049955e+09 1.61492889e+09 -247'369995
#> Sub-Saharan Africa 2702 486'371750 656'336230 -18'409999.8
#> Max
#> East Asia & Pacific 4.04487988e+09
#> Europe & Central Asia 4.34612988e+09
#> Latin America & Caribbean 2.99568994e+09
#> Middle East & North Africa 2.56715605e+10
#> North America 61'509998.3
#> South Asia 8.75425977e+09
#> Sub-Saharan Africa 1.18790801e+10
#>
#> , , Between, ODA
#>
#> N/T Mean SD Min
#> East Asia & Pacific 31 352'017964 457'183279 1'654615.38
#> Europe & Central Asia 32 402'455286 438'074771 12'516000.1
#> Latin America & Caribbean 37 172'880081 167'160838 2'225483.88
#> Middle East & North Africa 21 732'380009 775'418887 3'112820.5
#> North America 1 468717.916 0 468717.916
#> South Asia 8 1.27049955e+09 1.18347893e+09 27'152499.9
#> Sub-Saharan Africa 48 486'371750 397'995105 28'801206.9
#> Max
#> East Asia & Pacific 1.63585532e+09
#> Europe & Central Asia 2.05456932e+09
#> Latin America & Caribbean 538'386665
#> Middle East & North Africa 2.86174883e+09
#> North America 468717.916
#> South Asia 3.62337432e+09
#> Sub-Saharan Africa 1.55049113e+09
#>
#> , , Within, ODA
#>
#> N/T Mean SD
#> East Asia & Pacific 49.5806 454'720131 422'992450
#> Europe & Central Asia 24.5938 454'720131 361'916875
#> Latin America & Caribbean 53.2973 454'720131 200'159960
#> Middle East & North Africa 52.619 454'720131 1.30860235e+09
#> North America 39 454'720131 10'653560.8
#> South Asia 58.25 454'720131 1.09880524e+09
#> Sub-Saharan Africa 56.2917 454'720131 521'897637
#> Min Max
#> East Asia & Pacific -2.04042108e+09 3.59673152e+09
#> Europe & Central Asia -1.08796786e+09 3.30549004e+09
#> Latin America & Caribbean -527'706542 3.28976141e+09
#> Middle East & North Africa -2.34610870e+09 2.45610972e+10
#> North America 438'381413 515'761411
#> South Asia -2.44379420e+09 5.58560558e+09
#> Sub-Saharan Africa -952'168698 1.12814455e+10
#>
psr <- qsu(wldi, ~ region, cols = 9:12) # Same on indexed data
psr # -> Gives a 4D array
#> , , Overall, PCGDP
#>
#> N/T Mean SD Min
#> East Asia & Pacific 1467 10513.2441 14383.5507 132.0776
#> Europe & Central Asia 2243 25992.9618 26435.1316 366.9354
#> Latin America & Caribbean 1976 7628.4477 8818.5055 1005.4085
#> Middle East & North Africa 842 13878.4213 18419.7912 578.5996
#> North America 180 48699.76 24196.2855 16405.9053
#> South Asia 382 1235.9256 1611.2232 265.9625
#> Sub-Saharan Africa 2380 1840.0259 2596.0104 164.3366
#> Max
#> East Asia & Pacific 71992.1517
#> Europe & Central Asia 196061.417
#> Latin America & Caribbean 88391.3331
#> Middle East & North Africa 116232.753
#> North America 113236.091
#> South Asia 8476.564
#> Sub-Saharan Africa 20532.9523
#>
#> , , Between, PCGDP
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 34 10513.2441 12771.742 444.2899 39722.0077
#> Europe & Central Asia 56 25992.9618 24051.035 809.4753 141200.38
#> Latin America & Caribbean 38 7628.4477 8470.9708 1357.3326 77403.7443
#> Middle East & North Africa 20 13878.4213 17251.6962 1069.6596 64878.4021
#> North America 3 48699.76 18604.4369 35260.4708 74934.5874
#> South Asia 8 1235.9256 1488.3669 413.68 6621.5002
#> Sub-Saharan Africa 47 1840.0259 2234.3254 253.1886 9922.0052
#>
#> , , Within, PCGDP
#>
#> N/T Mean SD Min
#> East Asia & Pacific 43.1471 12048.778 6615.8248 -11964.6472
#> Europe & Central Asia 40.0536 12048.778 10971.0483 -33504.8721
#> Latin America & Caribbean 52 12048.778 2451.2636 -354.1639
#> Middle East & North Africa 42.1 12048.778 6455.0512 -18674.4049
#> North America 60 12048.778 15470.4609 -29523.1017
#> South Asia 47.75 12048.778 617.0934 10026.9155
#> Sub-Saharan Africa 50.6383 12048.778 1321.764 4846.3834
#> Max
#> East Asia & Pacific 49541.463
#> Europe & Central Asia 76767.5254
#> Latin America & Caribbean 23036.3668
#> Middle East & North Africa 63665.0446
#> North America 50350.2816
#> South Asia 14455.865
#> Sub-Saharan Africa 24883.1246
#>
#> , , Overall, LIFEEX
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 1807 65.9445 10.1633 18.907 85.078
#> Europe & Central Asia 3046 72.1625 5.7602 45.369 85.4171
#> Latin America & Caribbean 2107 68.3486 7.3768 41.762 82.1902
#> Middle East & North Africa 1226 66.2508 9.8306 29.919 82.8049
#> North America 144 76.2867 3.5734 68.8978 82.0488
#> South Asia 480 57.5585 11.3004 32.446 78.921
#> Sub-Saharan Africa 2860 51.581 8.6876 26.172 74.5146
#>
#> , , Between, LIFEEX
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 32 65.9445 7.6833 49.7995 77.9008
#> Europe & Central Asia 55 72.1625 4.4378 60.1129 85.4171
#> Latin America & Caribbean 40 68.3486 4.9199 53.4918 82.1902
#> Middle East & North Africa 21 66.2508 5.922 52.5371 76.7395
#> North America 3 76.2867 1.3589 74.8065 78.4175
#> South Asia 8 57.5585 5.6158 49.1972 69.3429
#> Sub-Saharan Africa 48 51.581 5.657 40.9663 71.5749
#>
#> , , Within, LIFEEX
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 56.4688 64.2963 6.6528 32.9068 83.9918
#> Europe & Central Asia 55.3818 64.2963 3.6723 46.3045 78.6265
#> Latin America & Caribbean 52.675 64.2963 5.4965 46.7831 79.5026
#> Middle East & North Africa 58.381 64.2963 7.8467 41.6187 78.8872
#> North America 48 64.2963 3.3049 54.7766 69.4306
#> South Asia 60 64.2963 9.8062 41.4342 83.0122
#> Sub-Saharan Africa 59.5833 64.2963 6.5933 41.5678 84.4198
#>
#> , , Overall, GINI
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 154 37.7571 5.0318 27.8 49.1
#> Europe & Central Asia 798 31.9114 4.5809 20.7 48.4
#> Latin America & Caribbean 413 49.9557 5.4821 34.4 63.3
#> Middle East & North Africa 91 36.0143 5.2073 26 47.4
#> North America 49 37.4816 3.6972 31 41.5
#> South Asia 46 33.8804 3.9898 25.9 43.8
#> Sub-Saharan Africa 193 44.6606 8.2003 29.8 65.8
#>
#> , , Between, GINI
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 23 37.7571 4.3005 30.8 45.8857
#> Europe & Central Asia 49 31.9114 4.0611 24.8667 40.935
#> Latin America & Caribbean 25 49.9557 4.0492 41.1 57.9
#> Middle East & North Africa 15 36.0143 4.7002 29.05 42.7
#> North America 2 37.4816 3.3563 33.1222 40.0129
#> South Asia 7 33.8804 3.0052 30.3556 38.8
#> Sub-Saharan Africa 46 44.6606 6.8844 34.52 61.7143
#>
#> , , Within, GINI
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 6.6957 38.5341 2.6125 31.0187 45.8901
#> Europe & Central Asia 16.2857 38.5341 2.1195 31.2841 50.1387
#> Latin America & Caribbean 16.52 38.5341 3.6955 25.3917 48.8341
#> Middle East & North Africa 6.0667 38.5341 2.2415 31.7675 45.777
#> North America 24.5 38.5341 1.5507 33.0212 42.7119
#> South Asia 6.5714 38.5341 2.6244 32.8341 45.0675
#> Sub-Saharan Africa 4.1957 38.5341 4.4553 27.9452 55.3591
#>
#> , , Overall, ODA
#>
#> N/T Mean SD Min
#> East Asia & Pacific 1537 352'017964 622'847624 -997'679993
#> Europe & Central Asia 787 402'455286 568'237036 -322'070007
#> Latin America & Caribbean 1972 172'880081 260'781049 -444'040009
#> Middle East & North Africa 1105 732'380009 1.52108993e+09 -141'789993
#> North America 39 468717.916 10'653560.8 -15'869999.9
#> South Asia 466 1.27049955e+09 1.61492889e+09 -247'369995
#> Sub-Saharan Africa 2702 486'371750 656'336230 -18'409999.8
#> Max
#> East Asia & Pacific 4.04487988e+09
#> Europe & Central Asia 4.34612988e+09
#> Latin America & Caribbean 2.99568994e+09
#> Middle East & North Africa 2.56715605e+10
#> North America 61'509998.3
#> South Asia 8.75425977e+09
#> Sub-Saharan Africa 1.18790801e+10
#>
#> , , Between, ODA
#>
#> N/T Mean SD Min
#> East Asia & Pacific 31 352'017964 457'183279 1'654615.38
#> Europe & Central Asia 32 402'455286 438'074771 12'516000.1
#> Latin America & Caribbean 37 172'880081 167'160838 2'225483.88
#> Middle East & North Africa 21 732'380009 775'418887 3'112820.5
#> North America 1 468717.916 0 468717.916
#> South Asia 8 1.27049955e+09 1.18347893e+09 27'152499.9
#> Sub-Saharan Africa 48 486'371750 397'995105 28'801206.9
#> Max
#> East Asia & Pacific 1.63585532e+09
#> Europe & Central Asia 2.05456932e+09
#> Latin America & Caribbean 538'386665
#> Middle East & North Africa 2.86174883e+09
#> North America 468717.916
#> South Asia 3.62337432e+09
#> Sub-Saharan Africa 1.55049113e+09
#>
#> , , Within, ODA
#>
#> N/T Mean SD
#> East Asia & Pacific 49.5806 454'720131 422'992450
#> Europe & Central Asia 24.5938 454'720131 361'916875
#> Latin America & Caribbean 53.2973 454'720131 200'159960
#> Middle East & North Africa 52.619 454'720131 1.30860235e+09
#> North America 39 454'720131 10'653560.8
#> South Asia 58.25 454'720131 1.09880524e+09
#> Sub-Saharan Africa 56.2917 454'720131 521'897637
#> Min Max
#> East Asia & Pacific -2.04042108e+09 3.59673152e+09
#> Europe & Central Asia -1.08796786e+09 3.30549004e+09
#> Latin America & Caribbean -527'706542 3.28976141e+09
#> Middle East & North Africa -2.34610870e+09 2.45610972e+10
#> North America 438'381413 515'761411
#> South Asia -2.44379420e+09 5.58560558e+09
#> Sub-Saharan Africa -952'168698 1.12814455e+10
#>
psr[,"N/T",,] # Checking out the number of observations:
#> , , PCGDP
#>
#> Overall Between Within
#> East Asia & Pacific 1467 34 43.1471
#> Europe & Central Asia 2243 56 40.0536
#> Latin America & Caribbean 1976 38 52
#> Middle East & North Africa 842 20 42.1
#> North America 180 3 60
#> South Asia 382 8 47.75
#> Sub-Saharan Africa 2380 47 50.6383
#>
#> , , LIFEEX
#>
#> Overall Between Within
#> East Asia & Pacific 1807 32 56.4688
#> Europe & Central Asia 3046 55 55.3818
#> Latin America & Caribbean 2107 40 52.675
#> Middle East & North Africa 1226 21 58.381
#> North America 144 3 48
#> South Asia 480 8 60
#> Sub-Saharan Africa 2860 48 59.5833
#>
#> , , GINI
#>
#> Overall Between Within
#> East Asia & Pacific 154 23 6.6957
#> Europe & Central Asia 798 49 16.2857
#> Latin America & Caribbean 413 25 16.52
#> Middle East & North Africa 91 15 6.0667
#> North America 49 2 24.5
#> South Asia 46 7 6.5714
#> Sub-Saharan Africa 193 46 4.1957
#>
#> , , ODA
#>
#> Overall Between Within
#> East Asia & Pacific 1537 31 49.5806
#> Europe & Central Asia 787 32 24.5938
#> Latin America & Caribbean 1972 37 53.2973
#> Middle East & North Africa 1105 21 52.619
#> North America 39 1 39
#> South Asia 466 8 58.25
#> Sub-Saharan Africa 2702 48 56.2917
#>
# In North america we only have 3 countries, for the GINI we only have 3.91 observations on average
# for 45 Sub-Saharan-African countries, etc..
psr[,"SD",,] # Considering only standard deviations
#> , , PCGDP
#>
#> Overall Between Within
#> East Asia & Pacific 14383.5507 12771.742 6615.8248
#> Europe & Central Asia 26435.1316 24051.035 10971.0483
#> Latin America & Caribbean 8818.5055 8470.9708 2451.2636
#> Middle East & North Africa 18419.7912 17251.6962 6455.0512
#> North America 24196.2855 18604.4369 15470.4609
#> South Asia 1611.2232 1488.3669 617.0934
#> Sub-Saharan Africa 2596.0104 2234.3254 1321.764
#>
#> , , LIFEEX
#>
#> Overall Between Within
#> East Asia & Pacific 10.1633 7.6833 6.6528
#> Europe & Central Asia 5.7602 4.4378 3.6723
#> Latin America & Caribbean 7.3768 4.9199 5.4965
#> Middle East & North Africa 9.8306 5.922 7.8467
#> North America 3.5734 1.3589 3.3049
#> South Asia 11.3004 5.6158 9.8062
#> Sub-Saharan Africa 8.6876 5.657 6.5933
#>
#> , , GINI
#>
#> Overall Between Within
#> East Asia & Pacific 5.0318 4.3005 2.6125
#> Europe & Central Asia 4.5809 4.0611 2.1195
#> Latin America & Caribbean 5.4821 4.0492 3.6955
#> Middle East & North Africa 5.2073 4.7002 2.2415
#> North America 3.6972 3.3563 1.5507
#> South Asia 3.9898 3.0052 2.6244
#> Sub-Saharan Africa 8.2003 6.8844 4.4553
#>
#> , , ODA
#>
#> Overall Between Within
#> East Asia & Pacific 622'847624 457'183279 422'992450
#> Europe & Central Asia 568'237036 438'074771 361'916875
#> Latin America & Caribbean 260'781049 167'160838 200'159960
#> Middle East & North Africa 1.52108993e+09 775'418887 1.30860235e+09
#> North America 10'653560.8 0 10'653560.8
#> South Asia 1.61492889e+09 1.18347893e+09 1.09880524e+09
#> Sub-Saharan Africa 656'336230 397'995105 521'897637
#>
# -> In all regions variations in inequality (GINI) between countries are greater than variations
# in inequality within countries. The opposite is true for Life-Expectancy in all regions apart
# from Europe, etc..
# Again let's do this manually for PDGCP:
d <- cbind(Overall = x,
Between = fbetween(x, g),
Within = fwithin(x, g, mean = "overall.mean"))
r <- qsu(d, g = wlddev$region)
r[,"N","Between"] <- fndistinct(g[!is.na(x)], wlddev$region[!is.na(x)])
r[,"N","Within"] <- r[,"N","Overall"] / r[,"N","Between"]
r
#> , , Overall
#>
#> N Mean SD Min
#> East Asia & Pacific 1467 10513.2441 14383.5507 132.0776
#> Europe & Central Asia 2243 25992.9618 26435.1316 366.9354
#> Latin America & Caribbean 1976 7628.4477 8818.5055 1005.4085
#> Middle East & North Africa 842 13878.4213 18419.7912 578.5996
#> North America 180 48699.76 24196.2855 16405.9053
#> South Asia 382 1235.9256 1611.2232 265.9625
#> Sub-Saharan Africa 2380 1840.0259 2596.0104 164.3366
#> Max
#> East Asia & Pacific 71992.1517
#> Europe & Central Asia 196061.417
#> Latin America & Caribbean 88391.3331
#> Middle East & North Africa 116232.753
#> North America 113236.091
#> South Asia 8476.564
#> Sub-Saharan Africa 20532.9523
#>
#> , , Between
#>
#> N Mean SD Min Max
#> East Asia & Pacific 34 10513.2441 12771.742 444.2899 39722.0077
#> Europe & Central Asia 56 25992.9618 24051.035 809.4753 141200.38
#> Latin America & Caribbean 38 7628.4477 8470.9708 1357.3326 77403.7443
#> Middle East & North Africa 20 13878.4213 17251.6962 1069.6596 64878.4021
#> North America 3 48699.76 18604.4369 35260.4708 74934.5874
#> South Asia 8 1235.9256 1488.3669 413.68 6621.5002
#> Sub-Saharan Africa 47 1840.0259 2234.3254 253.1886 9922.0052
#>
#> , , Within
#>
#> N Mean SD Min
#> East Asia & Pacific 43.1471 12048.778 6615.8248 -11964.6472
#> Europe & Central Asia 40.0536 12048.778 10971.0483 -33504.8721
#> Latin America & Caribbean 52 12048.778 2451.2636 -354.1639
#> Middle East & North Africa 42.1 12048.778 6455.0512 -18674.4049
#> North America 60 12048.778 15470.4609 -29523.1017
#> South Asia 47.75 12048.778 617.0934 10026.9155
#> Sub-Saharan Africa 50.6383 12048.778 1321.764 4846.3834
#> Max
#> East Asia & Pacific 49541.463
#> Europe & Central Asia 76767.5254
#> Latin America & Caribbean 23036.3668
#> Middle East & North Africa 63665.0446
#> North America 50350.2816
#> South Asia 14455.865
#> Sub-Saharan Africa 24883.1246
#>
# Proof:
qsu(wlddev, PCGDP ~ region, ~ iso3c)
#> , , Overall
#>
#> N/T Mean SD Min
#> East Asia & Pacific 1467 10513.2441 14383.5507 132.0776
#> Europe & Central Asia 2243 25992.9618 26435.1316 366.9354
#> Latin America & Caribbean 1976 7628.4477 8818.5055 1005.4085
#> Middle East & North Africa 842 13878.4213 18419.7912 578.5996
#> North America 180 48699.76 24196.2855 16405.9053
#> South Asia 382 1235.9256 1611.2232 265.9625
#> Sub-Saharan Africa 2380 1840.0259 2596.0104 164.3366
#> Max
#> East Asia & Pacific 71992.1517
#> Europe & Central Asia 196061.417
#> Latin America & Caribbean 88391.3331
#> Middle East & North Africa 116232.753
#> North America 113236.091
#> South Asia 8476.564
#> Sub-Saharan Africa 20532.9523
#>
#> , , Between
#>
#> N/T Mean SD Min Max
#> East Asia & Pacific 34 10513.2441 12771.742 444.2899 39722.0077
#> Europe & Central Asia 56 25992.9618 24051.035 809.4753 141200.38
#> Latin America & Caribbean 38 7628.4477 8470.9708 1357.3326 77403.7443
#> Middle East & North Africa 20 13878.4213 17251.6962 1069.6596 64878.4021
#> North America 3 48699.76 18604.4369 35260.4708 74934.5874
#> South Asia 8 1235.9256 1488.3669 413.68 6621.5002
#> Sub-Saharan Africa 47 1840.0259 2234.3254 253.1886 9922.0052
#>
#> , , Within
#>
#> N/T Mean SD Min
#> East Asia & Pacific 43.1471 12048.778 6615.8248 -11964.6472
#> Europe & Central Asia 40.0536 12048.778 10971.0483 -33504.8721
#> Latin America & Caribbean 52 12048.778 2451.2636 -354.1639
#> Middle East & North Africa 42.1 12048.778 6455.0512 -18674.4049
#> North America 60 12048.778 15470.4609 -29523.1017
#> South Asia 47.75 12048.778 617.0934 10026.9155
#> Sub-Saharan Africa 50.6383 12048.778 1321.764 4846.3834
#> Max
#> East Asia & Pacific 49541.463
#> Europe & Central Asia 76767.5254
#> Latin America & Caribbean 23036.3668
#> Middle East & North Africa 63665.0446
#> North America 50350.2816
#> South Asia 14455.865
#> Sub-Saharan Africa 24883.1246
#>
# Weighted Summaries -----------------------
n <- nrow(wlddev)
weights <- abs(rnorm(n)) # Generate random weights
qsu(wlddev, w = weights, higher = TRUE) # Computed weighted mean, SD, skewness and kurtosis
#> N WeightSum Mean SD Min
#> country 13176 10585.6614 - - -
#> iso3c 13176 10585.6614 - - -
#> date 13176 10585.6614 - - -
#> year 13176 10585.6614 1990.0567 17.571 1960
#> decade 13176 10585.6614 1985.5954 17.4457 1960
#> region 13176 10585.6614 - - -
#> income 13176 10585.6614 - - -
#> OECD 13176 10585.6614 - - -
#> PCGDP 9470 7605.2411 12200.4108 19476.0119 132.0776
#> LIFEEX 11670 9415.3635 64.2821 11.415 18.907
#> GINI 1744 1408.4604 38.6079 9.1105 20.7
#> ODA 8608 6912.9955 455'230900 845'140574 -997'679993
#> POP 12919 10394.9887 24'017627.8 101'096382 2833
#> Max Skew Kurt
#> country - - -
#> iso3c - - -
#> date - - -
#> year 2020 -0.0073 1.7972
#> decade 2020 0.0281 1.7872
#> region - - -
#> income - - -
#> OECD - - -
#> PCGDP 196061.417 3.138 17.0796
#> LIFEEX 85.4171 -0.6634 2.6629
#> GINI 65.8 0.6068 2.5843
#> ODA 2.56715605e+10 5.6181 68.6523
#> POP 1.39771500e+09 9.859 111.846
weightsNA <- weights # Weights may contain missing values.. inserting 1000
weightsNA[sample.int(n, 1000)] <- NA
qsu(wlddev, w = weightsNA, higher = TRUE) # But now these values are removed from all variables
#> N WeightSum Mean SD Min Max
#> country 12176 9789.5084 - - - -
#> iso3c 12176 9789.5084 - - - -
#> date 12176 9789.5084 - - - -
#> year 12176 9789.5084 1990.1222 17.5726 1960 2020
#> decade 12176 9789.5084 1985.6498 17.4602 1960 2020
#> region 12176 9789.5084 - - - -
#> income 12176 9789.5084 - - - -
#> OECD 12176 9789.5084 - - - -
#> PCGDP 8761 7056.5956 12227.288 19571.0129 132.0776 196061.417
#> LIFEEX 10790 8712.7208 64.2643 11.4466 18.907 85.4171
#> GINI 1620 1325.1654 38.7631 9.1942 20.7 65.8
#> ODA 7982 6414.8059 453'440519 836'437517 -997'679993 2.56715605e+10
#> POP 11935 9610.1929 24'163649.4 101'134914 2833 1.39771500e+09
#> Skew Kurt
#> country - -
#> iso3c - -
#> date - -
#> year -0.0101 1.7913
#> decade 0.0254 1.7864
#> region - -
#> income - -
#> OECD - -
#> PCGDP 3.1439 17.1288
#> LIFEEX -0.6606 2.6383
#> GINI 0.5847 2.5264
#> ODA 5.5819 70.3269
#> POP 9.7838 110.232
# Grouped and panel-summaries can also be weighted in the same manner
# Alternative Output Formats ---------------
# Simple case
as.data.frame(qsu(mtcars))
#> Variable N Mean SD Min Max
#> 1 mpg 32 20.090625 6.0269481 10.400 33.900
#> 2 cyl 32 6.187500 1.7859216 4.000 8.000
#> 3 disp 32 230.721875 123.9386938 71.100 472.000
#> 4 hp 32 146.687500 68.5628685 52.000 335.000
#> 5 drat 32 3.596563 0.5346787 2.760 4.930
#> 6 wt 32 3.217250 0.9784574 1.513 5.424
#> 7 qsec 32 17.848750 1.7869432 14.500 22.900
#> 8 vs 32 0.437500 0.5040161 0.000 1.000
#> 9 am 32 0.406250 0.4989909 0.000 1.000
#> 10 gear 32 3.687500 0.7378041 3.000 5.000
#> 11 carb 32 2.812500 1.6152000 1.000 8.000
# For matrices can also use qDF/qDT/qTBL to assign custom name and get a character-id
qDF(qsu(mtcars), "car")
#> car N Mean SD Min Max
#> 1 mpg 32 20.090625 6.0269481 10.400 33.900
#> 2 cyl 32 6.187500 1.7859216 4.000 8.000
#> 3 disp 32 230.721875 123.9386938 71.100 472.000
#> 4 hp 32 146.687500 68.5628685 52.000 335.000
#> 5 drat 32 3.596563 0.5346787 2.760 4.930
#> 6 wt 32 3.217250 0.9784574 1.513 5.424
#> 7 qsec 32 17.848750 1.7869432 14.500 22.900
#> 8 vs 32 0.437500 0.5040161 0.000 1.000
#> 9 am 32 0.406250 0.4989909 0.000 1.000
#> 10 gear 32 3.687500 0.7378041 3.000 5.000
#> 11 carb 32 2.812500 1.6152000 1.000 8.000
# DF from 3D array: do not combine with aperm(), might introduce wrong column labels
as.data.frame(stats, gid = "Region_Income")
#> Variable Region_Income N Mean
#> 1 PCGDP East Asia & Pacific.High income 487 26766.91630
#> 2 PCGDP East Asia & Pacific.Lower middle income 562 1599.47481
#> 3 PCGDP East Asia & Pacific.Upper middle income 418 3561.09108
#> 4 PCGDP Europe & Central Asia.High income 1551 35718.56961
#> 5 PCGDP Europe & Central Asia.Low income 35 809.47526
#> 6 PCGDP Europe & Central Asia.Lower middle income 125 1804.03377
#> 7 PCGDP Europe & Central Asia.Upper middle income 532 4979.09009
#> 8 PCGDP Latin America & Caribbean.High income 554 15523.28616
#> 9 PCGDP Latin America & Caribbean.Low income 60 1357.33257
#> 10 PCGDP Latin America & Caribbean.Lower middle income 235 1866.20548
#> 11 PCGDP Latin America & Caribbean.Upper middle income 1127 5282.97589
#> 12 PCGDP Middle East & North Africa.High income 347 28850.00072
#> 13 PCGDP Middle East & North Africa.Low income 30 1069.65963
#> 14 PCGDP Middle East & North Africa.Lower middle income 196 2076.34170
#> 15 PCGDP Middle East & North Africa.Upper middle income 269 4593.41176
#> 16 PCGDP North America.High income 180 48699.75997
#> 17 PCGDP South Asia.Low income 78 429.86964
#> 18 PCGDP South Asia.Lower middle income 220 810.84151
#> 19 PCGDP South Asia.Upper middle income 84 3097.72152
#> 20 PCGDP Sub-Saharan Africa.High income 60 7510.63503
#> 21 PCGDP Sub-Saharan Africa.Low income 1108 548.56242
#> 22 PCGDP Sub-Saharan Africa.Lower middle income 908 1528.03726
#> 23 PCGDP Sub-Saharan Africa.Upper middle income 304 6359.73242
#> 24 LIFEEX East Asia & Pacific.High income 664 73.37235
#> 25 LIFEEX East Asia & Pacific.Lower middle income 780 59.15969
#> 26 LIFEEX East Asia & Pacific.Upper middle income 363 66.93658
#> 27 LIFEEX Europe & Central Asia.High income 1845 74.82340
#> 28 LIFEEX Europe & Central Asia.Low income 60 60.11290
#> 29 LIFEEX Europe & Central Asia.Lower middle income 240 66.79432
#> 30 LIFEEX Europe & Central Asia.Upper middle income 901 68.94596
#> 31 LIFEEX Latin America & Caribbean.High income 662 72.22967
#> 32 LIFEEX Latin America & Caribbean.Low income 60 53.49180
#> 33 LIFEEX Latin America & Caribbean.Lower middle income 240 61.45570
#> 34 LIFEEX Latin America & Caribbean.Upper middle income 1145 68.32810
#> 35 LIFEEX Middle East & North Africa.High income 476 70.63646
#> 36 LIFEEX Middle East & North Africa.Low income 120 59.74102
#> 37 LIFEEX Middle East & North Africa.Lower middle income 270 62.47980
#> 38 LIFEEX Middle East & North Africa.Upper middle income 360 65.45012
#> 39 LIFEEX North America.High income 144 76.28670
#> 40 LIFEEX South Asia.Low income 120 51.56006
#> 41 LIFEEX South Asia.Lower middle income 240 56.95006
#> 42 LIFEEX South Asia.Upper middle income 120 64.77400
#> 43 LIFEEX Sub-Saharan Africa.High income 40 71.57494
#> 44 LIFEEX Sub-Saharan Africa.Low income 1440 48.15395
#> 45 LIFEEX Sub-Saharan Africa.Lower middle income 1020 53.69704
#> 46 LIFEEX Sub-Saharan Africa.Upper middle income 360 57.07242
#> SD Min Max Skew Kurt
#> 1 14823.517488 932.04173 71992.15165 0.28114938 2.556594
#> 2 895.527784 144.98631 4503.14543 0.49873460 3.094502
#> 3 2468.184300 132.07761 12486.67880 1.41935974 4.889957
#> 4 26466.464337 4500.73615 196061.41684 2.28344025 10.272790
#> 5 336.542523 366.93541 1458.99324 0.42602809 1.998718
#> 6 964.379287 534.95873 4243.77426 0.63859153 2.298402
#> 7 2720.477474 700.70077 15190.09947 1.09546118 4.170587
#> 8 12970.858363 2139.40778 88391.33307 2.72130946 13.398530
#> 9 197.564730 1029.20885 1864.79251 0.53390088 2.505654
#> 10 584.342033 1005.40847 3572.35759 0.81548052 2.919152
#> 11 2916.079321 1079.38330 15739.38039 1.16539793 4.168859
#> 12 20875.869970 2314.52022 116232.75298 1.71781166 6.006666
#> 13 198.158227 631.48788 1334.78484 -1.17045510 3.357308
#> 14 920.309863 578.59958 4408.36602 0.57585508 2.878659
#> 15 2111.758179 1431.60147 12064.78069 1.22413027 4.544486
#> 16 24196.285490 16405.90534 113236.09091 0.93800557 2.968769
#> 17 152.419382 265.96253 859.02368 0.86282023 2.901131
#> 18 578.514846 302.09256 3262.19897 2.10929853 7.659136
#> 19 2532.696888 585.90840 8476.56401 0.73603177 2.042002
#> 20 3462.940310 2616.87435 15048.74693 0.36967490 2.118876
#> 21 217.067951 164.33660 1535.70818 0.71209343 3.727907
#> 22 789.484771 261.79930 4818.19217 1.53816511 5.454925
#> 23 3909.851581 407.78231 20532.95226 0.96089266 4.348527
#> 24 6.659029 54.81000 85.07805 -0.49446606 2.687628
#> 25 9.654211 18.90700 75.40000 -1.00756909 4.167908
#> 26 5.671317 43.72500 77.15000 -0.91942718 4.856741
#> 27 4.384547 63.07488 85.41707 0.04204845 2.182419
#> 28 6.147033 50.61300 71.09700 0.39910040 1.987471
#> 29 3.481622 56.12807 71.90100 -0.83833914 3.219981
#> 30 4.993571 45.36900 78.57300 -1.16865255 5.576356
#> 31 4.700994 57.21900 82.19024 -0.47496125 2.669728
#> 32 6.363829 41.76200 64.00100 -0.20038283 1.965395
#> 33 9.170377 41.82000 75.27000 -0.27798130 1.861226
#> 34 6.122963 46.70200 80.27900 -0.75165566 3.384474
#> 35 8.240682 42.67200 82.80488 -1.27308334 4.297822
#> 36 12.204212 29.91900 74.43000 -0.97271953 3.055738
#> 37 9.377862 42.02100 76.69900 -0.25117207 1.823493
#> 38 8.581419 42.60900 78.93000 -0.69736771 2.547634
#> 39 3.573399 68.89780 82.04878 -0.19625717 1.976035
#> 40 11.042785 32.44600 70.77800 0.01562713 1.766991
#> 41 9.425067 34.52600 72.59100 -0.33995719 2.215945
#> 42 11.141296 37.34300 78.92100 -0.94398516 2.918096
#> 43 1.900883 67.97073 74.30976 -0.34869145 1.976528
#> 44 7.847359 26.17200 69.02400 0.14556687 2.641374
#> 45 7.302597 36.09500 72.98100 0.06439163 2.620950
#> 46 8.236870 36.53500 74.51463 -0.14535587 2.907584
# DF from 4D array: also no aperm()
as.data.frame(qsu(wlddev, ~ income, ~ iso3c, cols = 9:10), gid = "Region")
#> Variable Region Trans N/T Mean SD
#> 1 PCGDP High income Overall 3179.00000 30280.72833 23847.048336
#> 2 PCGDP High income Between 71.00000 30280.72833 20908.532258
#> 3 PCGDP High income Within 44.77465 12048.77802 11467.998655
#> 4 PCGDP Low income Overall 1311.00000 597.40532 288.439151
#> 5 PCGDP Low income Between 28.00000 597.40532 243.821942
#> 6 PCGDP Low income Within 46.82143 12048.77802 154.103875
#> 7 PCGDP Lower middle income Overall 2246.00000 1574.25347 858.718342
#> 8 PCGDP Lower middle income Between 47.00000 1574.25347 676.315687
#> 9 PCGDP Lower middle income Within 47.78723 12048.77802 529.144858
#> 10 PCGDP Upper middle income Overall 2734.00000 4945.32584 2979.560925
#> 11 PCGDP Upper middle income Between 60.00000 4945.32584 2327.383427
#> 12 PCGDP Upper middle income Within 45.56667 12048.77802 1860.395037
#> 13 LIFEEX High income Overall 3831.00000 73.62456 5.669317
#> 14 LIFEEX High income Between 73.00000 73.62456 3.349857
#> 15 LIFEEX High income Within 52.47945 64.29630 4.573796
#> 16 LIFEEX Low income Overall 1800.00000 49.73006 9.094399
#> 17 LIFEEX Low income Between 30.00000 49.73006 4.832080
#> 18 LIFEEX Low income Within 60.00000 64.29630 7.704485
#> 19 LIFEEX Lower middle income Overall 2790.00000 58.14807 9.311453
#> 20 LIFEEX Lower middle income Between 47.00000 58.14807 5.994485
#> 21 LIFEEX Lower middle income Within 59.36170 64.29630 7.125259
#> 22 LIFEEX Upper middle income Overall 3249.00000 66.64665 7.536998
#> 23 LIFEEX Upper middle income Between 57.00000 66.64665 4.995501
#> 24 LIFEEX Upper middle income Within 57.00000 64.29630 5.643696
#> Min Max
#> 1 932.04173 196061.41684
#> 2 5413.44953 141200.38001
#> 3 -33504.87206 76767.52544
#> 4 164.33660 1864.79251
#> 5 253.18856 1357.33257
#> 6 11606.23817 12698.29600
#> 7 144.98631 4818.19217
#> 8 444.28990 2896.86818
#> 9 10377.72342 14603.10545
#> 10 132.07761 20532.95226
#> 11 1604.59495 13344.54228
#> 12 4846.38341 24883.12456
#> 13 42.67200 85.41707
#> 14 64.03017 85.41707
#> 15 42.93814 78.12714
#> 16 26.17200 74.43000
#> 17 40.96632 66.94497
#> 18 41.56784 84.41984
#> 19 18.90700 76.69900
#> 20 45.76870 71.60780
#> 21 32.90682 83.99179
#> 22 36.53500 80.27900
#> 23 48.05698 74.05037
#> 24 41.43417 83.01217
# Output as nested list
psrl <- qsu(wlddev, ~ income, ~ iso3c, cols = 9:10, array = FALSE)
psrl
#> $PCGDP
#> $PCGDP$Overall
#> N Mean SD Min Max
#> High income 3179 30280.7283 23847.0483 932.0417 196061.417
#> Low income 1311 597.4053 288.4392 164.3366 1864.7925
#> Lower middle income 2246 1574.2535 858.7183 144.9863 4818.1922
#> Upper middle income 2734 4945.3258 2979.5609 132.0776 20532.9523
#>
#> $PCGDP$Between
#> N Mean SD Min Max
#> High income 71 30280.7283 20908.5323 5413.4495 141200.38
#> Low income 28 597.4053 243.8219 253.1886 1357.3326
#> Lower middle income 47 1574.2535 676.3157 444.2899 2896.8682
#> Upper middle income 60 4945.3258 2327.3834 1604.595 13344.5423
#>
#> $PCGDP$Within
#> N Mean SD Min Max
#> High income 44.7746 12048.778 11467.9987 -33504.8721 76767.5254
#> Low income 46.8214 12048.778 154.1039 11606.2382 12698.296
#> Lower middle income 47.7872 12048.778 529.1449 10377.7234 14603.1055
#> Upper middle income 45.5667 12048.778 1860.395 4846.3834 24883.1246
#>
#>
#> $LIFEEX
#> $LIFEEX$Overall
#> N Mean SD Min Max
#> High income 3831 73.6246 5.6693 42.672 85.4171
#> Low income 1800 49.7301 9.0944 26.172 74.43
#> Lower middle income 2790 58.1481 9.3115 18.907 76.699
#> Upper middle income 3249 66.6466 7.537 36.535 80.279
#>
#> $LIFEEX$Between
#> N Mean SD Min Max
#> High income 73 73.6246 3.3499 64.0302 85.4171
#> Low income 30 49.7301 4.8321 40.9663 66.945
#> Lower middle income 47 58.1481 5.9945 45.7687 71.6078
#> Upper middle income 57 66.6466 4.9955 48.057 74.0504
#>
#> $LIFEEX$Within
#> N Mean SD Min Max
#> High income 52.4795 64.2963 4.5738 42.9381 78.1271
#> Low income 60 64.2963 7.7045 41.5678 84.4198
#> Lower middle income 59.3617 64.2963 7.1253 32.9068 83.9918
#> Upper middle income 57 64.2963 5.6437 41.4342 83.0122
#>
#>
# We can now use unlist2d to create a tidy data frame
unlist2d(psrl, c("Variable", "Trans"), row.names = "Income")
#> Variable Trans Income N Mean SD
#> 1 PCGDP Overall High income 3179.00000 30280.72833 23847.048336
#> 2 PCGDP Overall Low income 1311.00000 597.40532 288.439151
#> 3 PCGDP Overall Lower middle income 2246.00000 1574.25347 858.718342
#> 4 PCGDP Overall Upper middle income 2734.00000 4945.32584 2979.560925
#> 5 PCGDP Between High income 71.00000 30280.72833 20908.532258
#> 6 PCGDP Between Low income 28.00000 597.40532 243.821942
#> 7 PCGDP Between Lower middle income 47.00000 1574.25347 676.315687
#> 8 PCGDP Between Upper middle income 60.00000 4945.32584 2327.383427
#> 9 PCGDP Within High income 44.77465 12048.77802 11467.998655
#> 10 PCGDP Within Low income 46.82143 12048.77802 154.103875
#> 11 PCGDP Within Lower middle income 47.78723 12048.77802 529.144858
#> 12 PCGDP Within Upper middle income 45.56667 12048.77802 1860.395037
#> 13 LIFEEX Overall High income 3831.00000 73.62456 5.669317
#> 14 LIFEEX Overall Low income 1800.00000 49.73006 9.094399
#> 15 LIFEEX Overall Lower middle income 2790.00000 58.14807 9.311453
#> 16 LIFEEX Overall Upper middle income 3249.00000 66.64665 7.536998
#> 17 LIFEEX Between High income 73.00000 73.62456 3.349857
#> 18 LIFEEX Between Low income 30.00000 49.73006 4.832080
#> 19 LIFEEX Between Lower middle income 47.00000 58.14807 5.994485
#> 20 LIFEEX Between Upper middle income 57.00000 66.64665 4.995501
#> 21 LIFEEX Within High income 52.47945 64.29630 4.573796
#> 22 LIFEEX Within Low income 60.00000 64.29630 7.704485
#> 23 LIFEEX Within Lower middle income 59.36170 64.29630 7.125259
#> 24 LIFEEX Within Upper middle income 57.00000 64.29630 5.643696
#> Min Max
#> 1 932.04173 196061.41684
#> 2 164.33660 1864.79251
#> 3 144.98631 4818.19217
#> 4 132.07761 20532.95226
#> 5 5413.44953 141200.38001
#> 6 253.18856 1357.33257
#> 7 444.28990 2896.86818
#> 8 1604.59495 13344.54228
#> 9 -33504.87206 76767.52544
#> 10 11606.23817 12698.29600
#> 11 10377.72342 14603.10545
#> 12 4846.38341 24883.12456
#> 13 42.67200 85.41707
#> 14 26.17200 74.43000
#> 15 18.90700 76.69900
#> 16 36.53500 80.27900
#> 17 64.03017 85.41707
#> 18 40.96632 66.94497
#> 19 45.76870 71.60780
#> 20 48.05698 74.05037
#> 21 42.93814 78.12714
#> 22 41.56784 84.41984
#> 23 32.90682 83.99179
#> 24 41.43417 83.01217