pitakakariki / simr

Power Analysis of Generalised Linear Mixed Models by Simulation
68 stars 19 forks source link

Extend with unbalanced dataframe #221

Closed filippogambarota closed 2 years ago

filippogambarota commented 3 years ago

Is there any way to use the extend function with a dataframe where the number of observation in a condition is lower compared to another? I did not found any along or within combination that allow me to create a simulation where the dataset is balanced. For example:

dat <- data.frame(
    id = 1:20,
    group = rep(c("a", "b"), c(15, 5)),
    y = rnorm(20)
)

How can I managed this? If I want that ids will be equally distributed on the group factor?

pitakakariki commented 3 years ago

Sorry, this hasn't been implemented yet.

Easiest way for now is probably to arrange the data frame so that recycling it doesn't distort the proportions, e.g.:

dat2 <- data.frame(
    id = 1:20,
    group = rep(c("a", "a", "a", "b"), 5),
    y = rnorm(20)
)
filippogambarota commented 3 years ago

Thank you! What about allowing the user to directly pass a custom dataset (maybe created with expand.grid()) for having more flexibility?

pitakakariki commented 3 years ago

That you can do - e.g.: getData(fm) <- dat.

filippogambarota commented 2 years ago

Great! thank you!