-
Notifications
You must be signed in to change notification settings - Fork 7
/
Setup_and_munge.R
64 lines (53 loc) · 1.89 KB
/
Setup_and_munge.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
##################
# Knitr settings #
##################
knitr::opts_chunk$set(warning=FALSE,
message=FALSE,
echo=FALSE,
dev="png", dev.args=list(type="cairo"), # The png device
# Change to dev="postscript" if you want the EPS-files
# for submitting. Also remove the dev.args() as the postscript
# doesn't accept the type="cairo" argument.
error=FALSE)
# Evaluate the figure caption after the plot
knitr::opts_knit$set(eval.after='fig.cap')
# Use the table counter that the htmlTable() provides
options(table_counter = TRUE)
# Use the figCapNo() with roman letters
options(fig_caption_no_roman = TRUE)
#################
# Load_packages #
#################
library(rms) # I use the cox regression from this package
library(boot) # The melanoma data set is used in this exampe
library(Gmisc) # Stuff I find convenient
library(Greg) # You need to get this from my GitHub see http://gforge.se/packages
library(magrittr) # The excellent piping package
##################
# Munge the data #
##################
# Here we go through and setup the variables so that
# they are in the proper format for the actual output
# Load the dataset - usually you would use read.csv
# or something similar
data("melanoma")
# Set time to years instead of days
melanoma$time_years <-
melanoma$time / 365.25
# Factor the basic variables that
# we're interested in
melanoma$status <-
factor(melanoma$status,
levels=c(2, 1, 3),
labels=c("Alive", # Reference
"Melanoma death",
"Non-melanoma death"))
melanoma$sex <-
factor(melanoma$sex,
labels=c("Male", # Reference
"Female"))
melanoma$ulcer <-
factor(melanoma$ulcer,
levels=0:1,
labels=c("Absent", # Reference
"Present"))