haroine / icarus

A package with useful functions for calibration and reweighting in survey sampling
9 stars 5 forks source link

Bounds not working #10

Open TimBock opened 5 years ago

TimBock commented 5 years ago

When I run the following, I get minimum and maximum weight values that are outside the bounds. Sorry if I've misunderstood the documentation...

library(icarus) mar1 <- c("categ",3,80,90,60) mar2 <- c("sexe",2,140,90,0) mar3 <- c("service",2,100,130,0) mar4 <- c("salaire", 0, 470000,0,0) margins <- rbind(mar1, mar2, mar3, mar4) wCal <- calibration(data = data_ex2, marginMatrix = margins, colWeights="poids", method = "logit", bounds = c(3, 38), description=FALSE) range(wCal)

haroine commented 5 years ago

Hi! Thanks for the reproducible example!

The bounds are actually on the g-weights (i.e. reweighting factor = w/d), which in this case refers to the vector wCal / data_ex2$poids

The problem as defined here does not actually have a solution, since margin on categ for example implies a constraint on total population of 230, but the min bound of 3 on the reweighting factor would mean an estimated pop total with calibrated weights of at least 3*230 = 690. What you observe here is thus a numerical aberration (icarus finds a numerical solution within the pre-set 1e-6 tolerance).

If what you want is the range of the final weight wCal between 3 and 38, since all initial weights are equal to 10 you can thus use:

bounds = c(0.3, 380)

which gives:

> range(wCal)
[1]  3.96063 39.08558

Hope it helps :)

TimBock commented 5 years ago

Ah! That helps a lot. Many thanks.

Tim From: Antoine R notifications@github.com Sent: Tuesday, May 28, 2019 11:05 AM To: haroine/icarus icarus@noreply.github.com Cc: Tim Bock tim.bock@displayr.com; Author author@noreply.github.com Subject: Re: [haroine/icarus] Bounds not working (#10)

Hi! Thanks for the reproducible example!

The bounds are actually on the g-weights (i.e. reweighting factor = w/d), which in this case refers to the vector wCal / data_ex2$poids

The problem as defined here does not actually have a solution, since margin on categ for example implies a constraint on total population of 230, but the min bound of 3 on the reweighting factor would mean an estimated pop total with calibrated weights of at least 3*230 = 690. What you observe here is thus a numerical aberration (icarus finds a numerical solution within the pre-set 1e-6 tolerance).

If what you want is the range of the final weight wCal between 3 and 38, since all initial weights are equal to 10 you can thus use:

bounds = c(0.3, 380)

which gives:

range(wCal)

[1] 3.96063 39.08558

Hope it helps :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/haroine/icarus/issues/10?email_source=notifications&email_token=ADEF6QC2T2LCFDG2WRSXRY3PXSALZA5CNFSM4HPZTCQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWKWHRA#issuecomment-496329668, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADEF6QEWUVDS7U3BYOGW2WLPXSALZANCNFSM4HPZTCQA.