Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calibration with raking method works with CALMAR2 SAS but not with Icarus in R #14

Open
EmanueleCeglia opened this issue Jun 11, 2024 · 4 comments

Comments

@EmanueleCeglia
Copy link

Hi, I need to perform a calibration using margins on a dataset of observations.
Now this operation is performed using the macro CALMAR2 in SAS, I tried using the Icarus package but the algorithm doesn't converge.
I checked all the input parameters and they are the same that I use in SAS, with the 'linear' method the algorithm converges but with the raking no.

@khaledlarbi
Copy link

Hi Emanuele,

Thank you very much for your message.

It may be difficult to address your issue without having more details (for instance, the number of calibration variables used, are they only numeric?).

The algorithm converges with both icarus and SAS (that's good news!). Are the weights from icarus and calmar the same?

Have a nice day.

Khaled

@EmanueleCeglia
Copy link
Author

HI @khaledlarbi thanks for your reply.
I try to explain better what I have to do.
I have a dataset of firms (interviewed in a survey), for each company I use some categorical observations in order to perform the weight calibration:

  • country (12 biggest EU countries)
  • sector (from A to D, we have four different sectors)
  • size (from 1 to 4, four different sizes: micro, small, medium, large)

Combining them together I create two new columns of observations:
ctrysize, ctrysect.

i.e. ctrysize: AT1, AT2, AT3, AT4, BE1, BE2, ... , SK3, SK4
i.e. ctrysect: ITA, ITB, ITC, ITD, GRA, GRB, ... , SKC, SKD

In total there are 48 unique observations for ctrysize and 48 for ctrysect.

In total my dataset has 11.699 companies interviewed so these combinations are repated, and I have no missing combinations.

Then I have margins, for each unique combination I have the total number of firms (integer) in the Euro Area, so I have two margins columns, one with the totals for each of the 48 ctrysize combinations and one with the totals for each of the 48 ctrysect combinations.

The margins columns are in alphabetic order.
What I do is to create a dataset with three columns: ctrysize, ctrysect, weight and 11.699 rows,
in the ctrysize col I have categorical data, in ctrysect as well and weight is initialized with 1.
I reorder the colmuns in alphabetic order and then I perform the calibration on this dataset using the two margins columns with Icarus.

calibration(data=dataset, marginMatrix=margins, colWeights="weight"
, method="raking", scale=T, description=T, maxIter = 2500,
calibTolerance = 0.0005)

But the algorithm doesn't converge with the raking method (I tried to modify also input parameters), with the linear converges but I need to perform the raking, because I have to migrate from SAS (where we use the macro Calmar2 raking method with the same dataset and it works) but I cannot understand why in R the algo doesn't converge.

Thanks for the support!!,
Emanuele

@EmanueleCeglia
Copy link
Author

Margins are properly created, here a pictures of how the margin dataset looks like
image

@khaledlarbi
Copy link

So, if I understood correctly: the algorithm converged in both calmar and icarus with the linear method. Did you compare the weights obtained from both methods? Are they the same?

Can you check that the weights you got from the linear method with icarus fulfill the margin constraints? For instance, if we consider the combination AT1, you need to ensure that the sum of the calibrated weights for units in country AT and size 1 is equal to the margin you provided in the margins matrix. I suggest checking this for all combinations.

Does "I have no missing combinations" mean that each combination has at least one unit?

Can you provide the code you used to run the calibration with calmar ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants