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
data_long = melt(CDIdata, id.vars=c("rowID", "ribotype", "severe", "LoS.total", "LoS.preinf", "LoS.postinf", "discharge.status")) | |
data_long$value = as.numeric(as.character(data_long$value)) | |
# Change discharge to death in hospital | |
data_long$variable = factor(data_long$variable, levels=c(unique(as.character(data_long$variable)), "Death in hospital")) | |
d = data_long$variable=="Discharged" & data_long$discharge.status == "3" | |
data_long$variable[d] = "Death in hospital" | |
#write.csv(data_long, file="data_long.csv") |
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
map.tb <- function(map.data, g=NA, brks=NA, title="", value="tb", file=FALSE){ | |
## plot UK choropleth maps | |
## developed using LA and ETS data but | |
## can be applied more generally | |
## | |
## map.data: map object loaded by readOGR() | |
## g: number of groups for values; max(g)=9 | |
## brks: given break points to group values | |
## title: plot title | |
## value: variable name of colouring value (string) |
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
\documentclass{article} | |
\usepackage[margin=0.5in]{geometry} | |
\begin{document} | |
\Sexpr{cat(sub("_", "\\\\\\_", version$platform))} | |
% !Rnw root = TB_root.Rnw | |
%% some of the output is missing when compiled to PDF | |
%% when the regression is fit to models with lots of variable levels |
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
covariateShift <- function(data, resla, riskfac, ssize=10000){ | |
## importance sampling approach | |
## when different distributions for the | |
## training and test data | |
require(plyr) | |
Natsal.riskfac.table <- DistnTable(data, riskfac) | |
Natsal.riskfac.table <- colNameReplace(Natsal.riskfac.table, "(all)", "Natsalfreq") |
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
## read from Excel workbook | |
require(XLConnect) | |
wb = loadWorkbook("C:/Users/ngreen1/Documents/IDEA/raw_data/TB_database_patientdata_300614.xlsx") | |
tab.names <- getSheets(wb) | |
TBlist <- sapply(1:length(tab.names), function(x) readWorksheet(wb, sheet=x, header=TRUE)) | |
names(TBlist) <- tab.names | |
## extract only columns of interest | |
require(plyr) | |
extractNames <- readLines("C:/Users/ngreen1/Documents/IDEA/raw_data/relevant_fields.csv") |
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("rmeta", lib.loc="C:/Program Files/R/R-3.1.0/library") | |
names <- c("Premature", "Not premature", | |
NA,"Surgical","Not surgical", | |
NA,"Congenital","Not congenital", | |
NA,"Catheter","Not catheter", | |
NA,"Other","Not other", | |
NA,"Tai","Not Tai", | |
NA,"Cancer","Not cancer") | |
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("plotrix", lib.loc="C:/Program Files/R/R-3.1.0/library") | |
library(Hmisc) | |
NATSAL.dat <<- read.csv("~/Chlamydia/data/NATSAL/Natsal-3_extract_2April2014.csv") | |
plotCInatsal <- function(varname, save=TRUE){ | |
tab <- table(NATSAL.dat$cttestly=="yes", NATSAL.dat[,varname]) | |
tab.df <- data.frame(addmargins(tab)) |
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
#--run in the old version of R | |
setwd("C:/Temp/") | |
packages <- installed.packages()[,"Package"] | |
save(packages, file="Rpackages") | |
Followed by this in the new version: | |
#--run in the new version | |
setwd("C:/Temp/") | |
load("Rpackages") | |
for (p in setdiff(packages, installed.packages()[,"Package"])) |
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
## ----setup, include=FALSE------------------------------------------------ | |
knitr::opts_chunk$set(echo = TRUE) | |
## ---- echo=T, eval=T----------------------------------------------------- | |
2 + 2 | |
## ---- echo=T, eval=T----------------------------------------------------- | |
a <- 2 + 2 | |
## ---- echo=T,eval=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
## ----setup, include=FALSE------------------------------------------------ | |
knitr::opts_chunk$set(echo = TRUE) | |
## ---- eval=T,echo=T------------------------------------------------------ | |
a <- 1 | |
b <- 2 | |
c <- -1 | |
d <- 2 | |
# Check if two values are the same. Note the difference between |