Hi Paul,
I have one further direct follow-up question, if that’s ok. It relates to something that @ucfagls mentioned above.
I’d like to use this kind of model to make predictions for future simulated experiments. For instance, let’s say I ran a pilot study with N=5 participants. I’d like to build a model with the pilot data, then use that model to simulate data for datasets with say N=25 participants in each expeirment. The idea might be to get a sense of likely “power” or precision of the estimates if we were to run a larger scale study with more participants. However, for this kind of factor by smooth model, I get an error whereby it does not allow new levels of particiapnt ID. I assume this issue is related to the comment made by Gavin above regarding the treatment of varying effects in these kinds of models. However, I am not sure, so I am reaching our for advice and guidance. Is it possible to set new levels of participant ID in these kinds of models? The usual allow_new_levels() arguement does not work.
As always, any help or advice would be very much appreicated. And if you need further information then please let me know. And it is possible that I have confused one or more aspects of this approach, so apologies in advance if that is the case.
The model formula, code to generate predictions and the error message it returns are copied below, in case they are helpful.
Best regards,
Rich
This is the model formula:
pupil ~ 1 + condition +
s(time, by = condition, bs = “bs”, k = 10) +
s(time, pid, bs = “fs”, xt = list(bs = "bs"))
And this is the code that I might use to generate predictions for one exp:
## nd = new data
nd <- crossing(pid = factor(1:25),
condition = c("slow", "medium", "fast"),
time = seq(0, 29800, 200)) %>%
mutate(condition = factor(condition,
levels = c("slow", "medium", "fast")))
head(nd)
sim_data <- add_predicted_draws(newdata = nd,
object = model)
head(sim_data)
and this is the error that it returns:
Error: New factor levels are not allowed.
Levels allowed: ‘1’, ‘2’, ‘3’, ‘4’, ‘5’
Levels found: ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’, ‘11’, ‘12’, ‘13’, ‘14’, ‘15’, ‘16’, ‘17’, ‘18’, ‘19’, ‘20’, ‘21’, ‘22’, ‘23’, ‘24’, ‘25’