# [R-sig-ME] calculate power-linear mixed effect model

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Fri Sep 17 22:55:32 CEST 2021

```I tried doing this but I am unsure if I am on the right track:

library(simr)

## trying to simulate some data and run a power calculation
x1 <- rnorm(1172) ## creating a continuous variable
x2 <- sample(1:2,1172,replace=T) # creating some sort of grouping
variable with 2 groups
y <- rbinom(n = 1172, size = 1, prob= 0.3) # creating a binary (0,1)
response variable (with probability of success = 0.3)
a=age(1172, x = 18:89, prob = NULL, name = "Age")   #simulating age
with “wakefield” package
s=sex(1172)   #simulating sex with “wakefield” package
df <- data.frame(y = y, x1 = x1, x2 = x2, a=a, s=s) #merging into one data set

y          x1 x2  a      s
1 0 -0.28876179  1 53   Male
2 0 -0.05696877  2 23 Female

m1 <- lmer(y ~ x1+a+s + (1|x2), data = df)

fixef(m1)["x1"] <-0.337

powerSim(m1)

I am getting a bunch of these messages when I run this:

“boundary (singular) fit: see ?isSingular”

On Fri, Sep 17, 2021 at 3:10 PM Ana Marija <sokovic.anamarija using gmail.com> wrote:
>
> Hi All,
>
> I plan to identify metabolite levels that differ between individuals
> with various retinopathy outcomes (DR or noDR). I plan to model
> metabolite levels using linear mixed models ref as implemented in
> lmm2met software. The model covariates will include: age, sex, SV1,
> SV, and disease_condition.
>
> The random effect is subject variation (ID)
>
> Disease condition is the fixed effect because I am interested in
> metabolite differences between those disease conditions.
>
> This command  will build a model for each metabolite:
> fitMet = fitLmm(fix=c('Sex','Age','SV1,'SV2','disease_condition'),
> random='(1|ID)', data=df, start=10)
>
> SV1 and SV2 are surrogate variables (numerical values)
>
> Next I need to calculate the power of my study. Let's say that I have
> 1,172 individuals total in the study, from which 431 are DR. Let's say
> that I would like to determine the power of this study given the
> effect size of 0.337.
>
> I know about SIMR software in R but I am not sure how to apply it to
> my study design.
>
> I looked at this paper:
> https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.12504
>
> But I am not sure how to adapt the code given in the tutorial so that
> it is matching to mine design.
>