R Under development (unstable) (2025-07-22 r88445 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # install.packages("sampling") # Install "sampling" if it is unavailable. > library(GECal) > > ############ > ## Example 1 > ############ > # matrix of sample calibration variables > Xs=cbind( + c(1,1,1,1,1,1,1,1,1,1), + c(1,1,1,1,1,0,0,0,0,0), + c(1,2,3,4,5,6,7,8,9,10) + ) > # inclusion probabilities > piks=rep(0.2,times=10); d=1/piks > # vector of population totals > total=c(50,24,290) > > # Calibration weights > sampling::calib(Xs, total, d = d, method="raking") * d [1] 3.887155 4.297846 4.751928 5.253985 5.809086 4.211085 4.656000 5.147922 [9] 5.691817 6.293176 > calibration <- GEcalib(~ 0 + Xs, dweight = d, const = total, method = "DS", entropy = "ET") > calibration$w 1 2 3 4 5 6 7 8 3.887155 4.297846 4.751928 5.253985 5.809086 4.211085 4.656000 5.147922 9 10 5.691817 6.293176 > > sampling::calib(Xs, total, d = d, method="linear") * d [1] 3.8 4.3 4.8 5.3 5.8 4.2 4.7 5.2 5.7 6.2 > calibration <- GEcalib(~ 0 + Xs, dweight = d, const = total, method = "DS", entropy = "SL") > calibration$w 1 2 3 4 5 6 7 8 9 10 3.8 4.3 4.8 5.3 5.8 4.2 4.7 5.2 5.7 6.2 > > ############ > ## Example 2 > ############ > # Example of g-weights (linear, raking, truncated, logit), > # with the data of Belgian municipalities as population. > # Firstly, a sample is selected by means of Poisson sampling. > # Secondly, the g-weights are calculated. > data(belgianmunicipalities, package = "sampling") > attach(belgianmunicipalities) > # matrix of calibration variables for the population > X=cbind(1, + Men03/mean(Men03), + Women03/mean(Women03), + Diffmen, + Diffwom, + TaxableIncome/mean(TaxableIncome), + Totaltaxation/mean(Totaltaxation), + medianincome/mean(medianincome), + averageincome/mean(averageincome)) > # selection of a sample with expectation size equal to 200 > # by means of Poisson sampling > # the inclusion probabilities are proportional to the average income > pik=sampling::inclusionprobabilities(averageincome,200) > N=length(pik) # population size > s=sampling::UPpoisson(pik) # sample > Xs=X[s==1,] # sample matrix of calibration variables > piks=pik[s==1]; d = 1 / piks# sample inclusion probabilities > n=length(piks) # expected sample size > # vector of population totals of the calibration variables > total=c(t(rep(1,times=N))%*%X) > # computation of the g-weights > # by means of different calibration methods > > all.equal(sampling::calib(Xs, total, d = d, method="linear") * d, + unname(GEcalib(~ 0 + Xs, dweight = d, const = c(total), + method = "DS", entropy = "SL")$w)) [1] TRUE > GEcalib(~ 0 + Xs + g(d), dweight = d, const = c(total, sum(g(1 / pik, 1))), + method = "GEC", entropy = "SL")$w 1 2 3 4 5 6 7 8 2.0881182 2.8489891 3.2747159 1.2930235 2.2697676 1.7075901 2.5642814 2.9502167 9 10 11 12 13 14 15 16 2.4494187 3.1988676 3.5011352 3.7010764 3.3849146 3.6128897 2.6390215 3.7819679 17 18 19 20 21 22 23 24 3.4282653 3.0199699 2.7801438 3.8780357 4.1658702 0.4504122 1.6358052 0.4736610 25 26 27 28 29 30 31 32 2.9126312 2.2707461 2.8247571 2.6341552 3.1804563 2.2148799 2.8649050 3.0635180 33 34 35 36 37 38 39 40 2.8575977 5.1621068 3.4492239 2.8043208 1.3535373 1.1080310 2.4024245 2.6856979 41 42 43 44 45 46 47 48 2.8821625 2.8722299 1.8284062 2.1227088 2.6383223 2.3904296 2.6384962 3.2006783 49 50 51 52 53 54 55 56 2.6192843 1.9856392 2.0092725 1.6952678 2.9509461 3.3088519 2.7636569 2.1814246 57 58 59 60 61 62 63 64 1.8921169 1.4862582 2.0155376 0.9484103 2.3429816 2.7305532 2.7402604 2.6425105 65 66 67 68 69 70 71 72 2.8114435 3.2756879 2.6878059 3.3084371 4.6173339 3.7527326 3.5229441 4.8023852 73 74 75 76 77 78 79 80 3.0687867 3.0677915 4.1683072 3.1499409 4.1871902 2.8732736 3.0854008 3.5464226 81 82 83 84 85 86 87 88 2.9211666 2.9591297 4.2071963 4.1512616 3.5392315 3.2051109 3.1300905 3.9548568 89 90 91 92 93 94 95 96 3.1307663 3.4420951 2.7095219 3.1232724 2.7824523 2.6775070 3.3736295 3.3408766 97 98 99 100 101 102 103 104 2.4317420 2.6746758 2.7503879 2.3463598 1.3098154 2.3483051 2.9000178 2.1490954 105 106 107 108 109 110 111 112 2.7166577 4.8691038 3.5519508 3.7855302 4.3398405 3.1664414 3.6159791 2.8635794 113 114 115 116 117 118 119 120 2.7273721 3.3979740 2.6475817 4.4524082 3.0121888 1.7918238 3.2909824 3.8626692 121 122 123 124 125 126 127 128 3.4366186 3.0524091 2.6657914 2.7677753 3.4989806 3.9478250 2.5206299 2.9257950 129 130 131 132 133 134 135 136 2.5629084 2.6288163 2.2718073 3.4035216 2.8279010 3.5529328 1.6753813 2.1719455 137 138 139 140 141 142 143 144 3.5452075 2.7106387 0.5622637 3.6402336 3.5944459 3.0225667 3.1821672 4.3972698 145 146 147 148 149 150 151 152 2.7482232 3.0402510 3.6336332 3.5512202 2.9253103 3.3024516 2.6785972 3.7973691 153 154 155 156 157 158 159 160 3.1995186 2.8405497 3.8616197 3.8807378 4.1443884 3.7550148 3.3656357 4.1854286 161 162 163 164 165 166 167 168 2.6984343 3.2067074 2.8721798 3.3140030 2.2784344 3.6157036 4.4122066 3.9642243 169 170 171 172 173 174 175 176 5.7405786 3.5997059 5.7820359 3.5021212 3.5428426 2.6312056 3.2710701 3.0333874 177 178 179 180 181 182 183 184 3.3533465 3.4244955 3.2195020 4.4488918 4.2275215 3.6944600 2.9673664 4.1588295 185 186 187 188 189 190 191 192 4.5744184 2.7141413 2.4804819 2.7393361 3.5661441 4.0967245 4.6396910 4.4039443 > > all.equal(sampling::calib(Xs, total, d = d, method="raking") * d, + unname(GEcalib(~ 0 + Xs, dweight = d, const = c(total), + method = "DS", entropy = "ET")$w)) [1] TRUE > GEcalib(~ 0 + Xs + g(d), dweight = d, const = c(total, sum(g(1 / pik, 0))), + method = "GEC", entropy = "ET")$w 1 2 3 4 5 6 7 8 2.1115189 2.8026343 3.1080962 1.5149985 2.2984399 1.6635893 2.5597734 2.9367737 9 10 11 12 13 14 15 16 2.4508889 3.2256385 3.5000786 3.8526210 3.3935718 3.7586304 2.6229957 3.7775283 17 18 19 20 21 22 23 24 3.4787484 2.9503086 2.5078056 3.5086136 4.1965968 0.8915950 1.7100774 1.0132007 25 26 27 28 29 30 31 32 2.6622197 2.2710770 2.7430723 2.5753274 3.1331537 2.0548608 2.8311981 2.9849021 33 34 35 36 37 38 39 40 2.7709463 5.5826238 3.0117917 2.5935069 1.5243334 1.3736617 2.2291990 2.6237356 41 42 43 44 45 46 47 48 2.8530846 2.8534196 1.9135118 2.1849996 2.6118171 2.2469003 2.4108969 3.1536088 49 50 51 52 53 54 55 56 2.3788973 1.9186327 1.9173214 1.6818711 2.7656440 3.3045242 2.7497476 2.1720361 57 58 59 60 61 62 63 64 1.8808129 1.5700870 2.0860178 1.3160262 2.3004464 2.6596841 2.7406870 2.6497479 65 66 67 68 69 70 71 72 2.4483599 3.2396598 2.6977020 3.2291238 5.0127796 3.6366712 3.5101366 5.2415196 73 74 75 76 77 78 79 80 3.0475685 3.0417339 4.2920710 3.1820122 4.2910971 2.9186030 3.1069341 3.4829637 81 82 83 84 85 86 87 88 2.8862247 3.0299474 4.2907100 4.2446430 3.6282264 3.2065828 3.0991957 3.7907154 89 90 91 92 93 94 95 96 3.0869134 3.3180262 2.6291552 3.1875585 2.7787831 2.6978623 3.3766135 3.3001880 97 98 99 100 101 102 103 104 2.4200697 2.6309429 2.7699178 2.3830321 1.4799699 2.4211339 2.8911687 2.1576732 105 106 107 108 109 110 111 112 2.7116760 5.4169294 3.5976900 3.5642708 4.1499907 2.8467185 3.6363392 2.7354717 113 114 115 116 117 118 119 120 2.6682536 3.2255866 2.5682986 4.7549741 2.8866889 1.9273659 3.1735896 3.7955455 121 122 123 124 125 126 127 128 3.3969617 2.9623690 2.5419372 2.6179217 3.4275119 4.0664604 2.3270428 2.8838193 129 130 131 132 133 134 135 136 2.5692670 2.6546126 2.3257214 3.4693723 2.8153854 3.4780129 1.7358405 2.1916609 137 138 139 140 141 142 143 144 3.5001691 2.6420875 0.9253635 3.5069918 3.5031023 2.9043303 3.1776853 4.6417125 145 146 147 148 149 150 151 152 2.6149445 3.0711863 3.6816764 3.6102657 2.8527276 3.3496958 2.6756661 3.7789299 153 154 155 156 157 158 159 160 3.1233735 2.8035330 4.0247273 4.0885631 4.4974219 3.8540201 3.4123712 4.4629965 161 162 163 164 165 166 167 168 2.7002431 3.3673969 2.7633883 3.4485395 2.2959638 3.5019725 4.4349246 3.7272729 169 170 171 172 173 174 175 176 6.2724382 3.2430935 6.0411293 3.4047831 3.4541413 2.6551728 3.2294597 3.0120393 177 178 179 180 181 182 183 184 3.2159934 3.3447499 3.1636230 4.4157353 4.0942439 3.6884327 2.9286289 4.4070449 185 186 187 188 189 190 191 192 4.3276188 2.6508236 2.4925478 2.6902559 3.5034266 4.0604016 5.0003101 4.4324327 > > GEcalib(~ 0 + Xs, dweight = d, const = c(total), + method = "DS", entropy = "EL")$w 1 2 3 4 5 6 7 8 2.121846 2.818851 3.042670 1.432597 2.313030 1.638283 2.583752 2.866510 9 10 11 12 13 14 15 16 2.432233 3.274496 3.557403 4.041144 3.382992 3.886601 2.522294 3.724401 17 18 19 20 21 22 23 24 3.683786 2.881755 2.534072 3.326908 4.206823 1.213947 1.796244 1.185792 25 26 27 28 29 30 31 32 2.506216 2.512130 2.816322 2.564609 3.186625 1.747488 2.793911 2.911632 33 34 35 36 37 38 39 40 2.641888 6.116238 2.522033 2.229363 1.422258 1.456549 2.139008 2.538459 41 42 43 44 45 46 47 48 2.812326 2.930826 1.857629 2.125776 2.608242 2.022192 2.041338 3.121905 49 50 51 52 53 54 55 56 2.185291 1.625533 1.554450 1.537083 2.691233 3.378684 2.742501 2.314509 57 58 59 60 61 62 63 64 1.915348 1.478940 2.231001 1.370109 2.348834 2.802304 2.835006 2.736354 65 66 67 68 69 70 71 72 2.463265 3.238115 2.839184 3.088686 4.917621 3.462107 3.653729 5.254238 73 74 75 76 77 78 79 80 3.106797 3.034786 4.278664 3.145543 4.267185 2.954788 3.174200 3.490202 81 82 83 84 85 86 87 88 2.949972 3.088236 4.351501 4.306239 3.730279 3.253950 3.077517 3.539375 89 90 91 92 93 94 95 96 3.111677 3.197413 2.585469 3.305102 2.802435 2.785142 3.308544 3.116377 97 98 99 100 101 102 103 104 2.395451 2.522773 2.730252 2.410497 1.351858 2.571240 2.886046 2.402277 105 106 107 108 109 110 111 112 2.746329 6.331760 3.724163 3.224275 3.735083 2.820429 3.805478 2.984150 113 114 115 116 117 118 119 120 2.904447 3.297628 2.881445 4.741540 3.024122 2.170700 3.179258 3.729027 121 122 123 124 125 126 127 128 3.513589 3.087742 2.581423 2.722944 3.356384 4.157954 2.364628 3.032386 129 130 131 132 133 134 135 136 2.741245 2.759461 2.325503 3.572348 2.867911 3.516710 1.791909 2.322069 137 138 139 140 141 142 143 144 3.598711 2.636338 1.300151 3.418080 3.438381 2.943859 3.258376 4.401363 145 146 147 148 149 150 151 152 2.607763 3.028868 3.825975 3.628509 2.954531 3.552334 2.793054 3.843237 153 154 155 156 157 158 159 160 3.161149 2.751013 3.974282 4.147734 4.737178 3.806299 3.323108 4.578077 161 162 163 164 165 166 167 168 2.863034 3.531541 2.724388 3.609800 2.231848 3.525512 4.253108 3.735249 169 170 171 172 173 174 175 176 5.551892 3.089434 5.069210 3.384390 3.444498 2.605183 3.202182 2.994000 177 178 179 180 181 182 183 184 3.197755 3.347646 3.168904 4.067939 3.829748 3.868393 2.967590 4.721315 185 186 187 188 189 190 191 192 3.894494 2.633269 2.547626 2.669292 3.458001 3.877618 5.063858 4.159566 > > GEcalib(~ 0 + Xs, dweight = d, const = c(total), + method = "DS", entropy = "HD")$w 1 2 3 4 5 6 7 8 2.129105 2.832016 3.089917 1.383041 2.310663 1.649448 2.601570 2.883745 9 10 11 12 13 14 15 16 2.449194 3.291514 3.546806 3.998005 3.391075 3.839291 2.546610 3.824131 17 18 19 20 21 22 23 24 3.658029 2.920475 2.580116 3.467816 4.208645 1.093497 1.745296 1.084600 25 26 27 28 29 30 31 32 2.574728 2.506659 2.846983 2.585075 3.215534 1.753296 2.793065 2.921765 33 34 35 36 37 38 39 40 2.661066 5.802184 2.684884 2.276803 1.374786 1.416732 2.159278 2.556867 41 42 43 44 45 46 47 48 2.825605 2.941677 1.832270 2.109656 2.612216 2.033549 2.082175 3.153602 49 50 51 52 53 54 55 56 2.251150 1.618091 1.542290 1.518017 2.768503 3.379483 2.755712 2.323411 57 58 59 60 61 62 63 64 1.925613 1.452553 2.218610 1.303571 2.367935 2.817342 2.834244 2.739028 65 66 67 68 69 70 71 72 2.584257 3.252569 2.837999 3.133851 4.833068 3.471825 3.658537 5.212279 73 74 75 76 77 78 79 80 3.121844 3.052653 4.256292 3.150143 4.273292 2.938227 3.176269 3.508564 81 82 83 84 85 86 87 88 2.972116 3.064003 4.351162 4.295701 3.689032 3.267158 3.105090 3.719579 89 90 91 92 93 94 95 96 3.131911 3.275296 2.634881 3.296390 2.819990 2.779330 3.345788 3.147919 97 98 99 100 101 102 103 104 2.399232 2.533589 2.728001 2.400107 1.304863 2.543035 2.894272 2.414072 105 106 107 108 109 110 111 112 2.753314 5.821555 3.732763 3.318120 3.706702 2.826928 3.778819 3.006533 113 114 115 116 117 118 119 120 2.908428 3.276950 2.884622 4.689347 3.070989 2.144411 3.210991 3.727685 121 122 123 124 125 126 127 128 3.499563 3.116055 2.631307 2.698728 3.355878 4.091140 2.394034 3.028240 129 130 131 132 133 134 135 136 2.730271 2.743769 2.312028 3.531582 2.866582 3.540878 1.778367 2.311549 137 138 139 140 141 142 143 144 3.584214 2.662325 1.134972 3.477403 3.405602 2.986072 3.246118 4.347771 145 146 147 148 149 150 151 152 2.657717 3.020020 3.788802 3.603422 2.958906 3.510078 2.784119 3.868457 153 154 155 156 157 158 159 160 3.183581 2.771564 3.948696 4.077504 4.619304 3.857174 3.355475 4.557214 161 162 163 164 165 166 167 168 2.862735 3.511018 2.771481 3.567356 2.232420 3.560281 4.263292 3.754329 169 170 171 172 173 174 175 176 5.573615 3.147071 5.062205 3.390888 3.452417 2.609483 3.214724 3.003054 177 178 179 180 181 182 183 184 3.217246 3.354377 3.196161 4.099437 3.840825 3.866036 2.982357 4.561042 185 186 187 188 189 190 191 192 4.095832 2.658544 2.542896 2.686027 3.463867 3.878263 4.926195 4.125094 > > GEcalib(~ 0 + Xs + g(d), dweight = d, const = c(total, sum(g(1 / pik, -1/2))), + method = "GEC", entropy = "HD")$w 1 2 3 4 5 6 7 8 2.128010 2.784435 2.981405 1.594697 2.314012 1.676963 2.557201 2.931537 9 10 11 12 13 14 15 16 2.454683 3.223916 3.495677 3.907748 3.392675 3.817386 2.618994 3.718013 17 18 19 20 21 22 23 24 3.481074 2.891916 2.434289 3.349690 4.202622 1.082608 1.783816 1.193586 25 26 27 28 29 30 31 32 2.549447 2.285262 2.702807 2.551009 3.099785 2.013236 2.800467 2.934027 33 34 35 36 37 38 39 40 2.721052 5.797709 2.800183 2.499316 1.592775 1.470117 2.176854 2.594446 41 42 43 44 45 46 47 48 2.830230 2.840923 1.953945 2.212666 2.600154 2.195028 2.327271 3.120105 49 50 51 52 53 54 55 56 2.307962 1.907527 1.894241 1.703549 2.690765 3.295701 2.743411 2.183899 57 58 59 60 61 62 63 64 1.893697 1.619185 2.123348 1.441465 2.293587 2.637147 2.737944 2.655841 65 66 67 68 69 70 71 72 2.317440 3.218432 2.703300 3.187790 5.278583 3.564967 3.488679 5.510012 73 74 75 76 77 78 79 80 3.033776 3.029126 4.343222 3.193355 4.317776 2.941776 3.111558 3.437649 81 82 83 84 85 86 87 88 2.869590 3.062497 4.309230 4.249250 3.656369 3.190437 3.074526 3.647510 89 90 91 92 93 94 95 96 3.064083 3.229999 2.590473 3.206374 2.774030 2.705979 3.363596 3.255824 97 98 99 100 101 102 103 104 2.420376 2.619024 2.783101 2.396619 1.546581 2.458431 2.886198 2.169724 105 106 107 108 109 110 111 112 2.709669 5.708003 3.589480 3.434049 4.034471 2.732300 3.633671 2.684545 113 114 115 116 117 118 119 120 2.649494 3.188988 2.542548 4.957019 2.822238 1.984956 3.127456 3.754874 121 122 123 124 125 126 127 128 3.374110 2.919642 2.496384 2.583377 3.394087 4.133057 2.283207 2.869396 129 130 131 132 133 134 135 136 2.578956 2.671066 2.355096 3.498608 2.815503 3.428300 1.783124 2.218276 137 138 139 140 141 142 143 144 3.479517 2.621781 1.099133 3.428673 3.475336 2.851704 3.178011 4.806360 145 146 147 148 149 150 151 152 2.570399 3.076668 3.703513 3.643168 2.827624 3.365542 2.681162 3.748688 153 154 155 156 157 158 159 160 3.088515 2.789576 4.110994 4.203846 4.704362 3.872397 3.419487 4.592685 161 162 163 164 165 166 167 168 2.700409 3.420841 2.721060 3.473853 2.304313 3.425589 4.412699 3.578789 169 170 171 172 173 174 175 176 6.591903 3.068020 6.114769 3.354206 3.406538 2.662772 3.210990 3.006124 177 178 179 180 181 182 183 184 3.154970 3.305590 3.132777 4.359377 3.996121 3.664270 2.909634 4.561598 185 186 187 188 189 190 191 192 4.158255 2.631515 2.505004 2.665491 3.469433 4.025993 5.249391 4.440324 > > proc.time() user system elapsed 0.23 0.15 0.37