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 1.40226300 3.66589925 0.63124303 2.87700773 3.16120332 1.68006943 7 8 9 10 11 12 2.78227006 2.40596498 0.48482895 2.62342948 2.79655616 1.62721422 13 14 15 16 17 18 2.45854582 2.63902508 2.55784587 2.59426460 3.37080695 2.90183889 19 20 21 22 23 24 2.77223488 2.86165817 3.15024183 2.90666861 2.92184636 2.20426582 25 26 27 28 29 30 3.31924502 4.12119505 4.80919009 5.11420448 6.49681715 3.48539002 31 32 33 34 35 36 2.74445785 2.38757603 2.62499054 4.08616984 2.80576405 2.24276292 37 38 39 40 41 42 3.26480581 2.30628654 2.30665353 3.69652894 2.06114887 2.51953362 43 44 45 46 47 48 1.91122561 2.55479859 3.07632646 2.64715854 4.61815845 2.61579499 49 50 51 52 53 54 3.46335528 0.62563337 2.15416404 1.94075161 2.28759710 3.07407877 55 56 57 58 59 60 1.56169119 3.04997649 2.21232528 2.22936628 2.92152174 2.12253711 61 62 63 64 65 66 3.07291214 2.25436208 2.58934332 1.52043786 3.01386542 2.48047440 67 68 69 70 71 72 -0.07402902 3.76419000 3.23557581 2.56979102 1.45468556 2.52250943 73 74 75 76 77 78 3.02797312 2.95518384 1.37045876 2.96408375 3.84588150 1.96104727 79 80 81 82 83 84 0.06022848 2.19208139 3.39706195 3.07571231 3.72821380 2.84814310 85 86 87 88 89 90 2.68397252 3.32079939 3.58299201 3.51034315 3.39523445 3.19447100 91 92 93 94 95 96 2.89535058 3.34698355 2.12846000 3.53620350 2.47283164 2.86235921 97 98 99 100 101 102 2.89044184 2.39474971 3.14025193 2.80273279 2.80203875 1.76574549 103 104 105 106 107 108 3.38098289 2.85657840 2.08432048 4.74966632 2.72303737 2.53134747 109 110 111 112 113 114 1.35949488 2.50595698 2.52112464 1.88933495 2.82069592 2.81840141 115 116 117 118 119 120 3.21076019 3.02865383 3.30623099 3.70984213 2.73906220 3.26744612 121 122 123 124 125 126 2.33824397 2.59798334 2.94847499 3.37929150 3.29850468 3.28142193 127 128 129 130 131 132 2.93174033 3.16948379 3.45308505 3.13641126 3.39331916 3.21547387 133 134 135 136 137 138 3.51555882 3.22612543 3.29005913 3.49026662 2.91645244 3.00436564 139 140 141 142 143 144 2.61181346 3.22216560 2.90328217 3.52260014 3.06212793 3.16879074 145 146 147 148 149 150 2.83314018 4.31264518 4.80569941 3.11411070 3.73402022 3.47919396 151 152 153 154 155 156 3.61160270 3.42238107 3.42917586 4.10240528 3.31517625 3.03300264 157 158 159 160 161 162 3.47453368 2.75211254 3.02000132 2.09709779 2.75411137 2.68618280 163 164 165 166 167 168 3.08122621 2.53903550 3.60686353 3.35817965 2.65324960 3.03364442 169 170 171 172 173 174 2.86526565 2.63446586 2.43093536 2.95921425 3.41061464 3.21077383 175 176 177 178 179 180 3.06961823 3.13915914 3.46632752 3.68869265 3.38920895 3.06152540 181 182 183 184 185 186 3.48538403 3.53817671 2.91748738 3.54410319 2.41260444 3.57559688 187 188 189 190 191 192 2.24547647 3.02563955 3.79876678 3.55903158 3.47046202 3.68378436 193 194 195 196 197 198 4.70863659 3.16044402 2.95564883 2.96500969 3.13704860 3.55999833 199 200 201 2.95562912 3.57520916 3.07876723 > > 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 1.5239187 3.8039544 1.1483983 2.8549717 3.1635822 1.5848398 2.6616088 2.3993471 9 10 11 12 13 14 15 16 1.0207735 2.5043730 2.5259900 1.6537250 2.4156746 2.5838159 2.5109631 2.5315440 17 18 19 20 21 22 23 24 3.4375364 2.8830232 2.7412931 2.8242099 3.1730001 2.8913462 2.9092848 2.1662761 25 26 27 28 29 30 31 32 3.4155778 4.3793627 4.8635794 4.9888434 6.6239405 3.2860490 2.6035658 2.2108556 33 34 35 36 37 38 39 40 2.5781519 4.2729015 2.7696910 2.0971755 3.2359555 2.1409655 2.2402064 3.9620987 41 42 43 44 45 46 47 48 1.8756035 2.4124939 1.6582966 2.4693889 3.0222982 2.4830900 5.1925455 2.4406639 49 50 51 52 53 54 55 56 3.5391250 1.0235655 1.9860245 1.6851359 2.1881254 3.0923371 1.5763057 3.0728720 57 58 59 60 61 62 63 64 1.9921367 1.9582483 2.7623316 2.0537348 2.9887261 1.9615775 2.4880544 1.4744932 65 66 67 68 69 70 71 72 2.9198590 2.3289517 0.6780169 3.6142107 3.2467516 2.4403734 1.4514748 2.4396543 73 74 75 76 77 78 79 80 2.9434957 2.9835616 1.5257976 2.9312302 4.0139692 2.0054262 0.8618429 2.1587448 81 82 83 84 85 86 87 88 3.2570985 3.0432568 3.8303854 2.7752433 2.6039688 3.3607542 3.7424635 3.6799062 89 90 91 92 93 94 95 96 3.5011962 3.2565339 2.8114144 3.2725636 2.1204748 3.5781879 2.4568108 2.8563591 97 98 99 100 101 102 103 104 2.8691320 2.3573107 3.1569879 2.7722264 2.7663995 1.7620630 3.5140196 2.7608962 105 106 107 108 109 110 111 112 1.9230275 4.6027210 2.6776542 2.4824482 1.3443557 2.4849747 2.4882028 1.9365615 113 114 115 116 117 118 119 120 2.5817386 2.7814337 3.2172460 2.9920283 3.1336930 3.6609744 2.7068871 3.2729303 121 122 123 124 125 126 127 128 2.2555894 2.5173744 2.9026557 3.2348729 3.0520882 3.0850541 2.8804623 3.1468486 129 130 131 132 133 134 135 136 3.3515908 2.9208132 3.4193644 3.1736110 3.5538148 3.1742606 3.3722809 3.6600028 137 138 139 140 141 142 143 144 2.8747847 3.0221644 2.4719653 3.3055762 2.7628691 3.6759665 3.0300489 3.1736118 145 146 147 148 149 150 151 152 2.7388161 4.4806515 4.8189960 2.9432213 3.9003471 3.5571404 3.7058769 3.4742044 153 154 155 156 157 158 159 160 3.5040229 4.5144088 3.4223539 3.0565712 3.5490835 2.7193004 3.0395492 1.9191466 161 162 163 164 165 166 167 168 2.7162984 2.6412966 3.1155181 2.4980141 3.7919572 3.4673815 2.6097028 3.0497117 169 170 171 172 173 174 175 176 2.8433836 2.5785178 2.3511630 2.8546418 3.2018447 3.2556369 3.1232145 2.9958461 177 178 179 180 181 182 183 184 3.5276969 3.7293531 3.5161502 3.0778204 3.5135389 3.7308926 2.8463582 3.7575336 185 186 187 188 189 190 191 192 2.4660237 3.7877681 2.3447125 2.9716663 3.9768971 3.7353334 3.4691645 3.6684616 193 194 195 196 197 198 199 200 5.3761617 3.2123521 2.9092609 2.8684866 3.0524512 3.6710113 2.7390066 3.6239556 201 3.0570187 > > GEcalib(~ 0 + Xs, dweight = d, const = c(total), + method = "DS", entropy = "EL")$w 1 2 3 4 5 6 7 8 1.5972059 3.7361443 1.3689989 2.7880159 3.1176841 1.5859059 2.5581292 2.4010967 9 10 11 12 13 14 15 16 1.1955695 2.4067507 2.3541974 1.6622237 2.4267979 2.5488184 2.5075350 2.4635232 17 18 19 20 21 22 23 24 3.4149063 2.8410371 2.6661358 2.8077633 3.1581380 2.8666143 2.8884927 2.1284911 25 26 27 28 29 30 31 32 3.4333656 4.4644980 4.7469269 4.9573101 6.6126747 3.1030437 2.4806901 2.0921540 33 34 35 36 37 38 39 40 2.5041750 4.6346177 2.6569839 2.0059266 3.0839907 2.0555959 2.1954676 4.0849133 41 42 43 44 45 46 47 48 1.8292547 2.3422397 1.5947819 2.3871523 2.9303598 2.4023566 7.2065751 2.3663233 49 50 51 52 53 54 55 56 3.4524606 1.1773034 1.8864189 1.6474708 2.1392476 3.0141969 1.6082559 3.0165138 57 58 59 60 61 62 63 64 1.9446097 1.9061280 2.6337610 2.0430154 2.8226488 1.8429272 2.3907320 1.5067409 65 66 67 68 69 70 71 72 2.7792342 2.2100729 0.8707892 3.4478759 3.1242670 2.3281496 1.7001448 2.3862541 73 74 75 76 77 78 79 80 2.8577224 2.9520840 1.5972742 2.9334688 4.0932088 2.2024546 1.3199024 2.2687917 81 82 83 84 85 86 87 88 3.2741777 3.0796387 3.7772607 2.8562380 2.7056950 3.3644291 3.8099982 3.7516638 89 90 91 92 93 94 95 96 3.4987160 3.2578130 2.7765598 3.2815794 2.0481169 3.4913425 2.4550149 2.8297488 97 98 99 100 101 102 103 104 2.8206184 2.3368017 3.1030408 2.7165834 2.6940832 1.7841926 3.5365137 2.7888372 105 106 107 108 109 110 111 112 1.8881304 4.1200899 2.6193290 2.4535467 1.3783905 2.4992871 2.5762877 1.9629561 113 114 115 116 117 118 119 120 2.5474761 2.7659998 3.1494586 2.9552397 3.1731053 3.6157501 2.6502513 3.1577325 121 122 123 124 125 126 127 128 2.3059883 2.4704791 2.8021624 3.3058441 3.0714342 3.1833910 2.8771240 3.0657387 129 130 131 132 133 134 135 136 3.2918420 2.9685689 3.4347243 3.1688204 3.4996526 3.1429477 3.3247569 3.6737860 137 138 139 140 141 142 143 144 2.7851864 2.9697581 2.3892441 3.2792741 2.7512841 3.7295157 3.0080233 3.0803908 145 146 147 148 149 150 151 152 2.6454866 4.5169661 4.7792309 2.9734090 3.9932583 3.5545962 3.6662153 3.4382529 153 154 155 156 157 158 159 160 3.5155347 4.8168857 3.4377489 2.9894216 3.4633990 2.6552110 3.0151123 2.1880874 161 162 163 164 165 166 167 168 2.7055692 2.6493458 3.0688310 2.5466676 3.8556821 3.5682233 2.6810747 3.0060904 169 170 171 172 173 174 175 176 2.8402705 2.5387321 2.4282309 2.8331454 3.1983468 3.2296403 3.1181005 2.9955300 177 178 179 180 181 182 183 184 3.5149547 3.7826160 3.5054812 3.0376794 3.5271022 3.7666635 2.8553645 3.8119883 185 186 187 188 189 190 191 192 2.4617114 3.8299184 2.3678658 2.9580747 3.9972309 3.7830005 3.4639684 3.6870013 193 194 195 196 197 198 199 200 5.8829768 3.1873359 2.8458222 2.8326528 3.0246500 3.6751774 2.8369699 3.5785342 201 2.9756537 > > GEcalib(~ 0 + Xs, dweight = d, const = c(total), + method = "DS", entropy = "HD")$w 1 2 3 4 5 6 7 8 1.5707949 3.7840358 1.2638381 2.8144661 3.1376564 1.5971076 2.6092820 2.3887725 9 10 11 12 13 14 15 16 1.1152877 2.4447489 2.4407066 1.6487807 2.4136386 2.5569133 2.4979154 2.4922530 17 18 19 20 21 22 23 24 3.4298459 2.8633793 2.6944054 2.8075495 3.1691100 2.8732365 2.8909760 2.1450527 25 26 27 28 29 30 31 32 3.4345364 4.4401919 4.8039321 5.0571673 6.5980382 3.2110755 2.5428757 2.1468392 33 34 35 36 37 38 39 40 2.5242923 4.5268710 2.7086701 2.0511543 3.1603092 2.0951228 2.2073974 4.0449635 41 42 43 44 45 46 47 48 1.8670054 2.3756609 1.6233381 2.4261685 2.9778911 2.4643501 5.9755474 2.4231432 49 50 51 52 53 54 55 56 3.4989152 1.1051825 1.9331661 1.6790102 2.1666348 3.0530994 1.5958925 3.0462611 57 58 59 60 61 62 63 64 1.9925410 1.9658898 2.6973278 2.0332601 2.8958046 1.9180348 2.4295068 1.4915120 65 66 67 68 69 70 71 72 2.8522469 2.2469756 0.7973114 3.5546989 3.1802311 2.3827132 1.5694954 2.4087227 73 74 75 76 77 78 79 80 2.8933589 2.9643964 1.5494059 2.9257507 4.0632734 2.1005920 1.1093164 2.2040082 81 82 83 84 85 86 87 88 3.2775415 3.0590702 3.8130517 2.8150971 2.6519081 3.3643513 3.7841560 3.7255527 89 90 91 92 93 94 95 96 3.5066563 3.2590087 2.7826227 3.2824252 2.0675446 3.5390892 2.4462820 2.8399930 97 98 99 100 101 102 103 104 2.8408088 2.3391022 3.1279633 2.7420442 2.7232018 1.7627554 3.5349636 2.7649051 105 106 107 108 109 110 111 112 1.9223500 4.3842034 2.6517134 2.4618535 1.3745928 2.4812438 2.5255777 1.9338312 113 114 115 116 117 118 119 120 2.5441772 2.7647729 3.1785435 2.9656611 3.1547639 3.6439711 2.6661341 3.2119825 121 122 123 124 125 126 127 128 2.2630075 2.4746936 2.8400617 3.2776735 3.0554724 3.1488326 2.8707749 3.0980508 129 130 131 132 133 134 135 136 3.3148973 2.9469308 3.4323422 3.1697608 3.5309676 3.1525255 3.3497382 3.6758202 137 138 139 140 141 142 143 144 2.8198249 2.9935991 2.4391236 3.2949671 2.7419360 3.7158423 3.0133951 3.1202849 145 146 147 148 149 150 151 152 2.6807041 4.5316329 4.8041143 2.9500012 3.9705158 3.5591847 3.6927467 3.4597447 153 154 155 156 157 158 159 160 3.5165976 4.6753527 3.4338356 3.0199060 3.5112101 2.6730739 3.0259203 2.0540037 161 162 163 164 165 166 167 168 2.6995300 2.6340524 3.0938183 2.5124556 3.8341381 3.5226995 2.6379815 3.0229466 169 170 171 172 173 174 175 176 2.8338374 2.5446254 2.3771080 2.8322169 3.1936584 3.2415704 3.1274401 2.9891035 177 178 179 180 181 182 183 184 3.5290810 3.7839399 3.5183052 3.0522159 3.5302429 3.7622739 2.8429200 3.7956841 185 186 187 188 189 190 191 192 2.4648505 3.8203444 2.3580626 2.9565950 4.0091103 3.7679756 3.4700700 3.6998706 193 194 195 196 197 198 199 200 5.6309140 3.2073671 2.8712278 2.8384340 3.0316498 3.6872337 2.7877744 3.6042265 201 3.0270843 > > 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 1.5767747 3.8514304 1.3092604 2.8402710 3.1545681 1.5826372 2.6017942 2.4104368 9 10 11 12 13 14 15 16 1.1808316 2.4636964 2.4257074 1.6979833 2.4126428 2.5667837 2.5054328 2.5014557 17 18 19 20 21 22 23 24 3.4545818 2.8556736 2.7243312 2.8119171 3.1719143 2.8799508 2.9050014 2.1529919 25 26 27 28 29 30 31 32 3.4374606 4.5251200 4.8971671 4.8712170 6.6577270 3.1504481 2.5403490 2.1564241 33 34 35 36 37 38 39 40 2.5684548 4.2344649 2.7372046 2.0509389 3.2008400 2.0922362 2.2283920 4.0601215 41 42 43 44 45 46 47 48 1.8260587 2.3672244 1.6360445 2.4275035 2.9876491 2.3839787 5.5142024 2.3476385 49 50 51 52 53 54 55 56 3.5567895 1.1693789 1.9424684 1.6424265 2.1499810 3.0804184 1.6099656 3.0590417 57 58 59 60 61 62 63 64 1.9132877 1.8554916 2.6924636 2.0620479 2.9448188 1.8672724 2.4503798 1.5126805 65 66 67 68 69 70 71 72 2.8566204 2.2970936 0.8556978 3.4955822 3.2389214 2.3821749 1.5334965 2.4072796 73 74 75 76 77 78 79 80 2.9062054 2.9839527 1.6079538 2.9198849 4.1097833 2.0524714 1.0895185 2.1769781 81 82 83 84 85 86 87 88 3.1867786 3.0292859 3.8647478 2.7507911 2.5867499 3.3701485 3.8151678 3.7456992 89 90 91 92 93 94 95 96 3.5376724 3.2686373 2.7842451 3.2279474 2.1234430 3.5831089 2.4553552 2.8447064 97 98 99 100 101 102 103 104 2.8496379 2.3521586 3.1485430 2.7481711 2.7460821 1.7983775 3.5504277 2.7392354 105 106 107 108 109 110 111 112 1.8677504 4.5131639 2.6371708 2.4638765 1.3786579 2.4863120 2.4884251 1.9776006 113 114 115 116 117 118 119 120 2.5150957 2.7709704 3.2162135 2.9753796 3.0585445 3.6223739 2.6988694 3.2528341 121 122 123 124 125 126 127 128 2.2618405 2.5031190 2.8824863 3.1645715 2.9449389 2.9946252 2.8617592 3.1325269 129 130 131 132 133 134 135 136 3.3054054 2.8438996 3.4243265 3.1445025 3.5591424 3.1447979 3.3982820 3.7282955 137 138 139 140 141 142 143 144 2.8526366 3.0134139 2.3978673 3.3265961 2.7144441 3.7187658 3.0145244 3.1697048 145 146 147 148 149 150 151 152 2.7042835 4.5301688 4.7588257 2.8749467 3.9721063 3.5842104 3.7344677 3.4893874 153 154 155 156 157 158 159 160 3.5276946 4.7814809 3.4598350 3.0497908 3.5608143 2.7090349 3.0392955 1.9243191 161 162 163 164 165 166 167 168 2.7077168 2.6346391 3.1067050 2.5004128 3.8663879 3.5105436 2.6053421 3.0552589 169 170 171 172 173 174 175 176 2.8356810 2.5684965 2.3526742 2.8259431 3.1177165 3.2649941 3.1100436 2.9418597 177 178 179 180 181 182 183 184 3.5473539 3.7294456 3.5616070 3.0769812 3.5141111 3.8125823 2.8228950 3.8538415 185 186 187 188 189 190 191 192 2.4596301 3.8837104 2.3528187 2.9545014 4.0576159 3.8142831 3.4588083 3.6463393 193 194 195 196 197 198 199 200 5.9212749 3.2066331 2.8819313 2.8377748 3.0122610 3.6963151 2.6607702 3.6309282 201 3.0082211 > > proc.time() user system elapsed 0.31 0.07 0.37