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
| ('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
| . 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
| 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
| rf2.longs.with <- bind_sims(extract_sims(rf2.preds), newdata) | |
| rf2predswide <- rf2.longs %>% | |
| dcast(., month+sim+pd.b~grp, value.var="fitted", fun.aggregate=mean) | |
| intervals <- rf2predswide %>% | |
| mutate(diff=tau-dbt) %>% | |
| group_by(month) %>% | |
| do(., as.data.frame(t(quantile(.$diff, probs=c(.025, .5, .975))))) |
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
| p1 <- | |
| ggplot(group.table, aes(month, fit, group=grp, color=grp, shape=grp)) + | |
| geom_point() + geom_line() + | |
| scale_color_discrete("") + scale_shape_discrete("") + | |
| geom_text(show_guide = FALSE, aes(label=fit, y=fit), size=3) + | |
| xlab(paste("Month")) + | |
| ylab(paste("Model adjusted", toupper(dv))) + | |
| theme(legend.position="top") + | |
| theme(axis.text.x=element_blank(),axis.title.x=element_blank()) | |
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
| library(lmerTest) | |
| library(merTools) | |
| library(tidyverse) | |
| # linear model | |
| m <- lmer(Reaction~Days*I(Days^2)+(1|Subject), data=sleepstudy) | |
| newdata = expand.grid(Reaction=NA, Days=1:5, Subject=Inf) %>% as.data.frame | |
| sims <- predictInterval(m, newdata=newdata, returnSims = T) |
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
| library(tidyverse) | |
| library(lmerTest) | |
| library(broom) | |
| pwr <- function(N){ | |
| simdata <- data_frame(person =1:N, c1=rnorm(N, 20, 25), c2 = rnorm(N, 77, 27)) %>% | |
| reshape2::melt(id.var="person") | |
| lmer(value~variable+(1|person), data=simdata) %>% summary tidy %>% | |
| mutate(N=N) | |
| } |
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
| library(tidyverse) | |
| library(lmerTest) | |
| library(broom) | |
| mu_type1 <- 20 | |
| mu_type2 <- 70 | |
| sd_both <- 20 | |
| pwr <- function(N, mu_type1, mu_type2, sd_both){ |
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
| library(tidyverse) | |
| library(lmerTest) | |
| library(broom) | |
| mu_type1 <- 20 | |
| mu_type2 <- 70 | |
| sd_both <- 20 | |
| pwr <- function(N, mu_type1, mu_type2, sd_both){ |