Skip to content

Instantly share code, notes, and snippets.

@jcheong0428
Created September 15, 2018 02:42
Show Gist options
  • Save jcheong0428/e6b560ce625b7d36ff087c8b402da7ce to your computer and use it in GitHub Desktop.
Save jcheong0428/e6b560ce625b7d36ff087c8b402da7ce to your computer and use it in GitHub Desktop.
Set of codes to setup rpy2 environment to python notebook
# First load rpy2
%load_ext rpy2.ipython
# Then load packages in a separate cell
%%R
require('lme4')
require('lmerTest')
require('lattice')
require('boot')
require('sjPlot')
require('optimx')
options("scipen"=999, "digits"=5)
r2 <- function(m) {
lmfit <- lm(model.response(model.frame(m)) ~ fitted(m))
# summary(lmfit)$r.squared
summary(lmfit)$adj.r.squared
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment