debruine / faux

R functions for simulating factorial datasets

Home Page:https://debruine.github.io/faux/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Power Simulations with Pilot Data

jgeller112 opened this issue · comments

Hi Lisa,

To start, great package! I have pilot data that I am trying to run power simulations on. Because I am not simulating data I tweaked your my_lmer_power function incorporating some simR functions:

my_lmer_power<-function(...) {
# ... is a shortcut that forwards any arguments to my_sim_data()
mode3<-simr::extend(fit, along="subject", n=30) # increase sample size from 5 to 30 
mod_sim <- lmer(aggbaseline ~ cueing + (1|subject), data = getData(mode3), REML=FALSE)
fixef(mod_sim)["cueing"]<-.01 # SESOI I want to run power simulations on with data. 
broom.mixed::tidy(mod_sim)
}

When I go to simulate the data sets, it simulates the same dataset 100 times.

reps <- 100
sims <- purrr::map_df(1:reps, ~my_lmer_power())
write_csv(sims, "sims.csv")

Any clue what I am doing wrong? Any help would be appreciated.

Jason



I haven't used {simr} before; where are you getting the object fit?

It looks to me like extend will always give you the exact same output for the same input. Try this:

library(simr)

fm <- lmer(y ~ x + (1|g), data=simdata)

extdata1 <- extend(fm, along="x", n=20) %>% getData()
extdata2 <- extend(fm, along="x", n=20) %>% getData()

all.equal(extdata1, extdata2)