R
29 posts
Why linear mixed-effects models are probably not the solution to your missing data problems
Linear mixed-effects models are often used for their ability to handle missing data using maximum likelihood estimation. In this post I will present a simple example of when the LMM fails, and illustrate two MNAR sensitivity analyses: the pattern-mixture method and the joint model.
Heterogeneous treatment effects and homogeneous outcome variances
Recently there has been a couple of meta-analyses investigating heterogeneous treatment effects by analyzing the ratio of the outcome variances in the treatment and control group. The argument made in these articles is that if individuals differ in their response, then observed variances in the treatment and control group in RCTs should differ. In this post I explore this argument and provide a counterargument.
Mediation, confounding, and measurement error
In this post, I give a brief simulation-based example of how confounding and measurement error impacts the estimation of direct and indirect effects in a mediation analysis.
Change over time is not "treatment response"
The term "treatment response" is both easy to understand and simultaneously often used when causal language is clearly unwarranted. In this post, I present a non-technical example of when a naïve subgroup analysis leads to the wrong conclusion that a subgroup of patients is treatment non-responders.
Estimating treatment effects and ICCs from (G)LMMs on the observed scale using Bayes, Part 1: lognormal models
In this post I show how to make marginal inferences on the untransformed scaled when using multilevel models with a non-linear transformation applied to the dependent variable (a log-transformation is used as an example). Cluster-specific versus population-average (conditional versus marginal) effects are compared using both average effects on the untransformed scale and using relative (multiplicative) effects.
Do you really need a multilevel model? A preview of powerlmm 0.4.0
The next version of powerlmm (0.4.0) will soon be released, besides bug fixes this version also includes several new simulation features. In this post I will show two examples that cover the major new features.
Power analysis for longitudinal multilevel models: powerlmm 0.3.0 is now out on CRAN
My R package 'powerlmm' has now been update to version 0.3.0. It adds support for a more flexible effect size specifiation.
Slides from my talk on how to do power analysis for longitudinal 2- and 3-level models.
This post contains the slides from a talk I gave recently at Stockholm University
Power analysis for longitudinal multilevel models: powerlmm 0.2.0 is now out on CRAN
My R package 'powerlmm' has now been update to version 0.2.0. It contains several improvements, and new features.
Confounded dose-response effects of treatment adherence: fitting Bayesian instrumental variable models using brms
Non-randomized comparisons are common in RCTs. In this post I show some examples of confounding and collider bias, using treatment adherence as an example. I present a small simulation study that show that common regression models used in clinical psychology, makes little sense, and that Bayesian instrumental variable regression can be easily fit using the R package brms.
Are parallel simulations in the cloud worth it? Benchmarking my MBP vs my Workstation vs Amazon EC2
In this post I compare the performance of Amazon EC2 instances vs my HP workstation and my MacBook Pro, when doing Monte Carlo simulations.
Introducing 'powerlmm' an R package for power calculations for longitudinal multilevel models
Over the summer I've been working on finishing my new R package 'powerlmm', which is now almost complete. It provides flexible power calculations for typical two- and three-level longitudinal linear mixed models, with unbalanced treatment groups and cluster sizes, as well as with missing data and random slopes at both the subject and cluster-level.
Where Cohen went wrong – the proportion of overlap between two normal distributions
This post explains how Cohen's d relates to the proportion of overlap between two normal distributions, and why I use a different measure then Cohen in my Cohen's d visualization.
Using R and lme/lmer to fit different two- and three-level longitudinal models
I often get asked about how to fit different longitudinal models in lme/lmer. In this post I cover several different two-level, three-level and partially nested models.
Calculating the Overlap of Two Normal Distributions Using Monte Carlo Integration
In this post I show how to calculate the overlap of two normal distributions using simulations.
Visualizing a One-Way ANOVA using D3.js
A while ago I was playing around with the javascript package D3.js, and I began with this visualization—that I never really finished—of how a one-way ANOVA is calculated. I tried to make it look like a plot from ggplot2 except with interactive elements. Take a look at it after the jump
Creating a typical textbook illustration of statistical power using either ggplot or base graphics
A common way of illustrating the idea behind statistical power in null hypothesis significance testing, is by plotting the sampling distributions of the null hypothesis and the alternative hypothesis. Typically, these illustrations highlight the regions that correspond to making a type II error, type I error and correctly rejecting the null hypothesis (i.e. the test’s power). In this post I will show how to create such “power plots” using both ggplot and R’s base graphics.
Working with shapefiles, projections and world maps in ggplot
In this post I show some different examples of how to work with map projections and how to plot the maps using ggplot. Many maps that are using the default projection are shown in the longlat-format, which is far from optimal. Here I show how to use either the Robinson or Winkel Tripel projection.
Analytical and simulation-based power analyses for mixed-design ANOVAs
In this post I show some R-examples on how to perform power analyses for mixed-design ANOVAs. The first example is analytical—and adapted from formulas used in G*Power (Faul et al., 2007), and the second example is a Monte Carlo simulation.
PubMed publications in 2011 by 202 world countries: who’s the winner?
Which country had the most PubMed citations in 2011? To find out I used R statistical software to analyze the affiliation of 986 427 articles
How to download complete XML records from PubMed and extract data
Yesterday I wrote an article that looked at the top 20 Cognitive Behavior Therapy journals with the most publications; today I will explain how I did it with R.
More PubMed data mining: looking at top 20 CBT journals
In this short article I present some data of the top 20 Cognitive Behavior Therapy (CBT) journals with the most PubMed publications, and compare that to data from 2010 and 2011.
Short R script to plot effect sizes (Cohen's d) and shade overlapping area
In this short post I take a look at how to use R and ggplot2 to visualize effect sizes (Cohen’s d) and how to shade the overlapping area of two distributions.
An R Script to Automatically download PubMed Citation Counts By Year of publication
An R script that queries PubMed’s E-utilities for the number of publications per year matching a search term, and plots the trends with ggplot2.
How to work with Google n-gram data sets in R using MySQL
In this R tutorial I show how to work with Google n-gram data sets with the help of MySQL and R. The complete R code is included in this post
Simple data mining and plotting data on a map with ggplot2
In this post I scrape data from a document were members of a group wrote were they live, and then plot the result using OpenStreetsMaps and ggplot2.
Ggplot2, PubMed citation frequency and DSM-IV Axis I disorders by year
I searched PubMed for several major DSM-IV disorders and downloaded the hits. Using ggplot2 I plotted the number of publications each year for each disorder
Using Ggplot2 to plot last.fm top 100 albums
I found out that last.fm had made data files available for their Best of 2011 artist list, and I thought it’d be a great opportunity to learn some more about data management in R and Ggplot2.
Monty Hall Simulations
In this post I use R to simulate the classic monty hall-problem and visualize the results with ggplot2.