philmikejones / rakeR

Tools for easy spatial microsimulation (raking) in R
http://philmikejones.github.io/rakeR/
11 stars 1 forks source link

Error when running rk_rake #91

Open radders opened 4 years ago

radders commented 4 years ago

When running the rk_rake command, I'm getting this error :

Error in if (!sum(weights_dec%%1) > 0) { : missing value where TRUE/FALSE needed

The arguments con, inds, vars look correct.

Any idea what could be causing this? First time I've used the package.

Thank

philmikejones commented 4 years ago

Are you able to share some of your data so I can replicate the error? Happy to take a look.

radders commented 4 years ago

Thanks for having a look at this. I can't show the individuals data but the structure is :

person_id, sex, oa_code, age_band, age_sex, oac_grp and it has just over 3,000 rows.

I'm using the code from Roger Beecham's tutorial here : http://homepages.see.leeds.ac.uk/~georjb/predictive-analytics/assignment/01-simulating-behaviour/

The other data attached is from the census.

data.zip

philmikejones commented 4 years ago

Hi Rob,

I've just emailed you an answer as well.

I think what was causing the error was that you had a zone that required lots of people of OAC group 3, but only 2 individuals of that group. These also both happened to be male 35-64, so the algorithm had no individuals of other age/sex combinations to simulate.

I've removed these and the simulation works, which I've sent to you. Please leave this issue open as I want to incorporate a way to test for errors of this type to provide feedback to the user. I'll have to come back to this, though.

philmikejones commented 4 years ago

Technical note: NA/NaNs introduced at weight stage in rk_weight()