This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extract_sims <- function(modelInterval){ | |
# Grabs simulation draws from a predictInterval object. | |
attr(modelInterval, "sim.results") | |
} | |
bind_sims <- function(sims, newdata){ | |
# Where you have simulated predictions based the model or new dataset, it can | |
# be helpful to combine these with the dataset. | |
# There may also be multiple draws from the simulation, stored in separate | |
# columns. These are melted into long form. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. replace adself_2_11=1 if patient==20617 & month==0 | |
(0 real changes made) | |
. replace adself_2_11=1 if patient==20271 & month==0 | |
(0 real changes made) | |
. replace adself_2_11=1 if patient==20509 & month==0 | |
(0 real changes made) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
('A+', 100) | |
('A', 88) | |
('A-', 77) | |
('B+', 68) | |
('B', 65) | |
('B-', 62) | |
('C+', 58) | |
('C', 55) | |
('C-', 52) | |
('D+', 48) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
msc_ids <- c(10308927, 10536302, 10461083, 10114629, 10534788, 10540000, 10539361, 10409295, 206408, 10538988, 755020, 10118522, 390769) | |
mscmarks <- read.csv("Marks_Yinghui2.csv") %>% filter(Reg.. %in% msc_ids) | |
mscmarks | |
NO ROWS.. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://en.wikipedia.org/wiki/Akaike_information_criterion#How_to_apply_AIC_in_practice | |
compareAIC <- function(..., models) { | |
mods = c(list(...), models) | |
aics <- sapply(mods, FUN = AIC) | |
round(exp((min(aics) - aics) / 2), 2) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/11693599/alternative-to-expand-grid-for-data-frames | |
expand.grid.df <- | |
function(...) | |
Reduce(function(...) | |
merge(..., by = NULL), list(...)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)})) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/21477040/reshape2-multiple-results-of-aggregation-function | |
dcastMult <- function(data, formula, value.var = "value", | |
funs = list("min" = min, "max" = max)) { | |
require(reshape2) | |
if (is.null(names(funs)) | any(names(funs) == "")) stop("funs must be named") | |
Form <- formula(formula) | |
LHS <- as.character(Form[[2]]) | |
if (length(LHS) > 1) LHS <- LHS[-1] | |
temp <- lapply(seq_along(funs), function(Z) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/21477040/reshape2-multiple-results-of-aggregation-function | |
dcastMult <- function(data, formula, value.var = "value", | |
funs = list("min" = min, "max" = max)) { | |
require(reshape2) | |
if (is.null(names(funs)) | any(names(funs) == "")) stop("funs must be named") | |
Form <- formula(formula) | |
LHS <- as.character(Form[[2]]) | |
if (length(LHS) > 1) LHS <- LHS[-1] | |
temp <- lapply(seq_along(funs), function(Z) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# effect on total variance | |
library(dplyr) | |
N=10000 | |
prob <- .25 | |
e_var = 1 | |
u_var = .25*e_var # see http://www.wolframalpha.com/input/?i=.1%3Db%2F%28a%2Bb%29 | |
icc = u_var/(u_var+e_var) |