<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/introducing-powerlmm-an-r-package-for-power-calculations-for-longitudinal-multilevel-models/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://rpsychologist.com/introducing-powerlmm"> R Psychologist - R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Over the years I’ve produced quite a lot of code for power calculations and simulations of different longitudinal linear mixed models. Over the summer I bundled together these calculations for the designs I most typically encounter into an R package. The purpose of <em>powerlmm</em> is to help design longitudinal treatment studies, with or without higher-level clustering (e.g. by therapists, groups, or physician), and missing data. Currently, <em>powerlmm</em> supports two-level models, nested three-level models, and partially nested models. Additionally, unbalanced designs and missing data can be accounted for in the calculations. Power is calculated analytically, but simulation methods are also provided in order to evaluated bias, type 1 error, and the consequences of model misspecification. For novice R users, the basic functionality is also provided as a Shiny web application. </p>
<p>The package can be install from GitHub here: <a rel="nofollow" href="http://github.com/rpsychologist/powerlmm" target="_blank">github.com/rpsychologist/powerlmm</a>. Currently, the packages includes three vignettes that show how to setup your studies and calculate power. </p>
<h1>A basic example</h1>
<div>
<pre><span></span><span>library</span><span>(</span>powerlmm<span>)</span>
<span># dropout per treatment group</span>
d <span>&lt;-</span> per_treatment<span>(</span>control <span>=</span> dropout_weibull<span>(</span><span>0.3</span><span>,</span> <span>2</span><span>),</span>
              treatment <span>=</span> dropout_weibull<span>(</span><span>0.2</span><span>,</span> <span>2</span><span>))</span>

<span># Setup design</span>
p <span>&lt;-</span> study_parameters<span>(</span>n1 <span>=</span> <span>11</span><span>,</span> <span># time points</span>
                      n2 <span>=</span> <span>10</span><span>,</span> <span># subjects per cluster</span>
                      n3 <span>=</span> <span>5</span><span>,</span> <span># clusters per treatment arm</span>
                      icc_pre_subject <span>=</span> <span>0.5</span><span>,</span>
                      icc_pre_cluster <span>=</span> <span>0</span><span>,</span>
                      icc_slope <span>=</span> <span>0.05</span><span>,</span>
                      var_ratio <span>=</span> <span>0.02</span><span>,</span>
                      dropout <span>=</span> d<span>,</span>
                      cohend <span>=</span> <span>-0.8</span><span>)</span>

<span># Power</span>
get_power<span>(</span>p<span>)</span>
</pre>
</div>
<div>
<pre><span></span>## 
##      Power calculation for longitudinal linear-mixed model (three-level)
##                            with missing data and unbalanced designs 
## 
##               n1 = 11
##               n2 = 10  (treatment)
##                    10  (control)
##               n3 = 5   (treatment)
##                    5   (control)
##                    10  (total)
##          total_n = 50  (treatment)
##                    50  (control)
##                    100 (total)
##          dropout =  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10 (time)
##                     0,  0,  1,  3,  6,  9, 12, 16, 20, 25, 30 (%, control)
##                     0,  0,  1,  2,  4,  5,  8, 10, 13, 17, 20 (%, treatment)
## icc_pre_subjects = 0.5
## icc_pre_clusters = 0
##        icc_slope = 0.05
##        var_ratio = 0.02
##           cohend = -0.8
##            power = 0.68
</pre>
</div>
<h1>Feedback</h1>
<p>I appreciate all types of feedback, e.g. typos, bugs, inconsistencies, feature requests, etc. Open an issue on <a rel="nofollow" href="http://github.com/rpsychologist/powerlmm/issues" target="_blank">github.com/rpsychologist/powerlmm/issues</a> or via my contact info <a rel="nofollow" href="http://rpsychologist.com/about" target="_blank">here</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://rpsychologist.com/introducing-powerlmm"> R Psychologist - R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/_4hHbNsUkn8" height="1"></a></div>