Power analysis for longitudinal multilevel models: powerlmm 0.2.0 is now out on CRAN

My R packge powerlmm 0.2.0 is now out on CRAN. It can be installed from CRAN https://cran.r-project.org/package=powerlmm or GitHub https://github.com/rpsychologist/powerlmm.

Changes in version 0.2.0

New features

  • Analytical power calculations now support using Satterthwaite’s degrees of freedom approximation.
  • Simulate.plcp will now automatically create lme4 formulas if none is supplied, see ?create_lmer_formula.
  • You can now choose what alpha level to use.
  • Treat cluster sizes as a random variable, uneqal_clusters now accepts a function indicating the distribution of cluster sizes, via the new argument func, e.g. rpois or rnorm could be used to draw cluster sizes.
  • Expected power for designs with parameters that are random variables, can be calculated by averaging over multiple realizations, using the argument R.
  • Support for parallel computations on Microsoft Windows, and in GUIs/interactive environments, using parallel::makeCluster (PSOCK). Forking is still used for non-interactive Unix environments.

Improvements

  • Calculations of the variance of the treatment effect is now much faster for designs with unequal clusters and/or missing data, when cluster sizes are large. The calculations now use the much faster implementation used by lme4.
  • Cleaner print-methods for plcp_multi-objects.
  • Multiple power calculations can no be performed in parallel, via the argument cores.
  • simulate.plcp_multi now have more options for saving intermediate results.
  • print.plcp_multi_power now has better support for subsetting via either [], head(), or subset().

Breaking changes

  • icc_pre_subject is now defined as (u_0^2 + v_0^2) / (u_0^2 + v_0^2 + error^2), instead of (u_0^2) / (u_0^2 + v_0^2 + error^2). This would be the subject-level ICC, if there’s no random slopes, i.e. correlation between time points for the same subject.
  • study_parameters(): 0 and NA now means different things. If 0 is passed, the parameters is kept in the model, if you want to remove it specify it as NA instead.
  • study_parameters(): is now less flexible, but more robust. Previously a large combination if raw and relative parameters could be combined, and the individual parameters was solved for. To make the function less bug prone and easier to maintain, it is now only possible to specify the cluster-level variance components as relative values, if the other parameters as passed as raw inputs.

Bug fixes and minor changes

  • Output from simulate_data() now includes a column y_c that contains the full outcome vector, without missing values added. This makes it easy to compare the complete and incomplete data set, e.g. via simulate().
  • simulate() new argument batch_progress enables showing progress when doing multiple simulations.
  • Fix bug in summary.plcp_sim where the wrong % convergence was calculated.
  • Simulation function now accepts lme4 formulas containing ”||β€œ.
  • The cluster-level intercept variance is now also set to zero in the control group, when a partially nested design is requested.
  • Fix incorrect error message from study_parameters when icc_cluster_pre = NULL and all inputs are standardized.
  • Fix bug that would cause all slopes to be zero when var_ratio argument was passed a vector of values including a 0, e.g. var_ratio = c(0, 0.1, 0.2).
  • Fix bug for multi-sim objects that caused the wrong class the be used for, e.g. res[[1]]$paras, and thus the single simulation would not print correctly.
  • Results from multi-sim objects can now be summarized for all random effects in the model.
  • More support for summarizing random effects from partially nested formulas, e.g. cluster_intercept and cluster_slope is now correctly extracted from (0 + treatment + treatment:time || cluster).
  • When Satterthwaite’s method fails the between clusters/subjects DFs are used to calculate p-values.
  • Power.plcp_multi is now exported.
  • get_power.plcp_multi now shows a progress bar.
  • Fix a bug that caused dropout to be wrong when one condition had 0 dropout, and deterministic_dropout = FALSE.

Written by Kristoffer Magnusson, a researcher in clinical psychology. You should follow him on Bluesky or on Twitter.


Share:

Published March 21, 2018 (View on GitHub)

Buy Me A Coffee

A huge thanks to the 175 supporters who've bought me a 422 coffees!

Steffen bought β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜• (12) coffees

I love your visualizations. Some of the best out there!!!

Jason Rinaldo bought β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜•β˜• (10) coffees

I've been looking for applets that show this for YEARS, for demonstrations for classes. Thank you so much! Students do not need to tolarate my whiteboard scrawl now. I'm sure they'd appreciate you, too.l

Shawn Bergman bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Thank you for putting this together! I am using these visuals and this information to teach my Advanced Quant class.

anthonystevendick@gmail.com bought β˜•β˜•β˜•β˜•β˜• (5) coffees

I've been using a lot of your ideas in a paper I'm writing and even borrowed some of your code (cited of course). But this site has been so helpful I think, in addition, I owe you a few coffees!

Chip Reichardt bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Hi Krisoffer, these are great applets and I've examined many. I'm writing a chapter for the second edition of "Teaching statistics and quantitative methods in the 21st century" by Joe Rodgers (Routledge). My chapter is on the use of applets in teaching statistics. I could well be describing 5 of yours. Would you permit me to publish one or more screen shots of the output from one or more of your applets. I promise I will be saying very positive things about your applets. If you are inclined to respond, my email address if Chip.Reichardt@du.edu.

Someone bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Someone bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Nice work! Saw some of your other publications and they are also really intriguing. Thanks so much!

JDMM bought β˜•β˜•β˜•β˜•β˜• (5) coffees

You finally helped me understand correlation! Many, many thanks... πŸ˜„

@VicCazares bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Good stuff! It's been so helpful for teaching a Psych Stats class. Cheers!

Dustin M. Burt bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Excellent and informative visualizations!

Someone bought β˜•β˜•β˜•β˜•β˜• (5) coffees

@metzpsych bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Always the clearest, loveliest simulations for complex concepts. Amazing resource for teaching intro stats!

Ryo bought β˜•β˜•β˜•β˜•β˜• (5) coffees

For a couple years now I've been wanting to create visualizations like these as a way to commit these foundational concepts to memory. But after finding your website I'm both relieved that I don't have to do that now and pissed off that I couldn't create anything half as beautiful and informative as you have done here. Wonderful job.

Diarmuid Harvey bought β˜•β˜•β˜•β˜•β˜• (5) coffees

You have an extremely useful site with very accessible content that I have been using to introduce colleagues and students to some of the core concepts of statistics. Keep up the good work, and thanks!

Michael Hansen bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Keep up the good work!

Michael Villanueva bought β˜•β˜•β˜•β˜•β˜• (5) coffees

I wish I could learn more from you about stats and math -- you use language in places that I do not understand. Cohen's D visualizations opened my understanding. Thank you

Someone bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Thank you, Kristoffer

PΓ₯l from Norway bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Great webpage, I use it to illustrate several issues when I have a lecture in research methods. Thanks, it is really helpful for the students:)

@MAgrochao bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Joseph Bulbulia bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Hard to overstate the importance of this work Kristoffer. Grateful for all you are doing.

@TDmyersMT bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Some really useful simulations, great teaching resources.

@lakens bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Thanks for fixing the bug yesterday!

@LinneaGandhi bought β˜•β˜•β˜•β˜•β˜• (5) coffees

This is awesome! Thank you for creating these. Definitely using for my students, and me! :-)

@ICH8412 bought β˜•β˜•β˜•β˜•β˜• (5) coffees

very useful for my students I guess

@KelvinEJones bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Preparing my Master's student for final oral exam and stumbled on your site. We are discussing in lab meeting today. Coffee for everyone.

Someone bought β˜•β˜•β˜•β˜•β˜• (5) coffees

What a great site

@Daniel_Brad4d bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Wonderful work!

David Loschelder bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Terrific work. So very helpful. Thank you very much.

@neilmeigh bought β˜•β˜•β˜•β˜•β˜• (5) coffees

I am so grateful for your page and can't thank you enough!Β Β 

@giladfeldman bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Wonderful work, I use it every semester and it really helps the students (and me) understand things better. Keep going strong.

Dean Norris bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Sal bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Really super useful, especially for teaching. Thanks for this!

dde@paxis.org bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Very helpful to helping teach teachers about the effects of the Good Behavior Game

@akreutzer82 bought β˜•β˜•β˜•β˜•β˜• (5) coffees

Amazing visualizations! Thank you!

@rdh_CLE bought β˜•β˜•β˜•β˜•β˜• (5) coffees

So good!

tchipman1@gsu.edu bought β˜•β˜•β˜• (3) coffees

Hey, your stuff is cool - thanks for the visual

Hugo QuenΓ© bought β˜•β˜•β˜• (3) coffees

Hi Kristoffer, Some time ago I've come up with a similar illustration about CIs as you have produced, and I'm now also referring to your work:<br>https://hugoquene.github.io/QMS-EN/ch-testing.html#sec:t-confidenceinterval-mean<br>With kind regards, Hugo QuenΓ©<br>(Utrecht University, Netherlands)

Tor bought β˜•β˜•β˜• (3) coffees

Thanks so much for helping me understand these methods!

Amanda Sharples bought β˜•β˜•β˜• (3) coffees

Soyol bought β˜•β˜•β˜• (3) coffees

Someone bought β˜•β˜•β˜• (3) coffees

Kenneth Nilsson bought β˜•β˜•β˜• (3) coffees

Keep up the splendid work!

@jeremywilmer bought β˜•β˜•β˜• (3) coffees

Love this website; use it all the time in my teaching and research.

Someone bought β˜•β˜•β˜• (3) coffees

Powerlmm was really helpful, and I appreciate your time in putting such an amazing resource together!

DR AMANDA C DE C WILLIAMS bought β˜•β˜•β˜• (3) coffees

This is very helpful, for my work and for teaching and supervising

Georgios Halkias bought β˜•β˜•β˜• (3) coffees

Regina bought β˜•β˜•β˜• (3) coffees

Love your visualizations!

Susan Evans bought β˜•β˜•β˜• (3) coffees

Thanks. I really love the simplicity of your sliders. Thanks!!

@MichaMarie8 bought β˜•β˜•β˜• (3) coffees

Thanks for making this Interpreting Correlations: Interactive Visualizations site - it's definitely a great help for this psych student! πŸ˜ƒ

Zakaria Giunashvili, from Georgia bought β˜•β˜•β˜• (3) coffees

brilliant simulations that can be effectively used in training

Someone bought β˜•β˜•β˜• (3) coffees

@PhysioSven bought β˜•β˜•β˜• (3) coffees

Amazing illustrations, there is not enough coffee in the world for enthusiasts like you! Thanks!

Cheryl@CurtinUniAus bought β˜•β˜•β˜• (3) coffees

🌟What a great contribution - thanks Kristoffer!

vanessa moran bought β˜•β˜•β˜• (3) coffees

Wow - your website is fantastic, thank you for making it.

Someone bought β˜•β˜•β˜• (3) coffees

mikhail.saltychev@gmail.com bought β˜•β˜•β˜• (3) coffees

Thank you Kristoffer This is a nice site, which I have been used for a while. Best Prof. Mikhail Saltychev (Turku University, Finland)

Someone bought β˜•β˜•β˜• (3) coffees

Ruslan Klymentiev bought β˜•β˜•β˜• (3) coffees

@lkizbok bought β˜•β˜•β˜• (3) coffees

Keep up the nice work, thank you!

@TELLlab bought β˜•β˜•β˜• (3) coffees

Thanks - this will help me to teach tomorrow!

SCCT/Psychology bought β˜•β˜•β˜• (3) coffees

Keep the visualizations coming!

@elena_bolt bought β˜•β˜•β˜• (3) coffees

Thank you so much for your work, Kristoffer. I use your visualizations to explain concepts to my tutoring students and they are a huge help.

A random user bought β˜•β˜•β˜• (3) coffees

Thank you for making such useful and pretty tools. It not only helped me understand more about power, effect size, etc, but also made my quanti-method class more engaging and interesting. Thank you and wish you a great 2021!

@hertzpodcast bought β˜•β˜•β˜• (3) coffees

We've mentioned your work a few times on our podcast and we recently sent a poster to a listener as prize so we wanted to buy you a few coffees.Β Thanks for the great work that you do!Dan Quintana and James Heathers - Co-hosts of Everything HertzΒ 

Cameron Proctor bought β˜•β˜•β˜• (3) coffees

Used your vizualization in class today. Thanks!

eshulman@brocku.ca bought β˜•β˜•β˜• (3) coffees

My students love these visualizations and so do I! Thanks for helping me make stats more intuitive.

Someone bought β˜•β˜•β˜• (3) coffees

Adrian HelgΓ₯ VestΓΈl bought β˜•β˜•β˜• (3) coffees

@misteryosupjoo bought β˜•β˜•β˜• (3) coffees

For a high school teacher of psychology, I would be lost without your visualizations. The ability to interact and manipulate allows students to get it in a very sticky manner. Thank you!!!

Chi bought β˜•β˜•β˜• (3) coffees

You Cohen's d post really helped me explaining the interpretation to people who don't know stats! Thank you!

Someone bought β˜•β˜•β˜• (3) coffees

You doing useful work !! thanks !!

@ArtisanalANN bought β˜•β˜•β˜• (3) coffees

Enjoy.

@jsholtes bought β˜•β˜•β˜• (3) coffees

Teaching stats to civil engineer undergrads (first time teaching for me, first time for most of them too) and grasping for some good explanations of hypothesis testing, power, and CI's. Love these interactive graphics!

@notawful bought β˜•β˜•β˜• (3) coffees

Thank you for using your stats and programming gifts in such a useful, generous manner. -Jess

Mateu Servera bought β˜•β˜•β˜• (3) coffees

A job that must have cost far more coffees than we can afford you ;-). Thank you.

@cdrawn bought β˜•β˜•β˜• (3) coffees

Thank you! Such a great resource for teaching these concepts, especially CI, Power, correlation.

Julia bought β˜•β˜•β˜• (3) coffees

Fantastic work with the visualizations!

@felixthoemmes bought β˜•β˜•β˜• (3) coffees

@dalejbarr bought β˜•β˜•β˜• (3) coffees

Your work is amazing! I use your visualizations often in my teaching. Thank you.Β 

@PsychoMouse bought β˜•β˜•β˜• (3) coffees

Excellent!  Well done!  SOOOO Useful!😊 🐭 

Someone bought β˜•β˜• (2) coffees

Thanks, your work is great!!

Dan Sanes bought β˜•β˜• (2) coffees

this is a superb, intuitive teaching tool!

@whlevine bought β˜•β˜• (2) coffees

Thank you so much for these amazing visualizations. They're a great teaching tool and the allow me to show students things that it would take me weeks or months to program myself.

Someone bought β˜•β˜• (2) coffees

@notawful bought β˜•β˜• (2) coffees

Thank you for sharing your visualization skills with the rest of us! I use them frequently when teaching intro stats.Β 

Someone bought β˜• (1) coffee

You are awesome

Thom Marchbank bought β˜• (1) coffee

Your visualisations are so useful! Thank you so much for your work.

georgina g. bought β˜• (1) coffee

thanks for helping me in my psych degree!

Someone bought β˜• (1) coffee

Thank You for this work.

Kosaku Noba bought β˜• (1) coffee

Nice visualization, I bought a cup of coffee.

Someone bought β˜• (1) coffee

Thomas bought β˜• (1) coffee

Great. Use it for teaching in psychology.

Someone bought β˜• (1) coffee

It is the best statistics visualization so far!

Ergun Pascu bought β˜• (1) coffee

AMAZING Tool!!! Thank You!

Ann Calhoun-Sauls bought β˜• (1) coffee

This has been a wonderful resource for my statistics and research methods classes. I also occassionally use it for other courses such as Theories of Personality and Social Psychology

David Britt bought β˜• (1) coffee

nicely reasoned

Mike bought β˜• (1) coffee

I appreciate your making this site available. Statistics are not in my wheelhouse, but the ability to display my data more meaningfully in my statistics class is both educational and visually appealing. Thank you!

Jayne T Jacobs bought β˜• (1) coffee

Andrew J O'Neill bought β˜• (1) coffee

Thanks for helping understand stuff!

Someone bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Shawn Hemelstrand bought β˜• (1) coffee

Thank you for this great visual. I use it all the time to demonstrate Cohen's d and why mean differences affect it's approximation.

Adele Fowler-Davis bought β˜• (1) coffee

Thank you so much for your excellent post on longitudinal models. Keep up the good work!

Stewart bought β˜• (1) coffee

This tool is awesome!

Someone bought β˜• (1) coffee

Aidan Nelson bought β˜• (1) coffee

Such an awesome page, Thank you

Someone bought β˜• (1) coffee

Ellen Kearns bought β˜• (1) coffee

Dr Nazam Hussain bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Eva bought β˜• (1) coffee

I've been learning about power analysis and effect sizes (trying to decide on effect sizes for my planned study to calculate sample size) and your Cohen's d interactive tool is incredibly useful for understanding the implications of different effect sizes!

Someone bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Thanks a lot!

Someone bought β˜• (1) coffee

Reena Murmu Nielsen bought β˜• (1) coffee

Tony Andrea bought β˜• (1) coffee

Thanks mate

Tzao bought β˜• (1) coffee

Thank you, this really helps as I am a stats idiot :)

Melanie Pflaum bought β˜• (1) coffee

Sacha Elms bought β˜• (1) coffee

Yihan Xu bought β˜• (1) coffee

Really appreciate your good work!

@stevenleung bought β˜• (1) coffee

Your visualizations really help me understand the math.

Junhan Chen bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Michael Hansen bought β˜• (1) coffee

ALEXANDER VIETHEER bought β˜• (1) coffee

mather bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Bastian Jaeger bought β˜• (1) coffee

Thanks for making the poster designs OA, I just hung two in my office and they look great!

@ValerioVillani bought β˜• (1) coffee

Thanks for your work.

Someone bought β˜• (1) coffee

Great work!

@YashvinSeetahul bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Angela bought β˜• (1) coffee

Thank you for building such excellent ways to convey difficult topics to students!

@inthelabagain bought β˜• (1) coffee

Really wonderful visuals, and such a fantastic and effective teaching tool. So many thanks!

Someone bought β˜• (1) coffee

Someone bought β˜• (1) coffee

Yashashree Panda bought β˜• (1) coffee

I really like your work.

Ben bought β˜• (1) coffee

You're awesome. I have students in my intro stats class say, "I get it now," after using your tool. Thanks for making my job easier.

Gabriel Recchia bought β˜• (1) coffee

Incredibly useful tool!

Shiseida Sade Kelly Aponte bought β˜• (1) coffee

Thanks for the assistance for RSCH 8210.

@Benedikt_Hell bought β˜• (1) coffee

Great tools! Thank you very much!

Amalia Alvarez bought β˜• (1) coffee

@noelnguyen16 bought β˜• (1) coffee

Hi Kristoffer, many thanks for making all this great stuff available to the community!

Eran Barzilai bought β˜• (1) coffee

These visualizations are awesome! thank you for creating it

Someone bought β˜• (1) coffee

Chris SG bought β˜• (1) coffee

Very nice.

Gray Church bought β˜• (1) coffee

Thank you for the visualizations. They are fun and informative.

Qamar bought β˜• (1) coffee

Tanya McGhee bought β˜• (1) coffee

@schultemi bought β˜• (1) coffee

Neilo bought β˜• (1) coffee

Really helpful visualisations, thanks!

Someone bought β˜• (1) coffee

This is amazing stuff. Very slick.Β 

Someone bought β˜• (1) coffee

Sarko bought β˜• (1) coffee

Thanks so much for creating this! Really helpful for being able to explain effect size to a clinician I'm doing an analysis for.Β 

@DominikaSlus bought β˜• (1) coffee

Thank you! This page is super useful. I'll spread the word.Β 

Someone bought β˜• (1) coffee

Melinda Rice bought β˜• (1) coffee

Thank you so much for creating these tools! As we face the challenge of teaching statistical concepts online, this is an invaluable resource.

@tmoldwin bought β˜• (1) coffee

Fantastic resource. I think you would be well served to have one page indexing all your visualizations, that would make it more accessible for sharing as a common resource.

Someone bought β˜• (1) coffee

Fantastic Visualizations! Amazing way to to demonstrate how n/power/beta/alpha/effect size are all interrelated - especially for visual learners! Thank you for creating this?

@jackferd bought β˜• (1) coffee

Incredible visualizations and the best power analysis software on R.

Cameron Proctor bought β˜• (1) coffee

Great website!

Someone bought β˜• (1) coffee

Hanah Chapman bought β˜• (1) coffee

Thank you for this work!!

Someone bought β˜• (1) coffee

Jayme bought β˜• (1) coffee

Nice explanation and visual guide of Cohen's d

Bart Comly Boyce bought β˜• (1) coffee

thank you

Dr. Mitchell Earleywine bought β˜• (1) coffee

This site is superb!

Florent bought β˜• (1) coffee

Zampeta bought β˜• (1) coffee

thank you for sharing your work.Β 

Mila bought β˜• (1) coffee

Thank you for the website, made me smile AND smarter :O enjoy your coffee! :)

Deb bought β˜• (1) coffee

Struggling with statistics and your interactive diagram made me smile to see that someone cares enough about us strugglers to make a visual to help us out!😍 

Someone bought β˜• (1) coffee

@exerpsysing bought β˜• (1) coffee

Much thanks! Visualizations are key to my learning style!Β 

Someone bought β˜• (1) coffee

Sponsors

You can sponsor my open source work using GitHub Sponsors and have your name shown here.

Backers ✨❀️

Questions & Comments

Please use GitHub Discussions for any questions related to this post, or open an issue on GitHub if you've found a bug or wan't to make a feature request.

Archived Comments (1)

J
Jason Geller 2018-03-21

Can this simulate power for growth curve models? I found simr to be quite sluggish.