Skip to content

Instantly share code, notes, and snippets.

odds_to_rr <-function (fit)
{
Estimates <- fixef(fit)
param <-data.frame(Estimates)
param$Parameter <- row.names(param)
est <- param %>% select(Parameter, Estimates)
rownames(est) <- NULL
est[[2]] <- exp(est[[2]])
ci <- stats::confint(fit, method = "Wald", parm = "beta_")
else ci <- stats::confint(fit)
#!/bin/bash
# Update Ubuntu
sudo apt-get update
# Install gcc and clang C++ compilers
sudo apt-get install gcc
sudo apt-get install clang
#Install libcurl4
@mjadkins
mjadkins / R_AWS.R
Last active October 6, 2016 09:39
R and RSTAN on Amazon Web Services Elastic Cloud Computing (EC2) using Ubuntu Linux Server - October 2016
# In your terminal navigate to key pair
cd <your directory>
# Connect to the server via Secure Shell (SSH)
ssh -i YOUR_KEYPAIR.pem.txt ubuntu@PUBLIC_DNS
# You may get an error so you will need to modify the key
chmod 600 YOUR_KEYPAIR.pem.txt
# Connect to the server via Secure Shell (SSH)
# Load libraries
lapply(c("R2MLwiN","arm","ggplot2","RColorBrewer","grid"),library, character.only=TRUE)
# Set working directory and load data
setwd("~/R")
data(tutorial)
str(tutorial)
# Fit a linear varying intercept multilevel model with group level predictors of normexam ~ sex + standlrt + vrband + schgend + avslrt + schav + (1|school)
fit.1 <-lmer(normexam ~ sex + standlrt + vrband + schgend + avslrt + schav + (1|school), data=tutorial)
@mjadkins
mjadkins / ggplot2_caterpillar.R
Created August 9, 2015 19:13
ggplot2 Caterpillar Plot
# Load libraries
lapply(c("R2MLwiN","arm","ggplot2","RColorBrewer","grid"),library, character.only=TRUE)
# Set working directory and load data
setwd("~/R")
data(tutorial)
str(tutorial)
# Fit a linear varying intercept multilevel model with group level predictors of normexam ~ sex + standlrt + vrband + schgend + avslrt + schav + (1|school)
fit.1 <-lmer(normexam ~ sex + standlrt + vrband + schgend + avslrt + schav + (1|school), data=tutorial)
@mjadkins
mjadkins / ggplot2_coefplot.R
Last active September 21, 2015 19:34
ggplot2_coefplot
# Load libraries
lapply(c("datasets","arm","ggplot2","RColorBrewer","grid"),library, character.only=TRUE)
# Set working directory and load data
setwd("~/R")
data(mtcars)
# Fit a linear model of mpg ~ wt + disp + hp + qsec
fit.1 <-lm(mpg ~ wt + disp + hp + qsec, data=mtcars)
display(fit.1)
require("RColorBrewer")
# not run:
# model = lm(y~x1+x2+x3+x4...)
# Construct quantile table for varialbes of interest
# t value: n-p=df.residual=634, alpha=5%,50%. t(1-alpha/2, n-p)
t.05 <- qt(1-0.025, 634, lower.tail = TRUE, log.p=FALSE)
t.5 <- qt(1-0.25, 634, lower.tail = TRUE, log.p=FALSE)
coef.quantil <- data.frame(matrix(0, nrow=length(model$coefficients)-1, ncol=8))