Giter Site home page Giter Site logo

mixedpower's Introduction

mixedpower

A package for simulation-based power analyses in (generalized) linear mixed models

Getting started

1. Install mixedpower

To set up mixedpower, copy this bit of code and run in in your R-environment:

  if (!require("devtools")) {
    install.packages("devtools", dependencies = TRUE)}

   devtools::install_github("DejanDraschkow/mixedpower") 

2. Documentation

Details to functions included in mixedpower can be found in the mixedpower documentation

3. Open Notebooks & Tutorial

Find example analyses and supporting information in the following Open Notebooks or the accompanying tutorial paper.

4. FAQ

Common error messages and solutions can be found in the mixedpower FAQ.

If you use the library, please cite:

Kumle, L., Võ, M. L., & Draschkow, D. (2021). Estimating power in (generalized) linear mixed models: an open introduction and tutorial in R. Behav Res. doi:10.3758/s13428-021-01546-0

🐥

mixedpower's People

Contributors

dejandraschkow avatar lkumle avatar promyloph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mixedpower's Issues

Failing to install

Dear all,
On mac OS BigSur Version 11.6 Apple M1, "R version 4.1.2 (2021-11-01)" I have the following message error when trying to install your package running:

if (!require("devtools")) {
install.packages("devtools", dependencies = TRUE)}
devtools::install_github("DejanDraschkow/mixedpower") # mixedpower is hosted on GitHub

result in
Downloading GitHub repo DejanDraschkow/mixedpower@HEAD
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

1: All
2: CRAN packages only
3: None
4: Rcpp (1.0.10 -> 1.0.11) [CRAN]
5: ps (1.7.2 -> 1.7.5 ) [CRAN]
6: processx (3.8.0 -> 3.8.2 ) [CRAN]
7: digest (0.6.31 -> 0.6.33) [CRAN]
8: testthat (3.1.5 -> 3.1.10) [CRAN]
9: plyr (1.8.8 -> 1.8.9 ) [CRAN]
10: minqa (1.2.5 -> 1.2.6 ) [CRAN]

Enter one or more numbers, or an empty line to skip updates: 3
Error: Failed to install 'mixedpower' from GitHub:
lazy-load database '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/pkgbuild/R/pkgbuild.rdb' is corrupt
In addition: Warning messages:
1: In safe_build_package(pkgdir, build_opts, build_manual, build_vignettes, :
restarting interrupted promise evaluation
2: In safe_build_package(pkgdir, build_opts, build_manual, build_vignettes, :
internal error -3 in R_decompress1

Is anyone can help ?
Thank you in advance.
Sébastien

SESOI Error

Hi, I'm getting an error about the length for SESOI even though I checked and the length for SESOI and my coefficients match. It isn't the warning mentioned in the FAQ, this is an error that stops the command from running. I am running mixedpower v. 0.1.0 installed from github with devtools in R 4.2.0

sesoi <- c(-0.83, .005, .042, .028, -.14, .016, .076, .008)
> length(sesoi)
[1] 8
> length(row.names(summary(power_fit_m1$full_model)$coefficients))
[1] 8

> power <- mixedpower(model = power_fit_m1$full_model, data = cleanChoicedata_prob,
+                         fixed_effects = c("cueValidity","prevRew", "rewCond"),
+                         simvar = "participant", steps = c(250,300,350,400,450,500),
+                         critical_value = 2, n_sim = 1000, SESOI = sesoi, databased = T)
Error in if (SESOI != F & length(SESOI) != length(row.names(summary(model)$coefficients))) { : 
  the condition has length > 1

Thanks for any guidance on this. I can run the power analysis without SESOI.

Could not figure out the error message

Hi,
Thanks for the awesome package. I was trying to run the simulation but I encountered an error message. Could you help me to identify what might be the problem? Let me know if other information is needed.


"""
"Estimating power for step:"
[1] 60
[1] "Simulations for step 60 are based on 0 successful single runs"
Error in apply(store_simulations, MARGIN = 1, FUN = mean, na.rm = T) :
dim(X) must have a positive length
"""
Here are the model
m1<-glmer(word_order~ longdaylanguage+(1+day|participant_id) + (1|list), data=prod, family='binomial', glmerControl(optimizer="bobyqa"))

powerm2_sesoi_2 <- mixedpower(model = m1, data = prod, fixed_effects = c("long", "day", "language"),simvar = "participant_id_dummy", steps = c(60), critical_value = 2, SESOI = SESOIs2, databased = F)


Session Info

R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] stringr_1.4.0 ggplot2_3.3.0 mixedpower_0.1.0 lme4_1.1-21 Matrix_1.2-18 dplyr_0.8.3 rlang_0.4.10

loaded via a namespace (and not attached):
[1] pkgload_1.2.1 foreach_1.5.1 splines_3.6.3 Formula_1.2-3 assertthat_0.2.1
[6] latticeExtra_0.6-29 remotes_2.3.0 sessioninfo_1.1.1 pillar_1.4.3 backports_1.1.5
[11] lattice_0.20-40 glue_1.3.1 digest_0.6.25 RColorBrewer_1.1-2 checkmate_2.0.0
[16] minqa_1.2.4 colorspace_1.4-1 htmltools_0.4.0 pkgconfig_2.0.3 devtools_2.4.0
[21] purrr_0.3.2 scales_1.0.0 processx_3.5.1 jpeg_0.1-8.1 tibble_3.0.3
[26] htmlTable_1.13.3 usethis_2.0.1 ellipsis_0.3.1 cachem_1.0.4 withr_2.4.1
[31] nnet_7.3-13 cli_2.4.0 survival_3.1-11 magrittr_1.5 crayon_1.3.4
[36] memoise_2.0.0 ps_1.6.0 fansi_0.4.1 fs_1.5.0 doParallel_1.0.16
[41] nlme_3.1-145 MASS_7.3-51.5 foreign_0.8-76 pkgbuild_1.2.0 tools_3.6.3
[46] data.table_1.12.8 prettyunits_1.1.1 lifecycle_1.0.0 munsell_0.5.0 cluster_2.1.0
[51] callr_3.6.0 compiler_3.6.3 grid_3.6.3 nloptr_1.2.2.1 iterators_1.0.13
[56] rstudioapi_0.13 htmlwidgets_1.5.1 labeling_0.3 base64enc_0.1-3 boot_1.3-24
[61] testthat_3.0.2 codetools_0.2-16 gtable_0.3.0 curl_4.3 R6_2.4.1
[66] gridExtra_2.3 knitr_1.31 utf8_1.1.4 fastmap_1.0.1 Hmisc_4.4-0
[71] rprojroot_1.3-2 desc_1.3.0 stringi_1.4.3 parallel_3.6.3 Rcpp_1.0.2
[76] vctrs_0.3.2 rpart_4.1-15 acepack_1.4.1 png_0.1-7 tidyselect_1.1.0
[81] xfun_0.22

Specifying an intercept as a fixed effect.

Hey team!

Thank you for creating a very useful library – it's been a huge help!

I'm curious, though, is there any way to set the intercept as a fixed effect? Right now, I'm trying to figure out the required sample size to check if an intercept is not zero. If you have already covered this in the documentation, my apologies for overlooking it.

Thanks again for all your hard work on this project.

Best regards,

Add option to specify the number of cores used

Looks like mixedpower by default uses all the available cores except one:

    cores = parallel::detectCores()
    cl <- parallel::makeCluster(cores[1] - 1)
    doParallel::registerDoParallel(cl)

As we have many users working on our computational cluster, it would be helpful if we could specify the maximum number of cores used.

Thank you for considering this request.

Run Time Ongoing

Hello,

I am attempting to perform a post-hoc power analysis on a complex linear mixed effects model from real data. We want to see how powered we are with each effect of interest. The model has a total of 6 predictor terms and two random effects. The full model assessed a three-way interaction and thus contains 15 total estimates (including the constant).

I treated the following variables as:

model <- lme4 model object
data <-  exact data frame used to create lme4 model object (was filtered to only consider accurate responses)
fixed_effects <- vector of individual variables terms, as strings used in the model : example c("variable 1", "variable 2", etc..)
simvar <- Subject dummy coded, as used in lme4 

# SIMULATION PARAMETERS
steps <- c(30, 40, 50, 60, 70, 90, 120, 160, 180) # sample sizes that we want to estimate!
critical_value <- 2 # which t/z value do we want to use to test for significance?
n_sim <- 1000 # how many single simulations should be used to estimate power?

# ------------------------------------------ #
# INCLUDE SESOI SIMULATION

SESOI <- vector of 15 effect sizes that correspond to the 15 betas produced by the lme4 model: example c(45.3, .076, etc..)

# ------------------------------------------ #
# RUN SIMULATION
level_sim <- mixedpower(model = model, data = subset(data, stimulus.ACC == 1),
                              fixed_effects = fixed_effects,
                              simvar = "dum_sum", steps = steps,
                              critical_value = 2.0, n_sim = n_sim,
                              SESOI = SESOI, databased = T)

My issue is that for the past few days I have been stuck on "step 30" even though my r-script is running on a high-performance computer with 32 cores and 500 gigabytes of RAM. It may be that this is expected considering what I asked mixed power to do but I am unsure of why that is the case and how it is occurring under the hood. Could this be solved with a verbose output? Is this a flag I am missing that I should know about?

Any advice and direction here is greatly appreciated!

Random factors as numeric

In the help documents it references the random variable as a character vector but throws an error when factor is not numeric. Can this be changed? In most cases my random vars are factors/chars not numeric (I have a feeling this is the case for most users).

multiplotPower error

When I use multiplotPower on R 4.3.0 the plot is not working. I get only the response:
RStudioGD
2

Having trouble storing simulations?

HI! Every time I try to run simulations i'm getting this error:

Error in apply(store_simulations, MARGIN = 1, FUN = mean, na.rm = T) :
dim(X) must have a positive length

along with these warnings: In for (v in val) { ... : closing unused connection 16 (<-localhost:11941)

I'm confused because this package has worked fine for me in the past! Any help would be greatly appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.