statistikat / simPop

Simulation of Synthetic Populations for Survey Data Considering Auxiliary Information
30 stars 7 forks source link

Update simStructure #20

Closed Kyoshido closed 2 years ago

Kyoshido commented 2 years ago

Hello,

I was playing with the method of multinom for simulation of household size and had this error: Error in nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax = TRUE, : too many (1404) weights

So according to the answer in https://stackoverflow.com/questions/36303404/too-many-weights-in-multinomial-logistic-regression-and-the-code-is-running-for I added argument MaxNWts which in the nnet package is in general for controlling the maximum number of weights.

Then another error appeared in lapply where we draw from original sample for each stratum Error in sample.int(length(x), size, replace, prob) : incorrect number of probabilities

This was just caused by my data because
n <- households[grid[i, 1], grid[i, 2]] (= 0) w <- wH[split[[i]]] (= numeric (empty)) p <- w / sum(w) (= numeric (empty)) And sample function doesn't seem to cooperate with numeric (empty) input so I added a condition that if the p is empty then just add 0 otherwise calculate spSample(n,p)

After that the code run

Do you agree with the changes?

Kyoshido commented 2 years ago

I created different pull request, where I did better solution