Skip to content

Instantly share code, notes, and snippets.

----------------------------
month patient hasahamd
------- --------- ----------
0 10008 1
0 10011 1
0 10015 1
0 10023 1
----------------------------
month patient hasahamd
------- --------- ----------
0 10008 1
0 10011 1
0 10015 1
0 10023 1
@puterleat
puterleat / icc.R
Created June 3, 2016 07:20
Function to calculate ICC for lmer model object
# calculate ICC for lmer model object
icc <- function(m){
vc <- as.data.frame((VarCorr(m)))
l <- vc$vcov
data_frame(grp=vc$grp, icc=sapply(l, function(x){x/sum(l)}))
}
<a href="javascript:var%20auto%20={names:%20'Steve%20Buscemi%20Catherine%20Keener%20Dermot%20Mulroney%20Danielle%20Zerneck%20James%20LeGros%20Rica%20Martens%20Peter%20Dinklage%20Kevin%20Corrigan%20Hilary%20Gilford%20Robert%20Wightman%20Tom%20Jarmusch%20Michael%20Griffiths%20Matthew%20Grace%20Ryan%20Bowker%20Francesca%20DiMauro',blurb:%20'Excepteur%20pariatur%20cillum%20labore%20ea%20proident%20et%20deserunt.%20Ex%20commodo%20ea%20esse%20incididunt%20deserunt%20dolor%20ea%20minim%20do%20qui%20irure.%20Qui%20aute%20irure%20ut%20ad%20id%20duis%20esse%20tempor%20occaecat%20exercitation%20excepteur%20do%20nostrud.%20Aute%20ex%20fugiat%20tempor%20laboris%20ex%20consequat%20consequat%20tempor%20anim%20ipsum%20consectetur%20et%20proident%20cupidatat%20duis%20nulla%20reprehenderit.%20Velit%20adipisicing%20occaecat%20nulla%20officia%20irure%20anim%20dolor%20quis%20cupidatat%20cupidatat%20deserunt%20esse%20Lorem%20exercitation%20in%20commodo.%20Amet%20ea%20labore%20duis%20mollit%20sit%20labore%20laborum%20sit%20aliqua%2
@puterleat
puterleat / gist:4e54cbb6bea559f56a2dedab97c0b8a5
Created May 24, 2016 15:12
Using WAIC to compare models
# The example below shows why WAIC could be useful when studies are underpowered.
# Here we simulate data with a weak polynomial relationship between x an y, with
# only a small sample. Although the effect of the polynomial term does not reach
# conventional standards for statistical significance, comparing WAIC (an estimate
# of how effective each model will be at predicting new, out-of-sample data) indicates
# we should assign a higher probability that `m2` is 'correct', when compared with `m1`
# (more than twice as likely).
library(rethinking)
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The example below shows why WAIC could be useful when studies are underpowered. Here we simulate data with a weak polynomial relationship between x an y, with only a small sample. Although the effect of the polynomial term does not reach conventional standards for statistical significance, comparing WAIC (an estimate of how effective each model will be at predicting new, out-of-sample data) indicates we should assign a higher probability that `m2` is 'correct', when compared with `m1` (more than twice as likely)."
]
},
{
If I have these data:
ID T Y
1 1 33
1 2 32
2 1 21
2 2 26
How do I make this extra column:
. do "/var/folders/47/f2b3zfds1y5gq4vp7m6___cr0000gn/T//SD44048.000000"
. clear all
. set seed 123
.
. * recruit subjects (if only this easy...)
. set obs 2000
clear all
set seed 123
* recruit subjects (if only this easy...)
set obs 2000
* assign to groups
gen mbct = mod(_n, 2)
* depression baseline score
. do "/var/folders/47/f2b3zfds1y5gq4vp7m6___cr0000gn/T//SD44048.000000"
. clear all
. set seed 123
.
. * recruit subjects (if only this easy...)
. set obs 2000