Pymer4

Love multi-level-modeling using lme4 in R, but prefer to work in the scientific Python ecosystem? This this package has got you covered! It’s a small convenience package wrapping the basic functionality of lme4 for compatibility with python. (Currently this only include linear and logistic multi-level models)

This package’s main purpose is to provide a clean interface that hides the back-and-forth code required when moving between R and Python. In other words a user can work completely in Python, never having to deal with R, but get (most) of lme4’s goodness. Behind the scenes this package simply uses rpy2 to pass objects between languages, compute what’s needed, parse everything, and convert to Python types (e.g. numpy arrays, pandas dataframes, etc).

This package can also fit standard regression models with a few extra bells and whistles compared to R’s lm() (Currently this only includes linear models)

TL;DR This package is your new simple Pythonic drop-in replacement for lm() or glmer() in R.

Features

This package has some extra goodies to make life a bit easier, namely:

  • For multi-level models (i.e. glmer()):

    • Automatic inclusion of p-values in model output using lmerTest
    • Automatic inclusion of confidence intervals in model output
    • Automatic conversion and calculation of odds-ratios and probabilities for logit models
    • Easy access to model fits, residuals, and random effects as pandas dataframes
    • Random effects plotting using seaborn
  • For standard linear models (i.e. lm())

    • Automatic inclusion of confidence intervals in model output
    • Easy computation of empirically bootstrapped 95% confidence intervals
    • Easy computation of heteroscedasticity or auto-correlation robust ‘sandwich estimators’ for standard errors (note: these are not the same as auto-regressive models)
    • Permutation tests on model parameters

Installation

Requires a working installation of both Python (2.7 or 3.6) and R (>= 3.2.4).

You will also need lme4 and lmerTest R packages installed.

This package will not install R or R packages for you!

  1. Method 1 - Install from github
pip install git+https://github.com/ejolly/pymer4
  1. Method 2 - Install from PyPi
pip install pymer4