I'm using simr for power analysis of a linear mixed effects model. Most examples I've seen use data from pilot studies for simulation, but I don't have any data yet. My questions are:
- Is data for the dependent/response variable necessary when using simr for power analysis?
- I've tried running simulations using a dataset without a dependent variable, and it seems to work. Is this approach valid?
- If data for the dependent/response variable is indeed necessary, should I generate random values? If so, how should I approach this?
Below is my current code in case that helps.
library(dplyr)
library(tidyr)
library(simr)
# Set parameters
n_subjects <- 100
n_events <- 24
# retrieve counterbalance of schemas & condition to balance frequency
counterbal <- read.csv("counterbalance.csv")
conditions <- expand.grid(
distance = c("close", "far"),
direction = c("antecedent", "consequence")
)
# randomly assign counterbalance group to participants
get_subj_data <- function(subj_id) {
temp <- data.frame(subject = rep(subj_id, n_events))
temp$event <- 1:n_events
counter <- sample(1:4, 1)
temp$conditions <- counterbal[[paste0("Counter", counter)]]
temp$distance <- conditions$distance[temp$conditions]
temp$direction <- conditions$direction[temp$conditions]
return(temp)
}
df <- data.frame()
for (i in 1:n_subjects) {
subj_data <- get_subj_data(i)
df <- rbind(df, subj_data)
}
# H1 - main effect T(consq) > T(ante)
# here specify effect size! Not coefficients!
fixed <- c(0.5, 0.5, 0.5, 0.5)
rand <- list(0.2, 0.1) # not sure what is this
res <- 2
model <- makeLmer(latency ~ direction * distance + (1|subject) + (1|event),
fixef=fixed, VarCorr=rand, sigma=res, data=df)
model
# simulation on direction?
sim_direction <- powerSim(model, nsim=100, test = fcompare(~ distance))
sim_direction
Which gives me the following output:
> sim_direction
Power for model comparison, (95% confidence interval):
100.0% (96.38, 100.0)
Test: Likelihood ratio
Comparison to ~distance + [re]
Based on 100 simulations, (0 warnings, 0 errors)
alpha = 0.05, nrow = 2400
Time elapsed: 0 h 0 m 12 s
```
simr
with data that does not include the response. But, did you specify model parameters (fixed effects, random effects, and residual variance) ? If not then I'm not sure how you could get a sensible answer. Can you include your code in the question (just edit the question and paste your code (and output if you wish) but surround it with 3 backticks: ``` and the start and end, and the system will format it nicely.) $\endgroup$