shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
shiny::runApp('Shiny Model')
rm(list = ls())
# original
load("L:\\SHARP analyses\\Decision analytic model\\Uncertainty analysis\\PSA\\data\\2015_boostrapped_coeffs_UK_10Feb2015.Rdata")
load("L:\\SHARP analyses\\Decision analytic model\\Uncertainty analysis\\PSA\\data\\coeffs_PSA.Rdata")
load("L:\\SHARP analyses\\Shiny model\\data\\coeffs_PSA.Rdata")
ls()
rm(list = ls())
# original
load("L:\\SHARP analyses\\Shiny model\\data\\coeffs_PSA.Rdata")
ls()
head(coeffs_PSA)
names(coeffs_PSA)
head(coeffs_PSA$qol)
colnames(coeffs_PSA$qol)[which(colnames(coeffs_PSA) == "renalDiagnosis_2Diabetic nephropathy(coeffs_PSA$qol)")]
colnames(coeffs_PSA$qol)[which(colnames(coeffs_PSA$qol) == "renalDiagnosis_2Diabetic nephropathy(coeffs_PSA$qol)")]
colnames(coeffs_PSA$qol)
which(colnames(coeffs_PSA$qol) == "renalDiagnosis_2Diabetic nephropathy(coeffs_PSA$qol)")
which(colnames(coeffs_PSA$qol) == "renalDiagnosis_2Diabetic nephropathy")
colnames(coeffs_PSA$qol)[which(colnames(coeffs_PSA$qol) == "renalDiagnosis_2Diabetic nephropathy")]
colnames(coeffs_PSA$qol)[which(colnames(coeffs_PSA$qol) == "renalDiagnosis_2Diabetic nephropathy")] <-
"renalDiagnosisDiabetic nephropathy"
colnames(coeffs_PSA$qol)
colnames(coeffs_PSA$VD)
rm(list = ls())
# original
load("L:\\SHARP analyses\\Shiny model\\data\\coeffs_PSA.Rdata")
colnames(coeffs_PSA$qol)[which(colnames(coeffs_PSA$qol) == "renalDiagnosis_2Diabetic nephropathy")] <-
"renalDiagnosisDiabetic nephropathy"
save(coeffs_PSA, file = "L:\\SHARP analyses\\Shiny model\\data\\coeffs_PSA.Rdata")
head(coeffs_PSA$qol)
head(coeffs_PSA$nonesrd2)
names(coeffs_PSA)
head(coeffs_PSA$nonesrd)
load("L:\\SHARP analyses\\Shiny model\\data\\coeffs_default.Rdata")
coeffs_defauls
coeffs_default
coeffs_default$qol2
colnames(coeffs_default$qol)[which(colnames(coeffs_default$qol) == "renalDiagnosis_2Diabetic nephropathy")] <-
"renalDiagnosisDiabetic nephropathy"
names(coeffs_default$qol)[which(names(coeffs_default$qol) == "renalDiagnosis_2Diabetic nephropathy")] <-
"renalDiagnosisDiabetic nephropathy"
coeffs_default$qol
coeffs_default
save(coeffs_default, file = "L:\\SHARP analyses\\Shiny model\\data\\coeffs_default.Rdata")
setwd("L:\\SHARP analyses\\Shiny model\\data\\")
load("pat0.Rdata")
pat0
pat0[-c(grep("_2", names(pat0))), ]
grep("_2", names(pat0))
names(pat0)
pat0
names(pat0)
colnames(pat0)
grep("_2", colnames(pat0))
pat0[-c(grep("_2", colnames(pat0))), ]
rm(list = ls())
### user-friendly input
data <- data.frame(id = 1, age = 65, sex = 0, ethnicity = 0,
education = 0, childDep = 0, adultDep = 0,
smoker = 0, currentAlc = 0,
BMI_quant = 0, DBP_quant = 0, SBP_quant = 0,
CholHDL_quant = 0, Albumin_quant = 0,
Hemoglobin_quant = 0, Phosphate_quant = 0,
ACR_quant = 0, CVD = 0, DM = 1,
CKDStage = 0, CKDDuration = 10,
renalDiagnosis = 1, ESRDDuration = 0, TX = 0)
save(data, file = "L:\\SHARP analyses\\Shiny Model\\data\\default_patient.Rdata")
write.csv(data, file = "L:\\SHARP analyses\\Shiny Model\\www\\default_patient.csv")
### translate into the format to be used for the program
# time-updated covariates
patT <- as.matrix(data.frame(id = data$id,
age_T = data$age, age_T2 = data$age + 1,
CKDDuration_T = data$CKDDuration,
ESRDDuration_T = data$ESRDDuration))
patT
save(patT, file = "L:\\SHARP analyses\\Shiny Model\\data\\patT.Rdata")
# not time-updated covariates
pat0 <- data
colnames(pat0)[which(colnames(pat0) == "sex")] <- "SEX"
pat0$SEX <- factor(pat0$SEX,
levels = c(0, 1),
labels = c("F", "M"))
pat0$ethnicity <- factor(pat0$ethnicity,
levels = c(0, 1, 2, 3, 4),
labels = c("White", "Asian: China", "Asian: other", "Black", "Other"))
pat0$education <- factor(pat0$education,
levels = c(0, 1, 2),
labels = c("A-levels and above", "GCSE/vocational", "below secondary"))
pat0$childDep <- factor(pat0$childDep,
levels = c(0, 1),
labels = c("0", ">0"))
pat0$adultDep <- factor(pat0$adultDep,
levels = c(0, 1),
labels = c("1", ">1"))
pat0$smoker <- factor(pat0$smoker,
levels = c(0, 1, 2),
labels = c("never", "before", "currently"))
pat0$currentAlc <- factor(pat0$currentAlc,
levels = c(0, 1),
labels = c(0, 1))
pat0$BMI_quant <- factor(pat0$BMI_quant,
levels = c(0, 1, 2),
labels = c("T2", "T1", "T3"))
pat0$DBP_quant <- factor(pat0$DBP_quant,
levels = c(0, 1, 2),
labels = c("T2", "T1", "T3"))
pat0$SBP_quant <- factor(pat0$SBP_quant,
levels = c(0, 1, 2),
labels = c("T2", "T1", "T3"))
pat0$CholHDL_quant <- factor(pat0$CholHDL_quant,
levels = c(0, 1, 2),
labels = c("T2", "T1", "T3"))
pat0$Albumin_quant <- factor(pat0$Albumin_quant,
levels = c(0, 1, 2),
labels = c("T2", "T1", "T3"))
pat0$Hemoglobin_quant <- factor(pat0$Hemoglobin_quant,
levels = c(0, 1, 2),
labels = c("T2", "T1", "T3"))
pat0$Phosphate_quant <- factor(pat0$Phosphate_quant,
levels = c(0, 1, 2),
labels = c("T2", "T1", "T3"))
pat0$ACR_quant <- factor(pat0$ACR_quant,
levels = c(0, 1, 2, 3),
labels = c("T2", "T1", "T3", "ESRD"))
pat0$DM <- factor(pat0$DM,
levels = c(0, 1),
labels = c(0, 1))
pat0$TX <- factor(pat0$TX,
levels = c(0, 1),
labels = c(0, 1))
pat0$renalDiagnosis <- factor(pat0$renalDiagnosis,
levels = c(2, 0, 1),
labels = c("Other (known or unknown cause)", "Diabetic nephropathy", "Cystic kidney disease"))
vars <- c(
"SEX",
"ethnicity", "smoker", "currentAlc", "adultDep", "childDep", "education", "BMI_quant",
"DM", "TX", "DBP_quant", "SBP_quant", "Albumin_quant", "Hemoglobin_quant", "Phosphate_quant",
"ACR_quant", "CholHDL_quant", "renalDiagnosis")
pat0 <- model.matrix(
as.formula(paste("~", paste(vars, collapse = "+"), sep = "")), data = pat0)
pat0 <- cbind(pat0, CVD = as.numeric(data$CVD == "Other vascular disease"))
pat0 <- cbind(pat0, id = data$id)
save(pat0, file = "L:\\SHARP analyses\\Shiny Model\\data\\pat0.Rdata")
pat0
df <- data.frame(id = c(1, 1, 1, 2, 2, 2), a = c(1, 2, 3), b = c(5, 3, 2))
df
library(plyr)
library(data.table)
library(microbenchmark)
ff = function(i) {
return(c(min(i),max(i)))
}
set.seed(12345)
id = c(rep(1:3,4000))
x  = runif(12000,1,10)
df = data.frame(id,id2,x)
View(df)
install.packages("data.table")
install.packages("microbenchmark")
library(plyr)
library(data.table)
library(microbenchmark)
ff = function(i) {
return(c(min(i),max(i)))
}
set.seed(12345)
id = c(rep(1:3,4000))
x  = runif(12000,1,10)
df = data.frame(id,id2,x)
df = data.frame(id,id,x)
head(df)
df = data.frame(id,x)
head(df)
res  = ddply(df,.(id),summarise,val1 = min(x), val2 = max(x), val3 = ff(x)[1], val4 = ff(x)[2], val5 = val3+val4, val6 = val3/val4)
View(res)
head(res)
nrow(res)
res2 = setDT(df)[, as.list(c(val1 = min(x), val2 = max(x), val3 = ff(x))), .(id)][, val5 := val31+val32][, val6 := val31/val32]
head(res)
res2 = setDT(df)[, as.list(c(val1 = min(x), val2 = max(x), val3 = ff(x))), .(id)]
head(res2)
res2 = setDT(df)[, as.list(c(val1 = min(x), val2 = max(x), val3 = ff(x))), .(id)][, val5 := val31+val32][, val6 := val31/val32]
head(res2)
class(res2)
data.frame(res2)
print(microbenchmark(ddply(df,.(id),summarise,val1 = min(x), val2 = max(x), val3 = ff(x)[1], val4 = ff(x)[2], val5 = val3+val4, val6 = val3/val4), times = 100))
print(microbenchmark(setDT(df)[, as.list(c(val1 = min(x), val2 = max(x), val3 = ff(x))), .(id)][, val5 := val31+val32][, val6 := val31/val32],times=100))
#df <- data.frame(id = c(1, 1, 1, 2, 2, 2), a = c(1, 2, 3), b = c(5, 3, 2))
rm(list = ls())
library(plyr)
library(data.table)
library(microbenchmark)
ff = function(i) {
return(list(a = min(i), b = max(i)))
}
set.seed(12345)
id = c(rep(1:3,4000))
x  = runif(12000,1,10)
df = data.frame(id,x)
res2 = setDT(df)[, as.list(c(val1 = min(x), val2 = max(x), val3 = ff(x))), .(id)]
res2
res2 = data.frame(setDT(df)[, as.list(c(val1 = min(x), val2 = max(x), val3 = ff(x))), .(id)])
res2
res2 = data.frame(setDT(df)[, as.list(c(val1 = min(x), val2 = max(x), ff(x))), .(id)])
res2
ddply(df, .(id), summarise, .PSA_CI_events)
.PSA_CI_events <- function(vec, level = 0.95) {
N <- length(vec)
vec <- sort(vec)
temp <- (1 - level) / 2
left <- vec[max(floor(N * temp), 1)]
right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(left = left, right = right))
}
ddply(df, .(id), summarise, .PSA_CI_events)
head(df)
ddply(df, .(id), summarise, .PSA_CI_events(x))
data.frame(setDT(df)[, as.list(.PSA_CI_events(x)), .(id)])
x <- list(left = left, right = right)
x <- list(left = 1, right = 2)
names(x)
.PSA_CI_events <- function(x, level = 0.95) {
N <- nrow(df)
temp <- (1 - level) / 2
vec <- sort(df$x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right))
}
data.frame(setDT(df)[, as.list(.PSA_CI_events(x)), .(id)])
.PSA_CI_events <- function(x, level = 0.95) {
print(x)
N <- nrow(x)
temp <- (1 - level) / 2
vec <- sort(df$x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right))
}
data.frame(setDT(df)[, as.list(.PSA_CI_events(x)), .(id)])
set.seed(12345)
id = c(rep(1:3,5))
x  = runif(12000,1,10)
df = data.frame(id,x)
df
.PSA_CI_events <- function(x, level = 0.95) {
print(x)
N <- nrow(x)
temp <- (1 - level) / 2
vec <- sort(df$x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right))
}
data.frame(setDT(df)[, as.list(.PSA_CI_events(x)), .(id)])
df
set.seed(12345)
id = c(rep(1:3,5))
x  = runif(length(id),1,10)
df = data.frame(id,x)
dfdf = data.frame(id,x)
df = data.frame(id,x)
df
.PSA_CI_events <- function(x, level = 0.95) {
print(x)
N <- nrow(x)
temp <- (1 - level) / 2
vec <- sort(df$x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right))
}
data.frame(setDT(df)[, as.list(.PSA_CI_events(x)), .(id)])
#df <- data.frame(id = c(1, 1, 1, 2, 2, 2), a = c(1, 2, 3), b = c(5, 3, 2))
rm(list = ls())
library(plyr)
library(data.table)
library(microbenchmark)
set.seed(12345)
id = c(rep(1:3,5))
x  = runif(length(id),1,10)
y  = runif(length(id),1,10)
df = data.frame(id, x, y)
df
.PSA_CI_events <- function(x, level = 0.95) {
print(x)
N <- nrow(x)
temp <- (1 - level) / 2
vec <- sort(df$x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
vec <- sort(df$y)
y_left <- vec[max(floor(N * temp), 1)]
y_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right,
y_left = y_left, y_right = y_right))
}
data.frame(setDT(df)[, as.list(.PSA_CI_events(x)), .(id)])
#df <- data.frame(id = c(1, 1, 1, 2, 2, 2), a = c(1, 2, 3), b = c(5, 3, 2))
rm(list = ls())
library(plyr)
library(data.table)
library(microbenchmark)
set.seed(12345)
id = c(rep(1:3,5))
x  = runif(length(id),1,10)
y  = runif(length(id),1,10)
df = data.frame(id, x, y)
df
.PSA_CI_events <- function(df, level = 0.95) {
print(df)
N <- nrow(df)
temp <- (1 - level) / 2
vec <- sort(df$x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
vec <- sort(df$y)
y_left <- vec[max(floor(N * temp), 1)]
y_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right,
y_left = y_left, y_right = y_right))
}
data.frame(setDT(df)[, as.list(.PSA_CI_events(.df)), .(id)])
#df <- data.frame(id = c(1, 1, 1, 2, 2, 2), a = c(1, 2, 3), b = c(5, 3, 2))
rm(list = ls())
library(plyr)
library(data.table)
library(microbenchmark)
set.seed(12345)
id = c(rep(1:3,5))
x  = runif(length(id),1,10)
y  = runif(length(id),1,10)
df = data.frame(id, x, y)
df
.PSA_CI_events <- function(df, level = 0.95) {
print(df)
N <- length(df)
temp <- (1 - level) / 2
vec <- sort(df$x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
vec <- sort(df$y)
y_left <- vec[max(floor(N * temp), 1)]
y_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right,
y_left = y_left, y_right = y_right))
}
data.frame(setDT(df)[, as.list(.PSA_CI_events(x)), .(id)])
data.frame(setDT(df)[, as.list(x = .PSA_CI_events(x), y = .PSA_CI_events(y)), .(id)])
#df <- data.frame(id = c(1, 1, 1, 2, 2, 2), a = c(1, 2, 3), b = c(5, 3, 2))
rm(list = ls())
library(plyr)
library(data.table)
library(microbenchmark)
set.seed(12345)
id = c(rep(1:3,5))
x  = runif(length(id),1,10)
y  = runif(length(id),1,10)
df = data.frame(id, x, y)
df
.PSA_CI_events <- function(df, level = 0.95) {
print(df)
N <- length(df)
temp <- (1 - level) / 2
vec <- sort(x)
x_left <- vec[max(floor(N * temp), 1)]
x_right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(x_left = x_left, x_right = x_right))
}
data.frame(setDT(df)[, as.list(x = .PSA_CI_events(x), y = .PSA_CI_events(y)), .(id)])
#df <- data.frame(id = c(1, 1, 1, 2, 2, 2), a = c(1, 2, 3), b = c(5, 3, 2))
rm(list = ls())
library(plyr)
library(data.table)
library(microbenchmark)
set.seed(12345)
id = c(rep(1:3,5))
x  = runif(length(id),1,10)
y  = runif(length(id),1,10)
df = data.frame(id, x, y)
df
.PSA_CI_events <- function(df, level = 0.95) {
print(df)
N <- length(df)
temp <- (1 - level) / 2
vec <- sort(x)
left <- vec[max(floor(N * temp), 1)]
right <- vec[min(ceiling(N * (1 - temp)), N)]
return(list(left = left, right = right))
}
data.frame(setDT(df)[, as.list(x = .PSA_CI_events(x), y = .PSA_CI_events(y)), .(id)])
data.frame(setDT(df)[, as.list(x = .PSA_CI_events(x)), .(id)]
[, as.list(y = .PSA_CI_events(y)), .(id)])
data.frame(setDT(df)[, as.list(c(x = .PSA_CI_events(x), y = .PSA_CI_events(y))), .(id)])
gsub(".", "_", "a.b", fixed=TRUE)
