This file contains 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
# For plotting qq | |
qqplot.data <- function(vec){ | |
y <- quantile(vec[!is.na(vec)], c(0.25, 0.75)) | |
x <- qnorm(c(0.25, 0.75)) | |
slope <- diff(y)/diff(x) | |
int <- y[1L] - slope * x[1L] | |
d <- data.frame(resids = vec) | |
ggplot(d, aes(sample = resids)) + | |
stat_qq() + | |
geom_abline(slope = slope, intercept = int) |
This file contains 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
rm(list = ls()) | |
library(contrast) | |
taps <- c(242, 245, 244, 248, 247, 248, | |
242, 244, 246, 242, 248, 246, 245, 247, | |
248, 250, 247, 246, 243, 244, 246, 248, | |
250, 252, 248, 250, 246, 248, 245, 250) | |
group <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) | |
df1 <- data.frame(taps, group) |
This file contains 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
* Sort the table columns alphabetically ; | |
proc contents data=Newcoach1t1 out=col_names noprint; run; | |
proc contents data=Newcoach1t1 out=col_names(keep=name ) noprint; run; | |
proc sort data=col_names; by name; run; | |
data _null_; | |
set col_names; | |
by name; | |
retain sorted_cols; | |
length sorted_cols $2500.; |
This file contains 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
knee.mean <- mean(df2$kneeheel, na.rm = T) | |
knee.sd <- sd(df2$kneeheel, na.rm = T) | |
p <- ggplot(data = df2, aes(x=kneeheel)) | |
p <- p + geom_density(aes(y=..density..)) | |
p <- p + stat_function(fun = dnorm, args = list(mean = knee.mean, sd = knee.sd), colour = "red") | |
print(p) | |
This file contains 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
# > head(df2) | |
# id variable cartvol time timeb | |
# 1 1 cartvol0 1.987862 0 0 | |
# 2 2 cartvol0 1.694808 0 0 | |
# 3 3 cartvol0 2.342389 0 0 | |
# 4 4 cartvol0 1.727150 0 0 | |
# 5 5 cartvol0 1.546601 0 0 | |
# 6 6 cartvol0 1.425992 0 0 | |
grid <- with(df2, seq(min(cartvol), max(cartvol), length = 100)) |
This file contains 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
p <- ggplot(data = df2, aes(x = factor(time), y = cartvol )) | |
p <- p + geom_boxplot() | |
p <- p + geom_jitter(size=1, position=position_jitter(width=0.03, height=0), colour = "blue") | |
#p <- p + geom_smooth(method = "lm", se = T) | |
p <- p + xlab("Time" ) | |
p <- p + ylab("Cartilage volume") | |
p <- p + theme_bw() | |
p <- p + theme(legend.position="bottom") | |
print(p) |
This file contains 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
# > head(df1, 2) | |
# id cartvol0 cartvol1 incr.cart interval diff | |
# 1 1 1.987862 2.023709 Yes 3 0.03584695 | |
# 2 2 1.694808 1.584858 No 2 -0.10995007 | |
df1$diff <- df1$cartvol1 - df1$cartvol0 | |
v <- as.numeric(quantile(df1$cartvol0, c(0.3333, 0.6667))) | |
df1$interval <- as.factor(findInterval(df1$cartvol0, v)+1) | |
ddply(df1, .(interval), summarise, diff.mean = mean(diff, na.rm = T), n = length(diff)) |
This file contains 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
--- | |
title: "A test" | |
author: "t-student" | |
date: "January 5, 2018" | |
output: html_document | |
--- | |
I'll be exploring the differences between these three models: | |
```{r, eval = FALSE} |
This file contains 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
> head(df.tmp) | |
# A tibble: 6 x 9 | |
patientid practiceid mmt.date mmt.val int pre preend post stage | |
<dbl> <dbl> <date> <dbl> <date> <date> <date> <date> <chr> | |
1 21342 3.00 2015-12-09 83.0 2017-03-07 2015-12-07 2016-12-07 2017-09-07 PRE | |
2 19273 3.00 2015-12-11 120 2017-03-07 2015-12-07 2016-12-07 2017-09-07 PRE | |
3 19273 3.00 2015-12-11 50.0 2017-03-07 2015-12-07 2016-12-07 2017-09-07 PRE | |
4 19273 3.00 2015-12-11 0 2017-03-07 2015-12-07 2016-12-07 2017-09-07 PRE | |
5 19273 3.00 2015-12-17 72.0 2017-03-07 2015-12-07 2016-12-07 2017-09-07 PRE | |
6 19273 3.00 2015-12-17 135 2017-03-07 2015-12-07 2016-12-07 2017-09-07 PRE |
This file contains 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
# See majutils | |
mean_sd <- function (x, dp = 2) | |
{ | |
my.stat <- paste0(round(mean(x, na.rm = T), dp), " (", round(sd(x, | |
na.rm = T), dp), ")") | |
return(my.stat) | |
} | |
prop <- function (x, level, dp = 1, percent = T) | |
{ |