# Simulation power analysis

How do you perform a power analysis for linear mixed model using R? I measure area of five groups of plants across time. Each group of plants grow under two treatments. I have 12 replicates for each plant. I have fitted a lme with plant group and treatment as fix effects and the replicates as random effect. How can I go from that to the actual calculation? I have found tools for ANOVAs and MANOVAs but not for lme. Thanks.

## 1 Answer

This is one way to perform power analysis using lmer. I have created a simulated data set using different functions. Here I report how I could perform the actual simulation.

library(lme4)
library(lmerTest)

simulateFixedEffect <- function(model, ecotype, time, id, B){
Tvalue=rep(0, B)
set.seed(781)
for(b in 1:B){
s1 <- drop(simulate(model))
ms <- lmer(s1$sim_1 ~ ecotype * time + (time | id)) Tvalue[b] <- anova(ms)[] } return(Tvalue) } plotValue <- function(Fvalue, alpha=0.05){ mean(Fvalue > alpha) hist(Fvalue, 30, prob=T, xlab="", ylab="", main="") x <- seq(0, 15, 0.1) lines(x, df(x,1,80), col="red") grid() } time <- (subdata$time)
gclass <- as.factor(subdata$gclass) id <- subdata$id
growth <- subdata\$growth

m1 <- lmer(growth ~ gclass * time + (time | id))
Tvalue <- simulateFixedEffect(m1,gclass, time, id, 10)