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

Error "attempt to select less than one element in get1index" #18

Closed
Kyoshido opened this issue Jan 18, 2022 · 1 comment
Closed

Error "attempt to select less than one element in get1index" #18

Kyoshido opened this issue Jan 18, 2022 · 1 comment
Assignees

Comments

@Kyoshido
Copy link
Contributor

Kyoshido commented Jan 18, 2022

Hello, I have this error

Error in { : 
  task 1 failed - "attempt to select less than one element in get1index"

Problem occurred during function simCategorical() with model method = "distribution".
The problem lies in other function generateValues_distribution.

Error "attempt to select less than one element in get1index" occurs when we use NULL as an index.
There is following code:

pSplit <- lapply(splitS, function(i) {
    tmp <- tableWt(dataSample[i, 
                              additional, 
                              with=FALSE], 
                   dataSample[[w]][i])
    tmp <- as.data.frame(tmp)
    p <- ncol(tmp)
    tmp[, p]/sum(tmp[, p])
  })

And the problem is in dataSample[[w]][i])
Because I want to model whole population, my weights are NULL. And the w = NULL cause an error.
This happened because in specifyInput.R the function is set with weight=NULL and from then the NULL travels.

 simPopObj <- function(data, hhid, hhsize=NULL, pid=NULL, weight=NULL,
                         strata=NULL, population=FALSE)
 dataS <- sampleObj(simPopObj)
 params$w <- dataS@weight
 w <- params$w
 dataSample[[w]][i])
@alexkowa
Copy link
Member

alexkowa commented Jan 25, 2022

Yes, the "distribution"-method gives this error, we will work on a fix. In the meantime, the other methods in simCategorical work fine.

Reproduced:

library(simPop)
data(eusilcS)
inp <- specifyInput(data=eusilcS, hhid="db030", hhsize="hsize", strata="db040", population = TRUE)
## in the following, nr_cpus are selected automatically
simPop <- simStructure(data=inp, method="direct", basicHHvars=c("age", "rb090"))
simPop <- simCategorical(simPop, additional=c("pl030", "pb220a"),
                         method="distribution", nr_cpus=1)

@alexkowa alexkowa self-assigned this Jan 25, 2022
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