Commit 358f57ab authored by mabrook's avatar mabrook
Browse files

adding new dataset, wihs2, with derived variables

parent 6e8feacc
# Hello, world!
#
# This is an example function named 'hello'
# which prints 'Hello, world!'.
#
# You can learn more about package authoring with RStudio at:
#
# http://r-pkgs.had.co.nz/
#
# Some useful keyboard shortcuts for package authoring:
#
# Build and Reload Package: 'Cmd + Shift + B'
# Check Package: 'Cmd + Shift + E'
# Test Package: 'Cmd + Shift + T'
hello <- function() {
print("Hello, world!")
}
# All code for setting up WIHS package
# Reading in WIHS data
wihs<-read.table("/Users/salevintow/Documents/R Software Development/WIHS2009/raw_data/wihs2009.14mar17.dat.txt")
colnames(wihs)<-c("id","idu","white","age","cd4","drop","delta","art","time")
# Review variables and make sure data read in correctly
str(wihs)
# ART variable is currently a factor w/ 489 levels
# Need to convert to numeric and replace '.' with NA
wihs$art<-as.character(wihs$art)
wihs$art<-ifelse(wihs$art=="."," ",wihs$art)
wihs$art<-as.numeric(wihs$art)
# Save R data set in the WIHS package
devtools::use_data(wihs)
# Creating raw data folder
use_data_raw()
# Load R data set
load(file="data/wihs.Rda")
# Initial analyses looking at data
library(ggplot2)
library(dplyr)
library(survival)
table(w$idu,w$delta,useNA = "always")
review<-wihs %>%
group_by(idu) %>%
summarize(num=n(),outcome=mean(delta),dropout=mean(drop),time=mean(time))
# Crude survival analysis
wihs$SurvObj <- with(wihs, Surv(time, delta == 1))
head(wihs)
# Kaplan-Meier estimator
km.as.one <- survfit(SurvObj ~ 1, data = wihs)
km.by.idu <- survfit(SurvObj ~ idu, data = wihs)
# Basic plots
plot(km.as.one)
plot(km.by.idu)
......@@ -26,4 +26,4 @@ You can install the package from Bitbucket
* There is one record per patient.
* The ART variable can be used as a competing event time.
* Times here are measured in decimals (or Colombian time), such that 365.25 days is 1.000 years.
\ No newline at end of file
* Times here are measured in decimals (or Colombian time), such that 365.25 days is 1.000 years.
......@@ -14,5 +14,13 @@ colnames(wihs)<-c("id","idu","white","age","cd4","drop","delta","art","time")
# Reviewing variables to make sure data read in correctly
str(wihs)
# Save R data set in the sharkr package
# construct a new dataset for input into
wihs2=wihs
wihs2$time=with(wihs,ifelse(art<time & !is.na(art),art,time))
wihs2$j=with(wihs,ifelse(art<time & !is.na(art),1,0))
wihs2$delta=with(wihs,ifelse(delta==1 | (!is.na(art) & art<time),1,0))
# Save R data set in the package
devtools::use_data(wihs,overwrite=TRUE)
devtools::use_data(wihs2,overwrite=TRUE)
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment